Paparazzi UAS  v5.18.0_stable
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 "subsystems/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 }
BARO_SCP_IDLE
#define BARO_SCP_IDLE
Definition: baro_scp_i2c.h:18
uint16_t
unsigned short uint16_t
Definition: types.h:16
i2c_transaction::buf
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
SCP1000_HIGH_RES
#define SCP1000_HIGH_RES
Definition: baro_scp_i2c.h:9
BARO_SCP_RD_PRESS_0
#define BARO_SCP_RD_PRESS_0
Definition: baro_scp_i2c.h:20
baro_scp_start_high_res_measurement
static void baro_scp_start_high_res_measurement(void)
Definition: baro_scp_i2c.c:36
abi.h
uint32_t
unsigned long uint32_t
Definition: types.h:18
baro_scp_event
void baro_scp_event(void)
Definition: baro_scp_i2c.c:65
SCP_I2C_DEV
#define SCP_I2C_DEV
Definition: baro_scp_i2c.c:31
SCP1000_SLAVE_ADDR
#define SCP1000_SLAVE_ADDR
Definition: baro_scp_i2c.c:34
BARO_SCP_RD_TEMP
#define BARO_SCP_RD_TEMP
Definition: baro_scp_i2c.h:19
I2CTransSuccess
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
i2c_transmit
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
SCP1000_TEMPOUT
#define SCP1000_TEMPOUT
Definition: baro_scp_i2c.h:15
BARO_SCP_SENDER_ID
#define BARO_SCP_SENDER_ID
Definition: abi_sender_ids.h:68
scp_trans
struct i2c_transaction scp_trans
Definition: baro_scp_i2c.c:28
BARO_SCP_RD_PRESS_1
#define BARO_SCP_RD_PRESS_1
Definition: baro_scp_i2c.h:21
i2c_transceive
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
sys_time.h
Architecture independent timing functions.
uint8_t
unsigned char uint8_t
Definition: types.h:14
i2c_transaction::status
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
baro_scp_periodic
void baro_scp_periodic(void)
Definition: baro_scp_i2c.c:49
BARO_SCP_UNINIT
#define BARO_SCP_UNINIT
Definition: baro_scp_i2c.h:17
led.h
arch independent LED (Light Emitting Diodes) API
i2c_transaction
I2C transaction structure.
Definition: i2c.h:93
baro_scp_init
void baro_scp_init(void)
Definition: baro_scp_i2c.c:44
SCP1000_DATARD8
#define SCP1000_DATARD8
Definition: baro_scp_i2c.h:13
baro_scp_temperature
uint16_t baro_scp_temperature
Definition: baro_scp_i2c.c:26
sys_time
Definition: sys_time.h:71
SCP1000_OPERATION
#define SCP1000_OPERATION
Definition: baro_scp_i2c.h:6
baro_scp_status
uint8_t baro_scp_status
Definition: baro_scp_i2c.c:24
baro_scp_pressure
uint32_t baro_scp_pressure
Definition: baro_scp_i2c.c:25
sys_time::nb_sec
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
SCP1000_DATARD16
#define SCP1000_DATARD16
Definition: baro_scp_i2c.h:14
baro_scp_i2c.h
i2c.h