45#define SPL06_PRESSURE_OVERSAMPLING SPL06_OVERSAMPLING_64X_P
46#define SPL06_TEMPERATURE_OVERSAMPLING SPL06_OVERSAMPLING_1X_T
49#define SPA06_BROKEN_RETRY_US 5000000
50#define SPA06_MAX_ERROR_CNT 10
51#define SPA06_PRESSURE_MIN_PA 30000.0f
52#define SPA06_PRESSURE_MAX_PA 120000.0f
73 spa->data_available =
false;
74 spa->initialized =
false;
75 spa->is_broken =
false;
79 spa->init_error_cnt = 0;
82 spa->tmp_coef_srce = 0;
94 spa->spi.trans.slave_idx =
spa->spi.slave_idx;
95 spa->spi.trans.output_length = 0;
96 spa->spi.trans.input_length = 0;
97 spa->spi.trans.before_cb =
NULL;
99 spa->spi.trans.input_buf =
spa->spi.rx_buf;
100 spa->spi.trans.output_buf =
spa->spi.tx_buf;
110 spa->i2c.trans.slave_addr =
spa->i2c.slave_addr;
113 spa->rx_buffer =
spa->i2c.trans.buf;
114 spa->tx_buffer =
spa->i2c.trans.buf;
133 if (
spa->is_broken) {
138 spa->is_broken =
false;
139 spa->init_error_cnt = 0;
148 switch (
spa->status) {
150 spa->data_available =
false;
151 spa->initialized =
false;
152 if (
spa->reset ==
false) {
159 if (
spa->reset ==
true) {
196 spa->initialized =
true;
197 spa->init_error_cnt = 0;
235 switch (
spa->status) {
246 spa->init_error_cnt = 0;
250 spa->init_error_cnt = 0;
253 spa->init_error_cnt++;
255 spa->is_broken =
true;
303 spa->init_error_cnt = 0;
307 spa->data_available =
true;
323 spa->init_error_cnt++;
324 if (!
spa->initialized) {
327 spa->is_broken =
true;
338 spa->initialized =
false;
339 spa->data_available =
false;
340 spa->init_error_cnt = 0;
381 switch (
spa->calib_idx) {
390 uint32_t)coef[5] >> 4) & 0x0F), 20);
472 switch (
spa->config_idx) {
525 switch (
spa->calib_idx) {
555 case 0:
return 524288;
556 case 1:
return 1572864;
557 case 2:
return 3670016;
558 case 3:
return 7864320;
559 case 4:
return 253952;
560 case 5:
return 516096;
561 case 6:
return 1040384;
562 case 7:
return 2088960;
584 spa->tx_buffer[0] = (reg & 0x7F);
585 spa->tx_buffer[1] = value;
586 spa->spi.trans.output_length = 2;
587 spa->spi.trans.input_length = 0;
592 spa->tx_buffer[0] = reg;
593 spa->tx_buffer[1] = value;
616 if ((size + 1u) >
sizeof(
spa->spi.rx_buf))
return;
619 spa->spi.trans.output_length = 2;
620 spa->spi.trans.input_length = size + 1;
621 spa->tx_buffer[1] = 0;
628 spa->tx_buffer[0] = reg ;
641 if (raw & (1U << (length - 1))) {
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
#define I2C_BUF_LEN
I2C buffer length.
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
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
@ SPICpolIdleHigh
CPOL = 1.
@ SPISelectUnselect
slave is selected before transaction and unselected after
static void parse_calib_data(struct spa06_t *spa, volatile uint8_t *coef)
Unpack one chunk of calibration coefficient bytes.
static int32_t raw_value_scale_factor(uint8_t oversampling)
Scale factor for raw values at a given oversampling setting.
static void parse_sensor_data(struct spa06_t *spa, volatile uint8_t *data)
Extract the raw 24-bit pressure and temperature measurements.
void spa06_init(struct spa06_t *spa)
Initialize the spa06 sensor instance.
void spa06_event(struct spa06_t *spa)
Should be called in the event thread.
#define SPA06_PRESSURE_MIN_PA
specified measurement range is 300-1200 hPa,
#define SPA06_BROKEN_RETRY_US
retry a failed/absent sensor every 5s instead of giving up forever
static void compensate_pressure(struct spa06_t *spa)
Convert raw measurements into pressure [Pa] and temperature [deg C].
static bool spa06_config(struct spa06_t *spa)
Configure the spa06 device register by register.
#define SPA06_PRESSURE_MAX_PA
anything outside means the data got corrupted
#define SPA06_MAX_ERROR_CNT
consecutive transaction failures before escalating
static bool spa06_get_calib(struct spa06_t *spa)
Request the calibration coefficients, one chunk per call.
void spa06_periodic(struct spa06_t *spa)
Should be called periodically to request sensor readings.
#define SPL06_PRESSURE_OVERSAMPLING
static int32_t getTwosComplement(uint32_t raw, uint8_t length)
Sign-extend a raw two's complement value of arbitrary bit length.
static void spa06_register_write(struct spa06_t *spa, uint8_t reg, uint8_t value)
Write a single register over the configured bus (SPI or I2C)
#define SPL06_TEMPERATURE_OVERSAMPLING
static void spa06_register_read(struct spa06_t *spa, uint8_t reg, uint16_t size)
Read consecutive registers over the configured bus (SPI or I2C)
Driver for the Goertek SPA06-003 / SPL06-001 barometer (I2C or SPI)
@ SPA06_UNKNOWN
not (yet) detected
@ SPA06
SPA06-003, has the extra c31/c40 calibration coefficients.
@ SPA06_STATUS_GET_CALIB
read the calibration coefficients (in chunks)
@ SPA06_STATUS_READ_STATUS_REG
operational: poll until pressure and temperature are ready
@ SPA06_STATUS_UNINIT
restart point: soft reset, then wait 40ms for the sensor to restart
@ SPA06_STATUS_READ_DATA_REGS
operational: read the 6 result registers
@ SPA06_STATUS_CONFIGURE
write the measurement configuration (register by register)
@ SPA06_STATUS_IDLE
read the chip ID to detect the device type
@ SPA06_STATUS_INIT_OK
wait for SENSOR_RDY and COEFFS_RDY
@ SPA06_STATUS_GET_COEF_SRCE
read which temperature sensor the factory calibration used
#define SPL06_REG_PRESSURE_B2
#define SPL06_REG_INT_AND_FIFO_CFG
#define SPL06_REG_CHIP_ID
#define SPL06_PRESSURE_LEN
#define SPL06_RESET_BIT_SOFT_RST
#define SPL06_PRES_RATE_4HZ
#define SPL06_REG_CALIB_COEFFS_START
#define SPL06_TEMPERATURE_LEN
#define SPL06_REG_PRESSURE_CFG
#define SPL06_TEMP_RATE_4HZ
#define SPL06_REG_TEMPERATURE_CFG
#define SPL06_MEAS_CFG_SENSOR_RDY
#define SPL06_MEAS_CFG_TEMPERATURE_RDY
#define SPL06_MEAS_CFG_PRESSURE_RDY
#define SPL06_TEMPERATURE_RESULT_BIT_SHIFT
#define SPL06_PRESSURE_RESULT_BIT_SHIFT
#define SPL06_CHIP_ID
Chip identifiers, register 0x0D: product ID [3:0], revision ID [7:4].
#define SPA06_I2C_ADDR_ALT
#define SPL06_REG_COEF_SRCE
#define SPL06_MEAS_CON_PRE_TEM
#define SPL06_COEF_SRCE_BIT_TMP_COEF_SRCE
#define SPL06_REG_MODE_AND_STATUS
#define SPL06_MEAS_CFG_COEFFS_RDY
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
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.