Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
enose.c
Go to the documentation of this file.
1 #include <string.h>
2 
3 #include "modules/enose/enose.h"
4 
5 #include "mcu_periph/i2c.h"
6 #include "mcu_periph/adc.h"
7 #include BOARD_CONFIG
8 
9 
14 
15 #define ENOSE_SLAVE_ADDR 0xAE
16 #define ENOSE_PWM_ADDR 0x06
17 #define ENOSE_DATA_ADDR 0x00
18 #define ENOSE_HEAT_INIT 237
19 
21 static volatile bool enose_i2c_done;
22 static struct adc_buf buf_PID;
23 
24 
25 void enose_init(void)
26 {
27  uint8_t i;
28  for (i = 0; i < ENOSE_NB_SENSOR; i++) {
30  enose_val[i] = 0;
31  }
33  enose_conf_requested = true;
34  enose_i2c_done = true;
35 
36 #ifdef ADC_CHANNEL_PID
37  adc_buf_channel(ADC_CHANNEL_PID, &buf_PID, ADC_CHANNEL_PID_NB_SAMPLES);
38 #endif
39 }
40 
41 
42 void enose_set_heat(uint8_t no_sensor, uint8_t value)
43 {
44  enose_heat[no_sensor] = value;
45  enose_conf_requested = true;
46 }
47 
48 
49 #include "mcu_periph/uart.h"
50 #include "pprzlink/messages.h"
52 
53 void enose_periodic(void)
54 {
56 
57  if (enose_i2c_done) {
59  const uint8_t msg[] = { ENOSE_PWM_ADDR, enose_heat[0], enose_heat[1], enose_heat[2] };
60  memcpy((void *)i2c0_buf, msg, sizeof(msg));
61  i2c0_transmit(ENOSE_SLAVE_ADDR, sizeof(msg), &enose_i2c_done);
62  enose_i2c_done = false;
63  enose_conf_requested = false;
64  } else if (enose_status == ENOSE_IDLE) {
66  const uint8_t msg[] = { ENOSE_DATA_ADDR };
67  memcpy((void *)i2c0_buf, msg, sizeof(msg));
68  i2c0_transmit(ENOSE_SLAVE_ADDR, sizeof(msg), &enose_i2c_done);
69  enose_i2c_done = false;
70  } else if (enose_status == ENOSE_MEASURING_WR) {
72  i2c0_receive(ENOSE_SLAVE_ADDR, 6, &enose_i2c_done);
73  enose_i2c_done = false;
74  } else if (enose_status == ENOSE_MEASURING_RD) {
75  uint16_t val = (i2c0_buf[0] << 8) | i2c0_buf[1];
76  if (val < 5000) {
77  enose_val[0] = val;
78  }
79  val = (i2c0_buf[2] << 8) | i2c0_buf[3];
80  if (val < 5000) {
81  enose_val[1] = val;
82  }
83  val = (i2c0_buf[4] << 8) | i2c0_buf[5];
84  if (val < 5000) {
85  enose_val[2] = val;
86  }
88  }
89  }
90  DOWNLINK_SEND_ENOSE_STATUS(DefaultChannel, DefaultDevice, &enose_val[0], &enose_val[1], &enose_val[2], &enose_PID_val,
91  3, enose_heat);
92 }
uint8_t av_nb_sample
Definition: adc.h:57
unsigned short uint16_t
Definition: types.h:16
void enose_periodic(void)
Definition: enose.c:53
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define ENOSE_SLAVE_ADDR
Definition: enose.c:15
void enose_set_heat(uint8_t no_sensor, uint8_t value)
Definition: enose.c:42
#define ENOSE_HEAT_INIT
Definition: enose.c:18
static struct adc_buf buf_PID
Definition: enose.c:22
uint16_t enose_val[ENOSE_NB_SENSOR]
Definition: enose.c:12
#define ENOSE_MEASURING_RD
Definition: enose.h:15
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Link between ChibiOS ADC drivers and Paparazzi adc_buffers.
Definition: adc_arch.c:265
uint32_t sum
Definition: adc.h:54
arch independent ADC (Analog to Digital Converter) API
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
void enose_init(void)
Definition: enose.c:25
uint16_t val[TCOUPLE_NB]
uint8_t enose_status
Definition: enose.c:10
#define ENOSE_DATA_ADDR
Definition: enose.c:17
static uint8_t enose_conf_requested
Definition: enose.c:20
#define ENOSE_PWM_ADDR
Definition: enose.c:16
uint16_t enose_PID_val
Definition: enose.c:13
unsigned char uint8_t
Definition: types.h:14
#define ENOSE_NB_SENSOR
Definition: enose.h:6
uint8_t enose_heat[ENOSE_NB_SENSOR]
Definition: enose.c:11
#define ENOSE_IDLE
Definition: enose.h:12
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
#define ENOSE_MEASURING_WR
Definition: enose.h:14
static volatile bool enose_i2c_done
Definition: enose.c:21
Architecture independent I2C (Inter-Integrated Circuit Bus) API.