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
infrared_adc.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2010 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
30 #include <stdlib.h>
31 
33 #include "mcu_periph/adc.h"
34 
35 #include BOARD_CONFIG
36 #include "generated/airframe.h"
37 
38 // TODO Specific sim implementation
39 #if ! (defined SITL || defined HITL)
40 static struct adc_buf buf_ir1;
41 static struct adc_buf buf_ir2;
42 
43 #ifdef ADC_CHANNEL_IR_TOP
44 static struct adc_buf buf_ir3;
45 #endif
46 #endif
47 
48 #ifndef ADC_CHANNEL_IR_NB_SAMPLES
49 #define ADC_CHANNEL_IR_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
50 #endif
51 
53 
54 // Standard infrared implementation
55 void infrared_init(void) {
57 }
58 
59 void infrared_update(void) {
61 }
62 
63 /* No event with adc ir */
64 void infrared_event(void) {}
65 
69 void infrared_adc_init(void) {
70 #if ! (defined SITL || defined HITL)
73 #ifdef ADC_CHANNEL_IR_TOP
74  adc_buf_channel(ADC_CHANNEL_IR_TOP, &buf_ir3, ADC_CHANNEL_IR_NB_SAMPLES);
75 #endif
76 #endif
77 
79 
80 #if ! (defined ADC_CHANNEL_IR_TOP || defined HITL || defined SITL)
81  ir_adc.ir3 = IR_DEFAULT_CONTRAST;
82 #endif
83 }
84 
85 
89 void infrared_adc_update(void) {
90 #if ! (defined SITL || defined HITL)
91  ir_adc.ir1 = (int32_t)(buf_ir1.sum/buf_ir1.av_nb_sample) - IR_ADC_IR1_NEUTRAL;
92  ir_adc.ir2 = (int32_t)(buf_ir2.sum/buf_ir2.av_nb_sample) - IR_ADC_IR2_NEUTRAL;
93 #ifdef ADC_CHANNEL_IR_TOP
94  ir_adc.ir3 = (int32_t)(buf_ir3.sum/buf_ir3.av_nb_sample) - IR_ADC_TOP_NEUTRAL;
95 #endif // IR_TOP
97 #endif /* !SITL && !HITL */
98 }
99 
#define ADC_CHANNEL_IR_NB_SAMPLES
Definition: infrared_adc.c:49
void infrared_init(void)
Definition: infrared_adc.c:55
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
void infrared_update(void)
Definition: infrared_adc.c:59
int16_t ir2
Definition: infrared.h:113
struct Infrared_raw ir_adc
Definition: infrared_adc.c:52
void infrared_event(void)
Definition: infrared_adc.c:64
uint8_t av_nb_sample
Definition: adc.h:64
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:61
void infrared_struct_init(void)
Initialisation of ir structure.
Definition: infrared.c:38
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:60
#define UpdateIRValue(_v)
Definition: infrared.h:149
signed long int32_t
Definition: types.h:19
void infrared_adc_init(void)
Initialisation of ir.
Definition: infrared_adc.c:69
static struct adc_buf buf_ir1
Definition: infrared_adc.c:40
int16_t ir1
Definition: infrared.h:112
void infrared_adc_update(void)
Update ir_roll and ir_pitch from ADCs or from simulator message in HITL and SITL modes.
Definition: infrared_adc.c:89
static struct adc_buf buf_ir2
Definition: infrared_adc.c:41
int16_t ir3
Definition: infrared.h:114