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);
126 uint32_t data_xlsb, data_lsb, data_msb;
133 prs_raw = data_msb | data_lsb | data_xlsb;
140 tmp_raw = data_msb | data_lsb | data_xlsb;
162 Traw_sc * c->
c01 + Traw_sc * Praw_sc * (c->
c11 + Praw_sc * c->
c21);
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).
struct i2c_transaction i2c_trans
I2C transaction (only one in flight at a time).
@ 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
uint8_t temp_fix_step
current step of the temperature errata fix sequence
float pressure
pressure in Pascal
float temperature
temperature in deg Celsius
struct i2c_periph * i2c_p
I2C peripheral used for communication.
uint32_t timer
broken-sensor retry backoff timer
int32_t raw_temperature
uncompensated temperature
enum Dps310Status status
state machine status
volatile bool data_available
data ready flag
bool is_broken
sensor not found or persistently failing, retried after a backoff period
bool initialized
config done flag
int32_t raw_pressure
uncompensated pressure
uint8_t init_error_cnt
number of consecutive transaction failures
uint8_t temp_coef_srce
TMP_COEF_SRCE bit read from the sensor, mirrored into TMP_CFG bit 7.
struct dps310_reg_calib_data calib
calibration data
#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
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
enum I2CTransactionStatus status
Transaction status.
uint8_t slave_addr
Slave address.
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.