29#define K_BMP390_TASK_TIMEOUT_MS 5000U
30#define K_BMP390_TAG "BMP390"
53 float t_lin,
spp_uint32_t *raw_press,
float *comp_press);
55 float *temperature_c);
59#define K_BMP390_PERFORMANCE_SAMPLES (10000U)
177 float altitude = 0.0f;
178 float pressure = 0.0f;
179 float temperature = 0.0f;
188 if (p_packet == NULL)
221#ifdef SPP_DEBUG_PRINT
222 SPP_LOGI(
K_BMP390_TAG,
"[BMP] alt=%.1fm P=%.1fhPa T=%.2fC\n", altitude, pressure / 100.0f, temperature);
226 spp_float32_t payload[3] = {altitude, pressure, temperature};
392 tcalib->
par_t1 = (uint16_t)((raw[1] << 8) | raw[0]);
393 tcalib->
par_t2 = (int16_t)((raw[3] << 8) | raw[2]);
394 tcalib->
par_t3 = (int8_t)raw[4];
463 float partial1 = (float)raw_temp - params->
PAR_T1;
464 float partial2 = partial1 * params->
PAR_T2;
465 float t_lin = partial2 + (partial1 * partial1) * params->
PAR_T3;
560 for (
int i = 0; i < 16; i++)
562 raw[i] = buf[3 * i + 2];
663 s_pd1 = raw_press * raw_press;
683 float t_lin,
spp_uint32_t *raw_press,
float *comp_press)
711 float *temperature_c)
713 if ((p_spiHandler == NULL) || (altitude_m == NULL) || (pressure_pa == NULL) || (temperature_c == NULL))
725 float compPress = 0.0f;
727 if (s_inited ==
false)
756 *temperature_c = t_lin;
757 *pressure_pa = compPress;
758 *altitude_m = 44330.0f * (1.0f - powf(compPress / 101325.0f, 1.0f / 5.255f));
static SPP_RetVal_t SPP_SERVICES_BMP390_readRawPress(void *p_spiHandler, spp_uint32_t *raw_press)
Reads the 24-bit raw pressure ADC value from the sensor.
static SPP_RetVal_t SPP_SERVICES_BMP390_readRawTemp(void *p_spiHandler, uint32_t *raw_temp)
Reads the 24-bit raw temperature ADC value from the sensor.
static SPP_RetVal_t SPP_SERVICES_BMP390_configCheck(void *p_spiHandler)
Reads the chip-ID register and returns an error if the value is not 0x60.
static SPP_RetVal_t SPP_SERVICES_BMP390_auxConfig(void *p_spiHandler)
Resets the sensor, enables SPI mode, and verifies the chip ID.
static const SPP_SERVICE_ProducerContract_t g_bmp390ProducerContract
static SPP_RetVal_t SPP_SERVICES_BMP390_readRawPressCoeffs(void *p_spiHandler, BMP390_press_calib_t *pcalib)
Reads raw pressure calibration coefficients from the sensor's NVM registers.
static SPP_RetVal_t SPP_SERVICES_BMP390_enableSpiMode(void *p_spiHandler)
Writes the interface-config register to lock the sensor into SPI mode.
static float SPP_SERVICES_BMP390_compensatePressure(spp_uint32_t raw_press, float t_lin, BMP390_press_params_t *p)
Applies the BMP390 pressure compensation formula using the linearised temperature.
static const char *const k_svcTag
#define K_BMP390_TASK_TIMEOUT_MS
static SPP_RetVal_t SPP_SERVICES_BMP390_readRawTempCoeffs(void *p_spiHandler, BMP390_temp_calib_t *tcalib)
Polls the DRDY flag until set or until the timeout elapses.
static float SPP_SERVICES_BMP390_compensateTemperature(spp_uint32_t raw_temp, BMP390_temp_params_t *params)
Applies the BMP390 double-quadratic temperature compensation formula.
static SPP_RetVal_t SPP_SERVICES_BMP390_auxGetTemp(void *p_spiHandler, const BMP390_temp_params_t *temp_params, spp_uint32_t *raw_temp, float *comp_temp)
Reads the raw temperature ADC and returns the compensated value.
static SPP_RetVal_t SPP_SERVICES_BMP390_init(void)
BMP390 sensor instance initialisation. This function is called by the service task....
const SPP_SERVICE_ProducerContract_t * SPP_SERVICES_BMP390_getProducerContract(void)
static SPP_RetVal_t SPP_SERVICES_BMP390_calibrateTempParams(void *p_spiHandler, BMP390_temp_params_t *out)
Reads raw temperature coefficients and scales them to floating-point parameters.
static SPP_RetVal_t SPP_SERVICES_BMP390_calibratePressParams(void *p_spiHandler, BMP390_press_params_t *out)
Reads raw pressure coefficients and scales them to floating-point parameters.
static BMP390_t s_bmpData
static SPP_RetVal_t SPP_SERVICES_BMP390_prepareMeasure(void *p_spiHandler)
Writes OSR, ODR, IIR and power-control registers to start continuous measurements.
static SPP_RetVal_t SPP_SERVICES_BMP390_acquireData(SPP_Kpid_t kpid)
Acquisition callback invoked by the SPP service task on each cycle.
static SPP_RetVal_t SPP_SERVICES_BMP390_intEnableDrdy(void *p_spiHandler)
Enables the active-high data-ready interrupt output on the sensor.
static SPP_RetVal_t SPP_SERVICES_BMP390_softReset(void *p_spiHandler)
Sends a soft-reset command to the sensor and waits 100 ms for it to reboot.
static SPP_RetVal_t SPP_SERVICES_BMP390_auxGetPress(void *p_spiHandler, const BMP390_press_params_t *press_params, float t_lin, spp_uint32_t *raw_press, float *comp_press)
Reads raw pressure ADC and returns the compensated value in Pa.
static SPP_RetVal_t SPP_SERVICES_BMP390_getAltitude(void *p_spiHandler, float *altitude_m, float *pressure_pa, float *temperature_c)
Reads compensated altitude, pressure and temperature from the sensor.
BMP390 barometric pressure sensor driver and service.
#define K_BMP390_TEMP_RAW_REG
#define K_BMP390_PRESS_CALIB_REG_START
#define K_BMP390_IF_CONF_REG
#define K_BMP390_INT_PIN_NUM
#define BMP390_VALUE_PWRCTRL
#define K_BMP390_SPI_READ
#define K_BMP390_SPI_BUS_IDX
#define BMP390_SOFT_RESET_CMD
#define K_BMP390_INT_CTRL_DRDY_EN
#define K_BMP390_SPI_WRITE
#define K_BMP390_INT_CTRL_LEVEL
#define K_BMP390_CHIP_ID_REG
#define K_BMP390_TEMP_CALIB_REG_START
#define K_BMP390_REG_INT_CTRL
#define K_BMP390_SOFT_RESET_REG
#define K_BMP390_PRESS_RAW_REG
#define BMP390_IF_CONF_SPI
#define K_BMP390_REG_PWRCTRL
#define K_BMP390_INT_INTR_TYPE
#define K_BMP390_INT_PULL
SPP_Packet_t * SPP_SERVICES_DATABANK_getPacket(void)
Acquire a free packet from the pool.
SPP_RetVal_t SPP_SERVICES_DATABANK_returnPacket(SPP_Packet_t *p_packet)
Return a packet to the pool after processing.
SPP_RetVal_t SPP_SERVICES_DATABANK_packetData(SPP_Packet_t *p_packet, spp_uint16_t apid, spp_uint16_t seq, const void *p_data, spp_uint16_t dataLen)
Fill a packet with data and compute its CRC.
Static packet pool manager.
Finite State Machine (FSM) module for the SPP core.
SPP_RetVal_t SPP_HAL_GPIO_registerIsr(spp_uint32_t pin, void *p_isrCtx)
Register an ISR handler for a GPIO pin.
SPP_RetVal_t SPP_HAL_GPIO_configInterrupt(spp_uint32_t pin, spp_uint32_t intrType, spp_uint32_t pull)
Configure a GPIO pin as an interrupt input.
#define SPP_LOGI(tag, fmt,...)
#define SPP_LOGE(tag, fmt,...)
#define SPP_LOGW(tag, fmt,...)
Solaris Packet Protocol (SPP) packet structure definitions.
SPP_RetVal_t SPP_SERVICES_PUBSUB_publish(SPP_Packet_t *p_pkt)
Copies a packet into the internal buffer and returns it to the databank.
Publish-subscribe packet router.
SPP_RetVal_t
Unified return type for all SPP API functions.
@ K_SPP_ERROR_NULL_POINTER
void * SPP_HAL_SPI_getHandle(spp_uint8_t deviceIdx)
Obtain the SPI device handle for the given device index.
SPP_RetVal_t SPP_HAL_SPI_deviceInit(void *p_handle)
Initialise a specific SPI device.
SPP_RetVal_t SPP_HAL_SPI_transmit(void *p_handle, spp_uint8_t *p_data, spp_uint8_t length)
Perform a full-duplex SPI transaction.
SPP SPI HAL API — dispatches through the registered HAL port.
volatile spp_bool_t drdyFlag
Raw pressure calibration coefficients.
Scaled pressure calibration parameters.
BMP390_SpiConfig_t spiConfig
BMP390_GpioConfig_t gpioConfig
Raw temperature calibration coefficients (as read from sensor).
Scaled temperature calibration parameters.
volatile spp_bool_t * p_flag
Describes the contract of a producer module. This module needs to have:
void SPP_HAL_TIME_delayMs(spp_uint32_t ms)
Block for the requested number of milliseconds.
SPP HAL time API — dispatches through the registered HAL port.