42#define DPS310_BROKEN_RETRY_US 5000000
43#define DPS310_MAX_ERROR_CNT 10
44#define DPS310_PRESSURE_MIN_PA 30000.0f
45#define DPS310_PRESSURE_MAX_PA 120000.0f
49#define DPS310_SCALE_FACTOR_KT 253952.0f
50#define DPS310_SCALE_FACTOR_KP 253952.0f
54#error "DPS310: I2C_BUF_LEN is too small for the 18 byte calibration coefficient read"
74#define DPS310_TEMP_FIX_SEQ_LEN (sizeof(dps310_temp_fix_seq) / sizeof(dps310_temp_fix_seq[0]))
84 if (raw & ((
uint32_t)1 << (length - 1))) {
105 uint32_t)coef[5] >> 4) & 0x0F), 20);
177 dps->i2c_trans.slave_addr = addr;
179 dps->data_available =
false;
180 dps->initialized =
false;
181 dps->is_broken =
false;
182 dps->init_error_cnt = 0;
185 dps->temp_coef_srce = 0;
186 dps->temp_fix_step = 0;
201 if (
dps->is_broken) {
207 dps->is_broken =
false;
208 dps->init_error_cnt = 0;
216 switch (
dps->status) {
218 dps->data_available =
false;
219 dps->initialized =
false;
220 dps->temp_fix_step = 0;
258 dps->i2c_trans.buf[3] = 0x00;
293 switch (
dps->status) {
298 dps->temp_fix_step = 0;
306 dps->temp_fix_step++;
339 dps->initialized =
true;
340 dps->init_error_cnt = 0;
346 dps->init_error_cnt = 0;
350 dps->data_available =
true;
359 dps->init_error_cnt++;
360 if (!
dps->initialized) {
363 dps->is_broken =
true;
369 dps->initialized =
false;
370 dps->data_available =
false;
371 dps->init_error_cnt = 0;
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
#define DPS310_SCALE_FACTOR_KP
pressure, 16x oversampling
#define DPS310_SCALE_FACTOR_KT
temperature, 16x oversampling
#define DPS310_TEMP_FIX_SEQ_LEN
static void parse_sensor_data(struct Dps310_I2c *dps)
Extract the raw 24-bit pressure and temperature measurements.
static void parse_calib_data(struct Dps310_I2c *dps)
Unpack the 18 calibration coefficient bytes (registers 0x10-0x21)
#define DPS310_MAX_ERROR_CNT
consecutive transaction failures before escalating
static const uint8_t dps310_temp_fix_seq[][2]
DPS310 temperature errata fix sequence.
void dps310_i2c_event(struct Dps310_I2c *dps)
Consume finished I2C transactions and advance the state machine.
#define DPS310_PRESSURE_MIN_PA
specified measurement range is 300-1200 hPa,
#define DPS310_PRESSURE_MAX_PA
anything outside means the data got corrupted
static int32_t getTwosComplement(uint32_t raw, uint8_t length)
Sign-extend a raw two's complement value of arbitrary bit length.
static void compensate_sensor(struct Dps310_I2c *dps)
Convert raw measurements into pressure [Pa] and temperature [deg C].
void dps310_i2c_periodic(struct Dps310_I2c *dps)
Run the driver state machine, submitting at most one I2C transaction.
void dps310_i2c_init(struct Dps310_I2c *dps, struct i2c_periph *i2c_p, uint8_t addr)
Initialize the driver instance (no bus traffic yet)
#define DPS310_BROKEN_RETRY_US
retry a failed/absent sensor every 5s instead of giving up forever
Driver for the Infineon DPS310 barometer (I2C)
@ DPS310_STATUS_CONFIGURE_REGS
write PRS_CFG, TMP_CFG, MEAS_CFG (idle) and CFG_REG in one burst
@ DPS310_STATUS_READ_DATA
operational: poll the 6 result registers
@ DPS310_STATUS_GET_COEF_SRCE
read which temperature sensor the factory calibration used
@ DPS310_STATUS_WAIT_RDY
wait for SENSOR_RDY and COEF_RDY (~40ms after power-up)
@ DPS310_STATUS_CONFIGURE_MEAS
enable continuous pressure + temperature measurements
@ DPS310_STATUS_TEMP_FIX
apply the 5-write temperature errata fix (genuine DPS310 only)
@ DPS310_STATUS_GET_ID
read the product/revision ID register
@ DPS310_STATUS_UNINIT
restart point: reset driver state, then detect the sensor
@ DPS310_STATUS_GET_CALIB
read the 18 calibration coefficient bytes
#define DPS310_MEAS_CTRL_CONT
#define DPS310_REG_MEAS_CFG
#define DPS310_COEF_SRCE_BIT_TMP_COEF_SRCE
#define DPS310_REG_COEF_SRCE
#define DPS310_MEAS_CFG_COEF_RDY
#define DPS310_PRS_CFG_PM_PRC_16
#define DPS310_TMP_CFG_TMP_RATE_16HZ
#define DPS310_MEAS_CFG_SENSOR_RDY
#define DPS310_TMP_CFG_TMP_PRC_16
#define DPS310_REG_PSR_B2
#define DPS310_REG_PRS_CFG
#define DPS310_PRS_CFG_PM_RATE_16HZ
#define DPS310_CFG_REG_P_SHIFT
#define DPS310_CFG_REG_T_SHIFT
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
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.
@ I2CTransSuccess
transaction successfully finished by I2C driver
@ I2CTransFailed
transaction failed
@ I2CTransDone
transaction set to done by user level
Architecture independent timing functions.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.