Solaris Software
Toggle main menu visibility
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>
13
#include "
spp/core/returnTypes.h
"
14
#include "
spp/core/types.h
"
15
#include "
spp/hal/gpio/gpio.h
"
16
#include "
spp/services/service.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). */
77
typedef
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. */
83
}
BMP390_temp_calib_t
;
84
85
/** @brief Scaled temperature calibration parameters. */
86
typedef
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. */
91
}
BMP390_temp_params_t
;
92
93
/** @brief Raw pressure calibration coefficients. */
94
typedef
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. */
107
}
BMP390_press_calib_t
;
108
109
/** @brief Scaled pressure calibration parameters. */
110
typedef
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. */
123
}
BMP390_press_params_t
;
124
125
/* ----------------------------------------------------------------
126
* STRUCTS AND ENUMS
127
* ---------------------------------------------------------------- */
128
129
typedef
struct
130
{
131
spp_uint8_t
spiDevIdx
;
/**< SPI device handle index. */
132
void
*
p_spiHandler
;
/**< SPI device handle. */
133
}
BMP390_SpiConfig_t
;
134
typedef
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). */
141
}
BMP390_GpioConfig_t
;
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
*/
149
typedef
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
*/
165
const
SPP_SERVICE_ProducerContract_t
*
SPP_SERVICES_BMP390_getProducerContract
(
void
);
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 */
SPP_SERVICES_BMP390_getProducerContract
const SPP_SERVICE_ProducerContract_t * SPP_SERVICES_BMP390_getProducerContract(void)
Returns the BMP390 producer contract for PUBSUB registration.
Definition
bmp390.c:101
gpio.h
SPP GPIO HAL API — dispatches through the registered HAL port.
returnTypes.h
Standard return-value type used across all SPP modules.
service.h
SPP module descriptor and registry API.
BMP390_GpioConfig_t
Definition
bmp390.h:135
BMP390_GpioConfig_t::isrCtx
SPP_GpioIsrCtx_t isrCtx
Definition
bmp390.h:140
BMP390_GpioConfig_t::intIntrType
spp_uint32_t intIntrType
Definition
bmp390.h:137
BMP390_GpioConfig_t::intPull
spp_uint32_t intPull
Definition
bmp390.h:138
BMP390_GpioConfig_t::drdyFlag
volatile spp_bool_t drdyFlag
Definition
bmp390.h:139
BMP390_GpioConfig_t::intPin
spp_uint32_t intPin
Definition
bmp390.h:136
BMP390_SpiConfig_t
Definition
bmp390.h:130
BMP390_SpiConfig_t::spiDevIdx
spp_uint8_t spiDevIdx
Definition
bmp390.h:131
BMP390_SpiConfig_t::p_spiHandler
void * p_spiHandler
Definition
bmp390.h:132
BMP390_press_calib_t
Raw pressure calibration coefficients.
Definition
bmp390.h:95
BMP390_press_calib_t::par_p10
spp_int8_t par_p10
Definition
bmp390.h:105
BMP390_press_calib_t::par_p5
spp_uint16_t par_p5
Definition
bmp390.h:100
BMP390_press_calib_t::par_p7
spp_int8_t par_p7
Definition
bmp390.h:102
BMP390_press_calib_t::par_p4
spp_int8_t par_p4
Definition
bmp390.h:99
BMP390_press_calib_t::par_p8
spp_int8_t par_p8
Definition
bmp390.h:103
BMP390_press_calib_t::par_p9
spp_int16_t par_p9
Definition
bmp390.h:104
BMP390_press_calib_t::par_p2
spp_uint16_t par_p2
Definition
bmp390.h:97
BMP390_press_calib_t::par_p6
spp_uint16_t par_p6
Definition
bmp390.h:101
BMP390_press_calib_t::par_p3
spp_int8_t par_p3
Definition
bmp390.h:98
BMP390_press_calib_t::par_p11
spp_int8_t par_p11
Definition
bmp390.h:106
BMP390_press_calib_t::par_p1
spp_uint16_t par_p1
Definition
bmp390.h:96
BMP390_press_params_t
Scaled pressure calibration parameters.
Definition
bmp390.h:111
BMP390_press_params_t::PAR_P4
float PAR_P4
Definition
bmp390.h:115
BMP390_press_params_t::PAR_P8
float PAR_P8
Definition
bmp390.h:119
BMP390_press_params_t::PAR_P7
float PAR_P7
Definition
bmp390.h:118
BMP390_press_params_t::PAR_P10
float PAR_P10
Definition
bmp390.h:121
BMP390_press_params_t::PAR_P9
float PAR_P9
Definition
bmp390.h:120
BMP390_press_params_t::PAR_P11
float PAR_P11
Definition
bmp390.h:122
BMP390_press_params_t::PAR_P2
float PAR_P2
Definition
bmp390.h:113
BMP390_press_params_t::PAR_P6
float PAR_P6
Definition
bmp390.h:117
BMP390_press_params_t::PAR_P3
float PAR_P3
Definition
bmp390.h:114
BMP390_press_params_t::PAR_P5
float PAR_P5
Definition
bmp390.h:116
BMP390_press_params_t::PAR_P1
float PAR_P1
Definition
bmp390.h:112
BMP390_t
BMP390 sensor instance.
Definition
bmp390.h:150
BMP390_t::spiConfig
BMP390_SpiConfig_t spiConfig
Definition
bmp390.h:152
BMP390_t::gpioConfig
BMP390_GpioConfig_t gpioConfig
Definition
bmp390.h:151
BMP390_t::seq
spp_uint16_t seq
Definition
bmp390.h:153
BMP390_temp_calib_t
Raw temperature calibration coefficients (as read from sensor).
Definition
bmp390.h:78
BMP390_temp_calib_t::t_lin
float t_lin
Definition
bmp390.h:82
BMP390_temp_calib_t::par_t2
int16_t par_t2
Definition
bmp390.h:80
BMP390_temp_calib_t::par_t1
uint16_t par_t1
Definition
bmp390.h:79
BMP390_temp_calib_t::par_t3
int8_t par_t3
Definition
bmp390.h:81
BMP390_temp_params_t
Scaled temperature calibration parameters.
Definition
bmp390.h:87
BMP390_temp_params_t::PAR_T1
float PAR_T1
Definition
bmp390.h:88
BMP390_temp_params_t::PAR_T2
float PAR_T2
Definition
bmp390.h:89
BMP390_temp_params_t::PAR_T3
float PAR_T3
Definition
bmp390.h:90
SPP_GpioIsrCtx_t
Context passed to the GPIO ISR handler.
Definition
gpio.h:27
SPP_SERVICE_ProducerContract_t
Defines the callbacks and metadata of an SPP producer.
Definition
service.h:25
types.h
Portable integer types and SPI/storage configuration types for SPP.
spp_uint16_t
uint16_t spp_uint16_t
Definition
types.h:29
spp_uint32_t
uint32_t spp_uint32_t
Definition
types.h:31
spp_int8_t
int8_t spp_int8_t
Definition
types.h:28
spp_uint8_t
uint8_t spp_uint8_t
Definition
types.h:27
spp_bool_t
bool spp_bool_t
Definition
types.h:36
spp_int16_t
int16_t spp_int16_t
Definition
types.h:30
solaris-v2
spp
services
bmp390
bmp390.h
Generated by
1.18.0