Bouffalo SDK  1.0
Bouffalolab Software Development Kit
bflb_adc.h
Go to the documentation of this file.
1 #ifndef _BFLB_ADC_H
2 #define _BFLB_ADC_H
3 
4 #include "bflb_core.h"
5 
17 #define ADC_CHANNEL_0 0
18 #define ADC_CHANNEL_1 1
19 #define ADC_CHANNEL_2 2
20 #define ADC_CHANNEL_3 3
21 #define ADC_CHANNEL_4 4
22 #define ADC_CHANNEL_5 5
23 #define ADC_CHANNEL_6 6
24 #define ADC_CHANNEL_7 7
25 #define ADC_CHANNEL_8 8
26 #define ADC_CHANNEL_9 9
27 #define ADC_CHANNEL_10 10
28 #define ADC_CHANNEL_11 11
29 #define ADC_CHANNEL_DACA 12
30 #define ADC_CHANNEL_DACB 13
31 #define ADC_CHANNEL_TSEN_P 14
32 #define ADC_CHANNEL_TSEN_N 15
33 #define ADC_CHANNEL_VREF 16
34 #define ADC_CHANNEL_VABT_HALF 18
35 #define ADC_CHANNEL_GND 23
36 
43 #define ADC_CLK_DIV_4 1
44 #define ADC_CLK_DIV_8 2
45 #define ADC_CLK_DIV_12 3
46 #define ADC_CLK_DIV_16 4
47 #define ADC_CLK_DIV_20 5
48 #define ADC_CLK_DIV_24 6
49 #define ADC_CLK_DIV_32 7
50 
57 #define ADC_RESOLUTION_12B 0
58 #define ADC_RESOLUTION_14B 2
59 #define ADC_RESOLUTION_16B 4
60 
67 #define ADC_VREF_3P2V 0
68 #define ADC_VREF_2P0V 1
69 
76 #define ADC_TSEN_MOD_INTERNAL_DIODE 0
77 #define ADC_TSEN_MOD_EXTERNAL_DIODE 1
78 
85 #define ADC_INTSTS_NEG_SATURATION (1 << 0)
86 #define ADC_INTSTS_POS_SATURATION (1 << 1)
87 #define ADC_INTSTS_FIFO_UNDERRUN (1 << 2)
88 #define ADC_INTSTS_FIFO_OVERRUN (1 << 3)
89 #define ADC_INTSTS_ADC_READY (1 << 4)
90 
97 #define ADC_INTCLR_NEG_SATURATION (1 << 0)
98 #define ADC_INTCLR_POS_SATURATION (1 << 1)
99 #define ADC_INTCLR_FIFO_UNDERRUN (1 << 2)
100 #define ADC_INTCLR_FIFO_OVERRUN (1 << 3)
101 #define ADC_INTCLR_ADC_READY (1 << 4)
102 
117  uint8_t clk_div;
118  uint8_t scan_conv_mode;
121  uint8_t resolution;
122  uint8_t vref;
123 };
124 
132  uint8_t pos_chan;
133  uint8_t neg_chan;
134 };
135 
145  int8_t pos_chan;
146  int8_t neg_chan;
147  int32_t value;
148  int32_t millivolt;
149 };
150 
151 #ifdef __cplusplus
152 extern "C" {
153 #endif
154 
161 void bflb_adc_init(struct bflb_device_s *dev, const struct bflb_adc_config_s *config);
162 
168 void bflb_adc_deinit(struct bflb_device_s *dev);
169 
176 void bflb_adc_link_rxdma(struct bflb_device_s *dev, bool enable);
177 
184 void bflb_adc_set_reference_channel(int channel, int32_t millivolt);
185 
194 int bflb_adc_channel_config(struct bflb_device_s *dev, struct bflb_adc_channel_s *chan, uint8_t channels);
195 
201 void bflb_adc_start_conversion(struct bflb_device_s *dev);
202 
208 void bflb_adc_stop_conversion(struct bflb_device_s *dev);
209 
216 uint8_t bflb_adc_get_count(struct bflb_device_s *dev);
217 
224 uint32_t bflb_adc_read_raw(struct bflb_device_s *dev);
225 
233 void bflb_adc_rxint_mask(struct bflb_device_s *dev, bool mask);
234 
241 void bflb_adc_errint_mask(struct bflb_device_s *dev, bool mask);
242 
249 uint32_t bflb_adc_get_intstatus(struct bflb_device_s *dev);
250 
257 void bflb_adc_int_clear(struct bflb_device_s *dev, uint32_t int_clear);
258 
267 void bflb_adc_parse_result(struct bflb_device_s *dev, uint32_t *buffer, struct bflb_adc_result_s *result, uint16_t count);
268 
275 void bflb_adc_tsen_init(struct bflb_device_s *dev, uint8_t tsen_mod);
276 
283 float bflb_adc_tsen_get_temp(struct bflb_device_s *dev);
284 
290 void bflb_adc_vbat_enable(struct bflb_device_s *dev);
291 
297 void bflb_adc_vbat_disable(struct bflb_device_s *dev);
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 
311 #endif
void bflb_adc_vbat_enable(struct bflb_device_s *dev)
Enable adc vbat power.
uint8_t neg_chan
Definition: bflb_adc.h:133
int32_t millivolt
Definition: bflb_adc.h:148
void bflb_adc_link_rxdma(struct bflb_device_s *dev, bool enable)
Enable adc rx dma.
ADC configuration structure.
Definition: bflb_adc.h:116
int bflb_adc_channel_config(struct bflb_device_s *dev, struct bflb_adc_channel_s *chan, uint8_t channels)
Config adc channels to sample.
void bflb_adc_vbat_disable(struct bflb_device_s *dev)
Disable adc vbat power.
void bflb_adc_int_clear(struct bflb_device_s *dev, uint32_t int_clear)
Clear adc interrupt instatus.
ADC result select.
Definition: bflb_adc.h:144
float bflb_adc_tsen_get_temp(struct bflb_device_s *dev)
Get adc temperature.
uint8_t scan_conv_mode
Definition: bflb_adc.h:118
void bflb_adc_set_reference_channel(int channel, int32_t millivolt)
Select reference channel.
uint8_t differential_mode
Definition: bflb_adc.h:120
uint8_t pos_chan
Definition: bflb_adc.h:132
ADC channel select.
Definition: bflb_adc.h:131
void bflb_adc_deinit(struct bflb_device_s *dev)
Deinitialize adc.
uint8_t clk_div
Definition: bflb_adc.h:117
void bflb_adc_tsen_init(struct bflb_device_s *dev, uint8_t tsen_mod)
Initialize adc temperature sensor.
void bflb_adc_parse_result(struct bflb_device_s *dev, uint32_t *buffer, struct bflb_adc_result_s *result, uint16_t count)
Parse adc conversion value into millivolt and actual numerical value.
void bflb_adc_stop_conversion(struct bflb_device_s *dev)
Stop adc conversion.
void bflb_adc_rxint_mask(struct bflb_device_s *dev, bool mask)
Enable or disable adc conversion completion interrupt. Triggerring when a channel conversion is compl...
uint32_t bflb_adc_get_intstatus(struct bflb_device_s *dev)
Get adc interrupt instatus.
void bflb_adc_start_conversion(struct bflb_device_s *dev)
Start adc conversion.
void bflb_adc_init(struct bflb_device_s *dev, const struct bflb_adc_config_s *config)
Initialize adc.
void bflb_adc_errint_mask(struct bflb_device_s *dev, bool mask)
Enable or disable adc error interrupt.
uint8_t continuous_conv_mode
Definition: bflb_adc.h:119
uint8_t resolution
Definition: bflb_adc.h:121
uint8_t bflb_adc_get_count(struct bflb_device_s *dev)
Get adc number of completed conversions.
uint32_t bflb_adc_read_raw(struct bflb_device_s *dev)
Read adc conversion value.