Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
baro_scp_i2c.c
Go to the documentation of this file.
1 
8 #include "baro_scp_i2c.h"
9 
10 #include "mcu_periph/sys_time.h"
11 #include "mcu_periph/i2c.h"
12 #include "modules/core/abi.h"
13 #include "led.h"
14 
15 #include "mcu_periph/uart.h"
16 #include "pprzlink/messages.h"
18 
19 #ifndef SENSOR_SYNC_SEND
20 #warning set SENSOR_SYNC_SEND to use baro_scp_i2c
21 #endif
22 
23 
27 
29 
30 #ifndef SCP_I2C_DEV
31 #define SCP_I2C_DEV i2c0
32 #endif
33 
34 #define SCP1000_SLAVE_ADDR 0x22
35 
37 {
38  /* switch to high resolution */
42 }
43 
44 void baro_scp_init(void)
45 {
47 }
48 
50 {
51 
53 
56  } else if (baro_scp_status == BARO_SCP_IDLE) {
57 
58  /* init: start two byte temperature */
62  }
63 }
64 
65 void baro_scp_event(void)
66 {
67 
69 
71 
72  /* read two byte temperature */
75  if (baro_scp_temperature & 0x2000) {
76  baro_scp_temperature |= 0xC000;
77  }
79 
80  /* start one byte msb pressure */
84  }
85 
87 
88  /* read one byte pressure */
89  baro_scp_pressure = scp_trans.buf[0] << 16;
90 
91  /* start two byte lsb pressure */
95  }
96 
98 
99  /* read two byte pressure */
100  baro_scp_pressure |= scp_trans.buf[0] << 8;
102  baro_scp_pressure *= 25;
103 
104  uint32_t now_ts = get_sys_time_usec();
105  float pressure = (float) baro_scp_pressure;
106  AbiSendMsgBARO_ABS(BARO_SCP_SENDER_ID, now_ts, pressure);
107 #ifdef SENSOR_SYNC_SEND
109 #endif
110 
112  }
113 
114  else { baro_scp_status = BARO_SCP_IDLE; }
115  }
116 }
Main include for ABI (AirBorneInterface).
#define BARO_SCP_SENDER_ID
#define SCP1000_SLAVE_ADDR
Definition: baro_scp_i2c.c:34
uint32_t baro_scp_pressure
Definition: baro_scp_i2c.c:25
uint8_t baro_scp_status
Definition: baro_scp_i2c.c:24
static void baro_scp_start_high_res_measurement(void)
Definition: baro_scp_i2c.c:36
void baro_scp_event(void)
Definition: baro_scp_i2c.c:65
void baro_scp_periodic(void)
Definition: baro_scp_i2c.c:49
void baro_scp_init(void)
Definition: baro_scp_i2c.c:44
#define SCP_I2C_DEV
Definition: baro_scp_i2c.c:31
struct i2c_transaction scp_trans
Definition: baro_scp_i2c.c:28
uint16_t baro_scp_temperature
Definition: baro_scp_i2c.c:26
#define SCP1000_DATARD16
Definition: baro_scp_i2c.h:14
#define BARO_SCP_RD_TEMP
Definition: baro_scp_i2c.h:19
#define BARO_SCP_UNINIT
Definition: baro_scp_i2c.h:17
#define BARO_SCP_IDLE
Definition: baro_scp_i2c.h:18
#define BARO_SCP_RD_PRESS_1
Definition: baro_scp_i2c.h:21
#define SCP1000_OPERATION
Definition: baro_scp_i2c.h:6
#define SCP1000_TEMPOUT
Definition: baro_scp_i2c.h:15
#define BARO_SCP_RD_PRESS_0
Definition: baro_scp_i2c.h:20
#define SCP1000_HIGH_RES
Definition: baro_scp_i2c.h:9
#define SCP1000_DATARD8
Definition: baro_scp_i2c.h:13
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:71
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition: i2c.c:324
bool i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Submit a write/read transaction.
Definition: i2c.c:344
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
I2C transaction structure.
Definition: i2c.h:93
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
arch independent LED (Light Emitting Diodes) API
Architecture independent timing functions.
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98