Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
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 #ifndef DOWNLINK_DEVICE
22 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
23 #endif
24 
25 #ifdef ADC_CHANNEL_GENERIC1
26 static struct adc_buf buf_generic1;
27 #endif
28 
29 #ifdef ADC_CHANNEL_GENERIC2
30 static struct adc_buf buf_generic2;
31 #endif
32 
33 void adc_generic_init( void ) {
34 #ifdef ADC_CHANNEL_GENERIC1
35  adc_buf_channel(ADC_CHANNEL_GENERIC1, &buf_generic1, ADC_CHANNEL_GENERIC_NB_SAMPLES);
36 #endif
37 #ifdef ADC_CHANNEL_GENERIC2
38  adc_buf_channel(ADC_CHANNEL_GENERIC2, &buf_generic2, ADC_CHANNEL_GENERIC_NB_SAMPLES);
39 #endif
40 }
41 
42 void adc_generic_periodic( void ) {
43 #ifdef ADC_CHANNEL_GENERIC1
44  adc_generic_val1 = buf_generic1.sum / buf_generic1.av_nb_sample;
45 #endif
46 #ifdef ADC_CHANNEL_GENERIC2
47  adc_generic_val2 = buf_generic2.sum / buf_generic2.av_nb_sample;
48 #endif
49 
50  DOWNLINK_SEND_ADC_GENERIC(DefaultChannel, DefaultDevice, &adc_generic_val1, &adc_generic_val2);
51 }
52 
#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:42
arch independent ADC (Analog to Digital Converter) API
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:60
void adc_generic_init(void)
Definition: adc_generic.c:33
uint16_t adc_generic_val2
Definition: adc_generic.c:9