Solaris Software
Loading...
Searching...
No Matches
bmp390.h
Go to the documentation of this file.
1/**
2 * @file bmp390.h
3 * @brief BMP390 barometric pressure sensor driver and service.
4 *
5 * Provides SPI-based communication with the Bosch BMP390 sensor for reading
6 * calibrated temperature, pressure and derived altitude. Supports data-ready
7 * interrupt via GPIO event groups.
8 *
9 * The driver follows a three-step workflow:
10 * 1. Initialise and configure the sensor (SPP_SERVICES_BMP390_init, SPP_SERVICES_BMP390_auxConfig,
11 * SPP_SERVICES_BMP390_prepareMeasure).
12 * 2. Wait for the data-ready interrupt (SPP_SERVICES_BMP390_waitDrdy).
13 * 3. Read compensated altitude/pressure/temperature (SPP_SERVICES_BMP390_getAltitude).
14 *
15 * To use the SPP service registry, declare a @ref BMP390_t with the hardware
16 * pin fields filled in, then call SPP_SERVICES_register() with @ref g_bmp390Module.
17 *
18 * Naming conventions used in this file:
19 * - Constants/macros: K_BMP390_*
20 * - Types: BMP390_*_t
21 * - Public functions: BMP390_*()
22 * - Pointer params: p_*
23 */
24
25#ifndef SPP_BMP390_H
26#define SPP_BMP390_H
27
28#include <stdint.h>
30#include "spp/core/types.h"
31#include "spp/hal/gpio/gpio.h"
33
34/* ----------------------------------------------------------------
35 * DEFINES
36 * ---------------------------------------------------------------- */
37
38/* Service */
39#define K_BMP_SERVICE_TASK_PRIO (5U) /**< FreeRTOS task priority for the BMP390 service. */
40#define K_BMP_SERVICE_TASK_DELAY_MS (200U) /**< Delay in ms between measurement cycles. */
41#define K_BMP_SERVICE_TASK_STACK_SIZE (4096U) /**< Stack size in bytes for the BMP390 service task. */
42#define K_BMP_SERVICE_PAYLOAD_LEN (12U) /**< Payload length in bytes (temp + press + alt). */
43
44/* SPI */
45#define K_BMP390_SPI_READ 0x80U /**< SPI read flag: OR with register address. */
46#define K_BMP390_SPI_WRITE 0x00U /**< SPI write flag: OR with register address. */
47#define K_BMP390_PIN_NUM_CS 18U /**< Chip-select GPIO pin (informational; set by HAL). */
48#define K_BMP390_SPI_BUS_IDX 0U /**< SPI bus index (informational; set by HAL). */
49
50/* Identity and reset */
51#define K_BMP390_CHIP_ID_REG 0x00 /**< Chip ID register address. */
52#define K_BMP390_CHIP_ID_VALUE 0x60 /**< Expected chip ID value. */
53#define K_BMP390_SOFT_RESET_REG 0x7E /**< Soft-reset register address. */
54#define BMP390_SOFT_RESET_CMD 0xB6 /**< Soft-reset command byte. */
55#define K_BMP390_IF_CONF_REG 0x1A /**< Interface configuration register address. */
56#define BMP390_IF_CONF_SPI 0x00 /**< SPI interface mode value. */
57
58/* Measurement configuration */
59#define K_BMP390_REG_PWRCTRL 0x1B /**< Power control register address. */
60#define BMP390_VALUE_PWRCTRL 0x33 /**< Power control value (temp+press on, normal mode). */
61#define K_BMP390_REG_OSR 0x1C /**< Oversampling register address. */
62#define BMP390_VALUE_OSR 0x00 /**< Oversampling value (no oversampling). */
63#define K_BMP390_REG_ODR 0x1D /**< Output data rate register address. */
64#define BMP390_VALUE_ODR 0x01 /**< Output data rate value. */
65#define K_BMP390_REG_IIR 0x1F /**< IIR filter register address. */
66#define BMP390_VALUE_IIR 0x02 /**< IIR filter coefficient value. */
67
68/* Status */
69#define K_BMP390_REG_STATUS 0x03 /**< Status register address. */
70#define K_BMP390_STATUS_DRDY_TEMP 0x40 /**< Status bit: temperature data ready. */
71#define BMP390_STATUS_DRDY_PRES 0x20 /**< Status bit: pressure data ready. */
72
73/* Temperature */
74#define K_BMP390_TEMP_CALIB_REG_START 0x31 /**< Start address of temperature calibration regs. */
75#define K_BMP390_TEMP_RAW_REG 0x07 /**< Start address of raw temperature data regs. */
76#define K_BMP390_DRDY_TIMEOUT_MS 5000U /**< Timeout in ms for the data-ready interrupt wait. */
77
78/* Pressure */
79#define K_BMP390_PRESS_CALIB_REG_START 0x36 /**< Start address of pressure calibration regs. */
80#define K_BMP390_PRESS_RAW_REG 0x04 /**< Start address of raw pressure data regs. */
81
82/* Interrupt */
83#define K_BMP390_REG_INT_CTRL 0x19 /**< Interrupt control register address. */
84#define K_BMP390_INT_CTRL_DRDY_EN 0x40 /**< Interrupt control: enable data-ready interrupt. */
85#define K_BMP390_INT_CTRL_LEVEL 0x02 /**< Interrupt control: active-high level. */
86#define K_BMP390_INT_PIN_NUM 3U /**< Interrupt GPIO pin */
87#define K_BMP390_INT_INTR_TYPE 1U /**< Interrupt trigger type (1=rising). */
88#define K_BMP390_INT_PULL 0U /**< Pull resistor: 0=none 1=up 2=down. */
89
90
91/* ----------------------------------------------------------------
92 * STRUCTS AND ENUMS
93 * ---------------------------------------------------------------- */
94
95/** @brief Raw temperature calibration coefficients (as read from sensor). */
96typedef struct
97{
98 uint16_t par_t1; /**< T1 (unsigned 16-bit). */
99 int16_t par_t2; /**< T2 (signed 16-bit). */
100 int8_t par_t3; /**< T3 (signed 8-bit). */
101 float t_lin; /**< Linearised temperature. */
103
104/** @brief Scaled temperature calibration parameters. */
105typedef struct
106{
107 float PAR_T1; /**< Scaled T1 = raw_t1 * 2^8. */
108 float PAR_T2; /**< Scaled T2 = raw_t2 / 2^30. */
109 float PAR_T3; /**< Scaled T3 = raw_t3 / 2^48. */
111
112/** @brief Raw pressure calibration coefficients. */
113typedef struct
114{
115 spp_uint16_t par_p1; /**< P1 raw coefficient. */
116 spp_uint16_t par_p2; /**< P2 raw coefficient. */
117 spp_int8_t par_p3; /**< P3 raw coefficient. */
118 spp_int8_t par_p4; /**< P4 raw coefficient. */
119 spp_uint16_t par_p5; /**< P5 raw coefficient. */
120 spp_uint16_t par_p6; /**< P6 raw coefficient. */
121 spp_int8_t par_p7; /**< P7 raw coefficient. */
122 spp_int8_t par_p8; /**< P8 raw coefficient. */
123 spp_int16_t par_p9; /**< P9 raw coefficient. */
124 spp_int8_t par_p10; /**< P10 raw coefficient. */
125 spp_int8_t par_p11; /**< P11 raw coefficient. */
127
128/** @brief Scaled pressure calibration parameters. */
129typedef struct
130{
131 float PAR_P1; /**< Scaled P1. */
132 float PAR_P2; /**< Scaled P2. */
133 float PAR_P3; /**< Scaled P3. */
134 float PAR_P4; /**< Scaled P4. */
135 float PAR_P5; /**< Scaled P5. */
136 float PAR_P6; /**< Scaled P6. */
137 float PAR_P7; /**< Scaled P7. */
138 float PAR_P8; /**< Scaled P8. */
139 float PAR_P9; /**< Scaled P9. */
140 float PAR_P10; /**< Scaled P10. */
141 float PAR_P11; /**< Scaled P11. */
143
144/* ----------------------------------------------------------------
145* STRUCTS AND ENUMS
146* ---------------------------------------------------------------- */
147
148typedef struct
149{
150 spp_uint8_t spiDevIdx; /**< SPI device handle index. */
151 void *p_spiHandler; /**< SPI device handle. */
153typedef struct
154{
155 spp_uint32_t intPin; /**< GPIO pin for DRDY interrupt. */
156 spp_uint32_t intIntrType; /**< Interrupt trigger type (1=rising). */
157 spp_uint32_t intPull; /**< Pull resistor: 0=none 1=up 2=down. */
158 volatile spp_bool_t drdyFlag; /**< Interrupt flag. */
159 SPP_GpioIsrCtx_t isrCtx; /**< ISR context (p_flag points at drdyFlag). */
161/**
162 * @brief BMP390 sensor instance.
163 *
164 * Declare one static instance with the hardware pin fields filled in, then
165 * pass its address to SPP_SERVICES_register(). All other fields are
166 * zero-initialised by the compiler and filled in by the init callback.
167 */
168typedef struct
169{
170 BMP390_GpioConfig_t gpioConfig; /**< GPIO configuration. */
171 BMP390_SpiConfig_t spiConfig; /**< SPI configuration. */
172 spp_uint16_t seq; /**< Packet sequence counter. */
173} BMP390_t;
174
175
176/* ----------------------------------------------------------------
177* PUBLIC FUNCTIONS
178* ---------------------------------------------------------------- */
180
181/* Performance Test*/
183
185 spp_uint32_t *p_tempSpiUs, spp_uint32_t *p_pressSpiUs);
186
187#endif /* SPP_BMP390_H */
const SPP_SERVICE_ProducerContract_t * SPP_SERVICES_BMP390_getProducerContract(void)
Definition bmp390.c:87
SPP_RetVal_t SPP_SERVICES_BMP390_getPerformanceSample(spp_uint16_t index, spp_uint32_t *p_bmpUs, spp_uint32_t *p_tempSpiUs, spp_uint32_t *p_pressSpiUs)
spp_uint16_t SPP_SERVICES_BMP390_getPerformanceSampleCount(void)
SPP GPIO HAL API — dispatches through the registered HAL port.
Standard return-value type used across all SPP modules.
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition returnTypes.h:24
SPP module descriptor and registry API.
SPP_GpioIsrCtx_t isrCtx
Definition bmp390.h:159
spp_uint32_t intIntrType
Definition bmp390.h:156
spp_uint32_t intPull
Definition bmp390.h:157
volatile spp_bool_t drdyFlag
Definition bmp390.h:158
spp_uint32_t intPin
Definition bmp390.h:155
spp_uint8_t spiDevIdx
Definition bmp390.h:150
void * p_spiHandler
Definition bmp390.h:151
Raw pressure calibration coefficients.
Definition bmp390.h:114
spp_int8_t par_p10
Definition bmp390.h:124
spp_uint16_t par_p5
Definition bmp390.h:119
spp_int8_t par_p7
Definition bmp390.h:121
spp_int8_t par_p4
Definition bmp390.h:118
spp_int8_t par_p8
Definition bmp390.h:122
spp_int16_t par_p9
Definition bmp390.h:123
spp_uint16_t par_p2
Definition bmp390.h:116
spp_uint16_t par_p6
Definition bmp390.h:120
spp_int8_t par_p3
Definition bmp390.h:117
spp_int8_t par_p11
Definition bmp390.h:125
spp_uint16_t par_p1
Definition bmp390.h:115
Scaled pressure calibration parameters.
Definition bmp390.h:130
BMP390 sensor instance.
Definition bmp390.h:169
BMP390_SpiConfig_t spiConfig
Definition bmp390.h:171
BMP390_GpioConfig_t gpioConfig
Definition bmp390.h:170
spp_uint16_t seq
Definition bmp390.h:172
Raw temperature calibration coefficients (as read from sensor).
Definition bmp390.h:97
uint16_t par_t1
Definition bmp390.h:98
Scaled temperature calibration parameters.
Definition bmp390.h:106
Context passed to the GPIO ISR handler.
Definition gpio.h:27
Describes the contract of a producer module. This module needs to have:
Definition service.h:28
Portable integer types and SPI/storage configuration types for SPP.
uint16_t spp_uint16_t
Definition types.h:29
uint32_t spp_uint32_t
Definition types.h:31
int8_t spp_int8_t
Definition types.h:28
uint8_t spp_uint8_t
Definition types.h:27
bool spp_bool_t
Definition types.h:36
int16_t spp_int16_t
Definition types.h:30