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