Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
spa06.h File Reference

Driver for the Goertek SPA06-003 / SPL06-001 barometer (I2C or SPI) More...

+ Include dependency graph for spa06.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  spa06_i2c_t
 I2C bus configuration and transaction state. More...
 
struct  spa06_spi_t
 SPI bus configuration and transaction state. More...
 
struct  spa06_reg_calib_data
 Factory calibration coefficients (register trim values) More...
 
struct  spa06_t
 Driver instance state. More...
 
union  spa06_t.__unnamed358__
 

Enumerations

enum  spa06_bus_t { SPA06_SPI , SPA06_I2C }
 Communication busses the spa06 driver can use. More...
 
enum  spa06_device_t { SPA06_UNKNOWN , SPA06 , SPL06 }
 Device type, detected from the chip ID during initialization. More...
 
enum  spa06_status_t {
  SPA06_STATUS_UNINIT , SPA06_STATUS_IDLE , SPA06_STATUS_INIT_OK , SPA06_STATUS_GET_COEF_SRCE ,
  SPA06_STATUS_GET_CALIB , SPA06_STATUS_CONFIGURE , SPA06_STATUS_READ_STATUS_REG , SPA06_STATUS_READ_DATA_REGS
}
 States of the non-blocking driver state machine. More...
 

Functions

void spa06_init (struct spa06_t *spa)
 Initialize the driver instance, expects bus and i2c/spi members to be pre-filled.
 
void spa06_periodic (struct spa06_t *spa)
 Run the state machine, submits at most one bus transaction; call periodically.
 
void spa06_event (struct spa06_t *spa)
 Handle finished transactions and publish measurements; call from the event loop.
 

Detailed Description

Driver for the Goertek SPA06-003 / SPL06-001 barometer (I2C or SPI)

Definition in file spa06.h.


Data Structure Documentation

◆ spa06_i2c_t

struct spa06_i2c_t

I2C bus configuration and transaction state.

Definition at line 37 of file spa06.h.

+ Collaboration diagram for spa06_i2c_t:
Data Fields
struct i2c_periph * p Peripheral device for communication.
uint8_t slave_addr The I2C slave address on the bus.
struct i2c_transaction trans Transaction used during configuration and measurements.

◆ spa06_spi_t

struct spa06_spi_t

SPI bus configuration and transaction state.

Definition at line 44 of file spa06.h.

+ Collaboration diagram for spa06_spi_t:
Data Fields
struct spi_periph * p Peripheral device for communication.
uint8_t rx_buf[50] Receive buffer (dummy byte + response)
uint8_t slave_idx Slave index used for Slave Select.
struct spi_transaction trans Transaction used during configuration and measurements.
uint8_t tx_buf[50] Transmit buffer (command byte + payload)

◆ spa06_reg_calib_data

struct spa06_reg_calib_data

Factory calibration coefficients (register trim values)

Mixed-width two's complement values unpacked from the COEF registers. c31 and c40 only exist on the SPA06 and are zero on the SPL06.

Definition at line 90 of file spa06.h.

Data Fields
int16_t c0 12 bit, temperature offset
int32_t c00 20 bit, pressure offset
int16_t c01 16 bit
int16_t c1 12 bit, temperature gain
int32_t c10 20 bit
int16_t c11 16 bit
int16_t c20 16 bit
int16_t c21 16 bit
int16_t c30 16 bit
int16_t c31 12 bit, SPA06 only
int16_t c40 12 bit, SPA06 only

◆ spa06_t

struct spa06_t

Driver instance state.

Fill in bus, and the i2c/spi member for that bus, before calling spa06_init(). Consumers read pressure/temperature when data_available is true and clear the flag themselves.

Definition at line 110 of file spa06.h.

+ Collaboration diagram for spa06_t:
Data Fields
union spa06_t.__unnamed358__ __unnamed__
enum spa06_bus_t bus The communication bus used to connect the device SPI/I2C.
struct spa06_reg_calib_data calib calibration data
uint8_t calib_idx progress through the calibration chunks (spa06_get_calib/parse_calib_data)
uint8_t config_idx progress through the configuration writes (spa06_config)
volatile bool data_available data ready flag
enum spa06_device_t device The device type detected.
uint8_t init_error_cnt Number of consecutive transaction failures.
bool initialized config done flag
bool is_broken sensor absent or persistently failing, retried after a backoff period
float pressure pressure in Pascal
int32_t raw_pressure uncompensated pressure
int32_t raw_temperature uncompensated temperature
bool reset reset command sent, waiting for the sensor to restart
volatile uint8_t * rx_buffer points into the active bus receive buffer (SPI dummy byte already skipped)
enum spa06_status_t status state machine status
float temperature temperature in deg Celcius
uint32_t timer times the 40ms post-reset wait and the broken-sensor retry backoff [us]
uint8_t tmp_coef_srce TMP_COEF_SRCE bit read from the sensor, mirrored into TMP_CFG bit 7.
volatile uint8_t * tx_buffer points into the active bus transmit buffer

◆ spa06_t.__unnamed358__

union spa06_t.__unnamed358__

Definition at line 126 of file spa06.h.

Data Fields
struct spa06_i2c_t i2c I2C specific configuration.
struct spa06_spi_t spi SPI specific configuration.

Enumeration Type Documentation

◆ spa06_bus_t

Communication busses the spa06 driver can use.

Enumerator
SPA06_SPI 
SPA06_I2C 

Definition at line 54 of file spa06.h.

◆ spa06_device_t

Device type, detected from the chip ID during initialization.

Enumerator
SPA06_UNKNOWN 

not (yet) detected

SPA06 

SPA06-003, has the extra c31/c40 calibration coefficients.

SPL06 

SPL06-001.

Definition at line 60 of file spa06.h.

◆ spa06_status_t

States of the non-blocking driver state machine.

Traversed once in order during initialization, then the driver alternates between READ_STATUS_REG and READ_DATA_REGS. Any failure path leads back to SPA06_STATUS_UNINIT.

Enumerator
SPA06_STATUS_UNINIT 

restart point: soft reset, then wait 40ms for the sensor to restart

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

SPA06_STATUS_GET_CALIB 

read the calibration coefficients (in chunks)

SPA06_STATUS_CONFIGURE 

write the measurement configuration (register by register)

SPA06_STATUS_READ_STATUS_REG 

operational: poll until pressure and temperature are ready

SPA06_STATUS_READ_DATA_REGS 

operational: read the 6 result registers

Definition at line 73 of file spa06.h.

Function Documentation

◆ spa06_event()

void spa06_event ( struct spa06_t spa)
extern

Handle finished transactions and publish measurements; call from the event loop.

Handle finished transactions and publish measurements; call from the event loop.

  • Configures the sensor and reads the responses
  • Parses the responses and publishes plausibility-checked measurements through data_available

On a failed transaction it counts consecutive errors, escalating from a simple retry to a full re-initialization (SPA06_MAX_ERROR_CNT) and, while uninitialized, to a timed backoff. During initialization the I2C address is hot-swapped between the two possible assignments on every failure.

Parameters
spaThe spa06 instance

Definition at line 230 of file spa06.c.

References compensate_pressure(), foo, get_sys_time_usec(), I2CTransDone, I2CTransFailed, I2CTransSuccess, parse_calib_data(), parse_sensor_data(), SPA06, SPA06_CHIP_ID, SPA06_I2C, SPA06_I2C_ADDR, SPA06_I2C_ADDR_ALT, SPA06_MAX_ERROR_CNT, SPA06_PRESSURE_MAX_PA, SPA06_PRESSURE_MIN_PA, SPA06_SPI, SPA06_STATUS_CONFIGURE, SPA06_STATUS_GET_CALIB, SPA06_STATUS_GET_COEF_SRCE, SPA06_STATUS_IDLE, SPA06_STATUS_INIT_OK, SPA06_STATUS_READ_DATA_REGS, SPA06_STATUS_READ_STATUS_REG, SPA06_STATUS_UNINIT, SPITransDone, SPITransFailed, SPITransSuccess, SPL06, SPL06_CHIP_ID, SPL06_COEF_SRCE_BIT_TMP_COEF_SRCE, SPL06_MEAS_CFG_COEFFS_RDY, SPL06_MEAS_CFG_PRESSURE_RDY, SPL06_MEAS_CFG_SENSOR_RDY, SPL06_MEAS_CFG_TEMPERATURE_RDY, and status.

Referenced by baro_spa06_event().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spa06_init()

void spa06_init ( struct spa06_t spa)
extern

Initialize the driver instance, expects bus and i2c/spi members to be pre-filled.

Initialize the driver instance, expects bus and i2c/spi members to be pre-filled.

Parameters
spaThe structure containing the configuration of the spa06 instance

Definition at line 71 of file spa06.c.

References foo, I2CTransDone, SPA06_SPI, SPA06_STATUS_UNINIT, SPA06_UNKNOWN, SPICphaEdge2, SPICpolIdleHigh, SPIDiv16, SPIDss8bit, SPIMSBFirst, SPISelectUnselect, and SPITransDone.

Referenced by baro_spa06_init().

+ Here is the caller graph for this function:

◆ spa06_periodic()

void spa06_periodic ( struct spa06_t spa)
extern

Run the state machine, submits at most one bus transaction; call periodically.

Run the state machine, submits at most one bus transaction; call periodically.

  • First detects the sensor using WHO_AM_I reading
  • Configures the sensor according the users requested configuration
  • Requests a sensor reading

Submits at most one bus transaction per call and does nothing while a transaction is still in flight. A persistently failing or absent sensor is retried after a SPA06_BROKEN_RETRY_US backoff instead of spamming the bus.

Parameters
spaThe spa06 instance

Definition at line 131 of file spa06.c.

References foo, get_sys_time_usec(), I2CTransDone, SPA06_BROKEN_RETRY_US, spa06_config(), spa06_get_calib(), SPA06_I2C, spa06_register_read(), spa06_register_write(), SPA06_SPI, SPA06_STATUS_CONFIGURE, SPA06_STATUS_GET_CALIB, SPA06_STATUS_GET_COEF_SRCE, SPA06_STATUS_IDLE, SPA06_STATUS_INIT_OK, SPA06_STATUS_READ_DATA_REGS, SPA06_STATUS_READ_STATUS_REG, SPA06_STATUS_UNINIT, SPITransDone, SPL06_PRESSURE_LEN, SPL06_REG_CHIP_ID, SPL06_REG_COEF_SRCE, SPL06_REG_MODE_AND_STATUS, SPL06_REG_PRESSURE_B2, SPL06_REG_RST, SPL06_RESET_BIT_SOFT_RST, and SPL06_TEMPERATURE_LEN.

Referenced by baro_spa06_periodic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: