Firmware SDK
twr_adc.h
1 #ifndef _TWR_ADC_H
2 #define _TWR_ADC_H
3 
4 #include <twr_common.h>
5 #include <stm32l083xx.h>
6 
10 
12 
13 typedef enum
14 {
17 
20 
23 
26 
29 
32 
35 
37 
39 
40 typedef enum
41 {
44 
47 
50 
53 
56 
59 
62 
65 
68 
70 
72 
73 typedef enum
74 {
77 
79  TWR_ADC_RESOLUTION_10_BIT = ADC_CFGR1_RES_0,
80 
82  TWR_ADC_RESOLUTION_8_BIT = ADC_CFGR1_RES_1,
83 
85  TWR_ADC_RESOLUTION_6_BIT = ADC_CFGR1_RES_1 | ADC_CFGR1_RES_0,
86 
88 
90 
91 typedef enum
92 {
95 
97 
99 
100 void twr_adc_init();
101 
105 
106 bool twr_adc_is_ready();
107 
113 
114 bool twr_adc_get_value(twr_adc_channel_t channel, uint16_t *result);
115 
122 
123 bool twr_adc_set_event_handler(twr_adc_channel_t channel, void (*event_handler)(twr_adc_channel_t, twr_adc_event_t, void *), void *event_param);
124 
129 
131 
137 
138 bool twr_adc_async_get_value(twr_adc_channel_t channel, uint16_t *result);
139 
145 
146 bool twr_adc_async_get_voltage(twr_adc_channel_t channel, float *result);
147 
152 
153 bool twr_adc_get_vdda_voltage(float *vdda_voltage);
154 
158 
159 bool twr_adc_calibration(void);
160 
164 
166 
170 
172 
174 
175 #endif // _TWR_ADC_H
void twr_adc_resolution_set(twr_adc_channel_t channel, twr_adc_resolution_t resolution)
Set ADC resolution for specific channel.
Definition: twr_adc.c:106
bool twr_adc_async_measure(twr_adc_channel_t channel)
Begins reading the ADC channel voltage in asynchronous mode.
Definition: twr_adc.c:234
void twr_adc_oversampling_set(twr_adc_channel_t channel, twr_adc_oversampling_t oversampling)
Set ADC oversampling for specific channel.
Definition: twr_adc.c:101
bool twr_adc_set_event_handler(twr_adc_channel_t channel, void(*event_handler)(twr_adc_channel_t, twr_adc_event_t, void *), void *event_param)
Set callback function.
Definition: twr_adc.c:218
twr_adc_oversampling_t
ADC oversampling.
Definition: twr_adc.h:41
bool twr_adc_calibration(void)
Calibration.
Definition: twr_adc.c:343
bool twr_adc_async_get_voltage(twr_adc_channel_t channel, float *result)
Get asynchronous measurement result in volts.
Definition: twr_adc.c:280
twr_adc_event_t
ADC event.
Definition: twr_adc.h:92
bool twr_adc_get_vdda_voltage(float *vdda_voltage)
Get voltage on VDDA pin.
Definition: twr_adc.c:286
twr_adc_channel_t
ADC channel.
Definition: twr_adc.h:14
twr_adc_resolution_t
ADC resolution.
Definition: twr_adc.h:74
bool twr_adc_is_ready()
Check if ADC is ready for reading.
Definition: twr_adc.c:173
bool twr_adc_async_get_value(twr_adc_channel_t channel, uint16_t *result)
Get asynchronous measurement result.
Definition: twr_adc.c:274
bool twr_adc_get_value(twr_adc_channel_t channel, uint16_t *result)
Reads the ADC channel value.
Definition: twr_adc.c:178
void twr_adc_init()
Initialize ADC converter.
Definition: twr_adc.c:66
@ TWR_ADC_OVERSAMPLING_128
ADC 128x oversampling.
Definition: twr_adc.h:64
@ TWR_ADC_OVERSAMPLING_4
ADC 4x oversampling.
Definition: twr_adc.h:49
@ TWR_ADC_OVERSAMPLING_2
ADC 2x oversampling.
Definition: twr_adc.h:46
@ TWR_ADC_OVERSAMPLING_64
ADC 64x oversampling.
Definition: twr_adc.h:61
@ TWR_ADC_OVERSAMPLING_256
ADC 256x oversampling.
Definition: twr_adc.h:67
@ TWR_ADC_OVERSAMPLING_8
ADC 8x oversampling.
Definition: twr_adc.h:52
@ TWR_ADC_OVERSAMPLING_NONE
ADC no oversampling.
Definition: twr_adc.h:43
@ TWR_ADC_OVERSAMPLING_32
ADC 32x oversampling.
Definition: twr_adc.h:58
@ TWR_ADC_OVERSAMPLING_16
ADC 16x oversampling.
Definition: twr_adc.h:55
@ TWR_ADC_EVENT_DONE
ADC event.
Definition: twr_adc.h:94
@ TWR_ADC_CHANNEL_A2
ADC channel A2.
Definition: twr_adc.h:22
@ TWR_ADC_CHANNEL_A5
ADC channel A5.
Definition: twr_adc.h:31
@ TWR_ADC_CHANNEL_A0
ADC channel A0.
Definition: twr_adc.h:16
@ TWR_ADC_CHANNEL_A4
ADC channel A4.
Definition: twr_adc.h:28
@ TWR_ADC_CHANNEL_A6
ADC channel A6.
Definition: twr_adc.h:34
@ TWR_ADC_CHANNEL_A3
ADC channel A3.
Definition: twr_adc.h:25
@ TWR_ADC_CHANNEL_A1
ADC channel A1.
Definition: twr_adc.h:19
@ TWR_ADC_RESOLUTION_6_BIT
ADC 6 bit resolution.
Definition: twr_adc.h:85
@ TWR_ADC_RESOLUTION_10_BIT
ADC 10 bit resolution.
Definition: twr_adc.h:79
@ TWR_ADC_RESOLUTION_12_BIT
ADC 12 bit resolution.
Definition: twr_adc.h:76
@ TWR_ADC_RESOLUTION_8_BIT
ADC 8 bit resolution.
Definition: twr_adc.h:82