Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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 #ifdef ADC_CHANNEL_GENERIC1
32  adc_buf_channel(ADC_CHANNEL_GENERIC1, &buf_generic1, ADC_CHANNEL_GENERIC_NB_SAMPLES);
33 #endif
34 #ifdef ADC_CHANNEL_GENERIC2
35  adc_buf_channel(ADC_CHANNEL_GENERIC2, &buf_generic2, ADC_CHANNEL_GENERIC_NB_SAMPLES);
36 #endif
37 }
38 
39 void adc_generic_periodic( void ) {
40 #ifdef ADC_CHANNEL_GENERIC1
41  adc_generic_val1 = buf_generic1.sum / buf_generic1.av_nb_sample;
42 #endif
43 #ifdef ADC_CHANNEL_GENERIC2
44  adc_generic_val2 = buf_generic2.sum / buf_generic2.av_nb_sample;
45 #endif
46 
47  DOWNLINK_SEND_ADC_GENERIC(DefaultChannel, DefaultDevice, &adc_generic_val1, &adc_generic_val2);
48 }
49 
#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
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:59
uint16_t adc_generic_val1
Definition: adc_generic.c:8
void adc_generic_periodic(void)
Definition: adc_generic.c:39
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_generic_init(void)
Definition: adc_generic.c:30
uint16_t adc_generic_val2
Definition: adc_generic.c:9