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
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;
98 spa->spi.trans.after_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;
152 if (spa->
reset ==
false) {
159 if (spa->
reset ==
true) {
162 if (diff_val < 40000) {
390 uint32_t)coef[5] >> 4) & 0x0F), 20);
487 uint8_t int_and_fifo_reg_value = 0;
554 switch (oversampling) {
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;
586 spa->spi.trans.output_length = 2;
587 spa->spi.trans.input_length = 0;
596 i2c_transmit(spa->i2c.p, &(spa->i2c.trans), spa->i2c.slave_addr, 2);
618 if ((size + 1u) >
sizeof(spa->spi.rx_buf))
return;
621 spa->spi.trans.output_length = 2;
622 spa->spi.trans.input_length = size + 1;
633 i2c_transceive(spa->i2c.p, &(spa->i2c.trans), spa->i2c.slave_addr, 1, size);
645 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).
float pressure
pressure in Pascal
uint8_t calib_idx
progress through the calibration chunks (spa06_get_calib/parse_calib_data)
volatile bool data_available
data ready flag
uint8_t init_error_cnt
Number of consecutive transaction failures.
@ SPA06_UNKNOWN
not (yet) detected
@ SPA06
SPA06-003, has the extra c31/c40 calibration coefficients.
float temperature
temperature in deg Celcius
int32_t raw_pressure
uncompensated pressure
enum spa06_status_t status
state machine status
uint8_t tmp_coef_srce
TMP_COEF_SRCE bit read from the sensor, mirrored into TMP_CFG bit 7.
@ 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
uint8_t config_idx
progress through the configuration writes (spa06_config)
int16_t c40
12 bit, SPA06 only
int16_t c0
12 bit, temperature offset
bool reset
reset command sent, waiting for the sensor to restart
int16_t c1
12 bit, temperature gain
struct spa06_reg_calib_data calib
calibration data
enum spa06_bus_t bus
The communication bus used to connect the device SPI/I2C.
bool initialized
config done flag
bool is_broken
sensor absent or persistently failing, retried after a backoff period
volatile uint8_t * tx_buffer
points into the active bus transmit buffer
uint32_t timer
times the 40ms post-reset wait and the broken-sensor retry backoff [us]
int16_t c31
12 bit, SPA06 only
int32_t raw_temperature
uncompensated temperature
int32_t c00
20 bit, pressure offset
volatile uint8_t * rx_buffer
points into the active bus receive buffer (SPI dummy byte already skipped)
enum spa06_device_t device
The device type detected.
#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.