Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
adc_generic.c
Go to the documentation of this file.
1 #include "adc_generic.h"
2 #include "mcu_periph/adc.h"
3 #include "mcu_periph/uart.h"
4 #include "messages.h"
6 #include BOARD_CONFIG
7 
10 
11 #ifndef ADC_CHANNEL_GENERIC1
12 #ifndef ADC_CHANNEL_GENERIC2
13 #error "at least one ADC_CHANNEL_GENERIC1/2 needs to be defined to use the generic_adc module"
14 #endif
15 #endif
16 
17 #ifndef ADC_CHANNEL_GENERIC_NB_SAMPLES
18 #define ADC_CHANNEL_GENERIC_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
19 #endif
20 
21 
22 #ifdef ADC_CHANNEL_GENERIC1
23 static struct adc_buf buf_generic1;
24 #endif
25 
26 #ifdef ADC_CHANNEL_GENERIC2
27 static struct adc_buf buf_generic2;
28 #endif
29 
30 void adc_generic_init(void)
31 {
32 #ifdef ADC_CHANNEL_GENERIC1
33  adc_buf_channel(ADC_CHANNEL_GENERIC1, &buf_generic1, ADC_CHANNEL_GENERIC_NB_SAMPLES);
34 #endif
35 #ifdef ADC_CHANNEL_GENERIC2
36  adc_buf_channel(ADC_CHANNEL_GENERIC2, &buf_generic2, ADC_CHANNEL_GENERIC_NB_SAMPLES);
37 #endif
38 }
39 
41 {
42 #ifdef ADC_CHANNEL_GENERIC1
43  adc_generic_val1 = buf_generic1.sum / buf_generic1.av_nb_sample;
44 #endif
45 #ifdef ADC_CHANNEL_GENERIC2
46  adc_generic_val2 = buf_generic2.sum / buf_generic2.av_nb_sample;
47 #endif
48 
49  DOWNLINK_SEND_ADC_GENERIC(DefaultChannel, DefaultDevice, &adc_generic_val1, &adc_generic_val2);
50 }
51 
#define ADC_CHANNEL_GENERIC_NB_SAMPLES
Definition: adc_generic.c:18
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint16_t adc_generic_val1
Definition: adc_generic.c:8
void adc_generic_periodic(void)
Definition: adc_generic.c:40
arch independent ADC (Analog to Digital Converter) API
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Registers a buffer to be used to store the specified converted channel Usage:
Definition: adc_arch.c:91
void adc_generic_init(void)
Definition: adc_generic.c:30
uint16_t adc_generic_val2
Definition: adc_generic.c:9