31#define K_BMP390_TASK_TIMEOUT_MS 5000U
32#define K_BMP390_TAG "BMP390"
55 float t_lin,
spp_uint32_t *raw_press,
float *comp_press);
57 float *temperature_c);
61#define K_BMP390_PERFORMANCE_SAMPLES (10000U)
87#define K_BMP390_CALIBRATION_SAMPLES 500U
205 float altitude = 0.0f;
206 float pressure = 0.0f;
207 float temperature = 0.0f;
252 if (p_packet == NULL)
270#ifdef SPP_DEBUG_PRINT
271 SPP_LOGI(
K_BMP390_TAG,
"[BMP] alt=%.1fm P=%.1fhPa T=%.2fC\n", altitude, pressure / 100.0f, temperature);
275 spp_float32_t payload[3] = {altitude, pressure, temperature};
348 printf(
"BMP390 ID=0x%02X\n", buf[8]);
435 tcalib->
par_t1 = (uint16_t)((raw[1] << 8) | raw[0]);
436 tcalib->
par_t2 = (int16_t)((raw[3] << 8) | raw[2]);
437 tcalib->
par_t3 = (int8_t)raw[4];
506 float partial1 = (float)raw_temp - params->
PAR_T1;
507 float partial2 = partial1 * params->
PAR_T2;
508 float t_lin = partial2 + (partial1 * partial1) * params->
PAR_T3;
603 for (
int i = 0; i < 16; i++)
605 raw[i] = buf[3 * i + 2];
706 s_pd1 = raw_press * raw_press;
726 float t_lin,
spp_uint32_t *raw_press,
float *comp_press)
753 float *temperature_c)
755 if ((p_spiHandler == NULL) || (altitude_m == NULL) || (pressure_pa == NULL) || (temperature_c == NULL))
767 float compPress = 0.0f;
769 if (s_inited ==
false)
798 *temperature_c = t_lin;
799 *pressure_pa = compPress;
809 *altitude_m = (referenceTemperatureK / 0.0065f) * (1.0f - powf(compPress /
s_referencePressure, 1.0f / 5.255f));
spp_float32_t s_referenceTemperature
spp_float32_t s_temperatureSum
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.
spp_uint16_t s_calibrationSamples
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
spp_float32_t s_referencePressure
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
#define K_BMP390_CALIBRATION_SAMPLES
static SPP_RetVal_t SPP_SERVICES_BMP390_readRawTempCoeffs(void *p_spiHandler, BMP390_temp_calib_t *tcalib)
Reads raw temperature calibration coefficients from the sensor's NVM registers.
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)
Initializes the BMP390 sensor and its hardware interfaces.
const SPP_SERVICE_ProducerContract_t * SPP_SERVICES_BMP390_getProducerContract(void)
Returns the BMP390 producer contract for PUBSUB registration.
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
spp_bool_t s_isCalibrated
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)
Acquires BMP390 measurements and publishes them through PUBSUB.
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.
spp_float32_t s_pressureSum
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 temperature and pressure, and computes relative altitude.
BMP390 barometric sensor driver and SPP producer.
#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)
Performs register-based SPI transactions.
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
Defines the callbacks and metadata of an SPP producer.
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.