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
ADC 32x oversampling.
Definition: twr_adc.h:58
ADC channel A4.
Definition: twr_adc.h:28
twr_adc_oversampling_t
ADC oversampling.
Definition: twr_adc.h:40
bool twr_adc_calibration(void)
Calibration.
Definition: twr_adc.c:344
ADC channel A3.
Definition: twr_adc.h:25
bool twr_adc_get_vdda_voltage(float *vdda_voltage)
Get voltage on VDDA pin.
Definition: twr_adc.c:286
bool twr_adc_is_ready()
Check if ADC is ready for reading.
Definition: twr_adc.c:173
ADC 6 bit resolution.
Definition: twr_adc.h:85
twr_adc_event_t
ADC event.
Definition: twr_adc.h:91
ADC 64x oversampling.
Definition: twr_adc.h:61
ADC channel A2.
Definition: twr_adc.h:22
ADC channel A5.
Definition: twr_adc.h:31
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_get_value(twr_adc_channel_t channel, uint16_t *result)
Reads the ADC channel value.
Definition: twr_adc.c:178
ADC 8x oversampling.
Definition: twr_adc.h:52
ADC channel A0.
Definition: twr_adc.h:16
ADC channel A1.
Definition: twr_adc.h:19
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
ADC event.
Definition: twr_adc.h:94
twr_adc_resolution_t
ADC resolution.
Definition: twr_adc.h:73
ADC 10 bit resolution.
Definition: twr_adc.h:79
ADC 4x oversampling.
Definition: twr_adc.h:49
ADC 256x oversampling.
Definition: twr_adc.h:67
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_async_measure(twr_adc_channel_t channel)
Begins reading the ADC channel voltage in asynchronous mode.
Definition: twr_adc.c:234
bool twr_adc_async_get_voltage(twr_adc_channel_t channel, float *result)
Get asynchronous measurement result in volts.
Definition: twr_adc.c:280
ADC 12 bit resolution.
Definition: twr_adc.h:76
twr_adc_channel_t
ADC channel.
Definition: twr_adc.h:13
ADC 8 bit resolution.
Definition: twr_adc.h:82
ADC no oversampling.
Definition: twr_adc.h:43
ADC channel A6.
Definition: twr_adc.h:34
bool twr_adc_async_get_value(twr_adc_channel_t channel, uint16_t *result)
Get asynchronous measurement result.
Definition: twr_adc.c:274
void twr_adc_init()
Initialize ADC converter.
Definition: twr_adc.c:66
ADC 128x oversampling.
Definition: twr_adc.h:64
ADC 2x oversampling.
Definition: twr_adc.h:46
ADC 16x oversampling.
Definition: twr_adc.h:55