51 lines
1019 B
C
51 lines
1019 B
C
|
/*
|
||
|
* lightsense.h
|
||
|
*
|
||
|
* Created on: Oct 18, 2024
|
||
|
* Author: true
|
||
|
*/
|
||
|
|
||
|
#ifndef USER_SRC_ADC_H_
|
||
|
#define USER_SRC_ADC_H_
|
||
|
|
||
|
|
||
|
|
||
|
#define LSENS_DARK_THRESHOLD 0x7ff // baseline minimum value reading achieved in darkness
|
||
|
|
||
|
#define LSENS_PORT GPIOA
|
||
|
#define LSENS_A_PIN GPIO_Pin_2
|
||
|
#define LSENS_K_PIN GPIO_Pin_3
|
||
|
#define LSENS_ADC_CH ADC_Channel_3
|
||
|
|
||
|
#define LSENS_COARSE_UP 0x690 // counts higher than this increase lsens_coarse, maximum 64
|
||
|
#define LSENS_COARSE_DOWN 0x5a0 // counts lower than this decrease lsens_coarse, minimum 1
|
||
|
|
||
|
enum lsens_mode {
|
||
|
LSENS_READING_IDLE = 0,
|
||
|
LSENS_READING_START,
|
||
|
LSENS_READING_WAIT,
|
||
|
LSENS_READING_TIMEOUT,
|
||
|
LSENS_OUTPUT = 0xff
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
void adc_init();
|
||
|
|
||
|
void adc_convert();
|
||
|
void adc_read();
|
||
|
|
||
|
void adc_set_mode_lsens(uint8_t mode);
|
||
|
uint8_t adc_get_mode_lsens();
|
||
|
|
||
|
void adc_process_lsens();
|
||
|
|
||
|
uint16_t adc_get_lsens();
|
||
|
uint8_t adc_get_lsens_coarse();
|
||
|
|
||
|
uint8_t adc_get_brightness(uint8_t level);
|
||
|
|
||
|
|
||
|
|
||
|
#endif /* USER_SRC_ADC_H_ */
|