ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
bmp3xx_base.h
Go to the documentation of this file.
1/*
2 based on BMP388_DEV by Martin Lindupp
3 under MIT License (MIT)
4 Copyright (C) Martin Lindupp 2020
5 http://github.com/MartinL1/BMP388_DEV
6*/
8#pragma once
14
15static const uint8_t BMP388_ID = 0x50; // The BMP388 device ID
16static const uint8_t BMP390_ID = 0x60; // The BMP390 device ID
17static const uint8_t RESET_CODE = 0xB6; // The BMP388 reset code
18
20enum {
21 BMP388_CHIP_ID = 0x00, // Chip ID register sub-address
22 BMP388_ERR_REG = 0x02, // Error register sub-address
23 BMP388_STATUS = 0x03, // Status register sub-address
24 BMP388_DATA_0 = 0x04, // Pressure eXtended Least Significant Byte (XLSB) register sub-address
25 BMP388_DATA_1 = 0x05, // Pressure Least Significant Byte (LSB) register sub-address
26 BMP388_DATA_2 = 0x06, // Pressure Most Significant Byte (MSB) register sub-address
27 BMP388_DATA_3 = 0x07, // Temperature eXtended Least Significant Byte (XLSB) register sub-address
28 BMP388_DATA_4 = 0x08, // Temperature Least Significant Byte (LSB) register sub-address
29 BMP388_DATA_5 = 0x09, // Temperature Most Significant Byte (MSB) register sub-address
30 BMP388_SENSORTIME_0 = 0x0C, // Sensor time register 0 sub-address
31 BMP388_SENSORTIME_1 = 0x0D, // Sensor time register 1 sub-address
32 BMP388_SENSORTIME_2 = 0x0E, // Sensor time register 2 sub-address
33 BMP388_EVENT = 0x10, // Event register sub-address
34 BMP388_INT_STATUS = 0x11, // Interrupt Status register sub-address
35 BMP388_INT_CTRL = 0x19, // Interrupt Control register sub-address
36 BMP388_IF_CONFIG = 0x1A, // Interface Configuration register sub-address
37 BMP388_PWR_CTRL = 0x1B, // Power Control register sub-address
38 BMP388_OSR = 0x1C, // Oversampling register sub-address
39 BMP388_ODR = 0x1D, // Output Data Rate register sub-address
40 BMP388_CONFIG = 0x1F, // Configuration register sub-address
41 BMP388_TRIM_PARAMS = 0x31, // Trim parameter registers' base sub-address
42 BMP388_CMD = 0x7E // Command register sub-address
43};
44
46enum OperationMode { SLEEP_MODE = 0x00, FORCED_MODE = 0x01, NORMAL_MODE = 0x03 };
47
57
69
72 public:
73 void setup() override;
74 void dump_config() override;
75 void update() override;
76
77 void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
78 void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; }
79
81 void set_temperature_oversampling_config(Oversampling temperature_oversampling) {
82 this->temperature_oversampling_ = temperature_oversampling;
83 }
85 void set_pressure_oversampling_config(Oversampling pressure_oversampling) {
86 this->pressure_oversampling_ = pressure_oversampling;
87 }
90
92 uint8_t reset();
98 bool stop_conversion();
100 bool set_pressure_oversampling(Oversampling pressure_oversampling);
102 bool set_temperature_oversampling(Oversampling temperature_oversampling);
106 bool get_temperature(float &temperature);
108 bool get_pressure(float &pressure);
110 bool get_measurements(float &temperature, float &pressure);
116 bool set_oversampling_register(Oversampling pressure_oversampling, Oversampling temperature_oversampling);
118 bool data_ready();
119
120 protected:
134
135 struct { // The BMP388 compensation trim parameters (coefficients)
136 uint16_t param_T1;
137 uint16_t param_T2;
138 int8_t param_T3;
139 int16_t param_P1;
140 int16_t param_P2;
141 int8_t param_P3;
142 int8_t param_P4;
143 uint16_t param_P5;
144 uint16_t param_P6;
145 int8_t param_P7;
146 int8_t param_P8;
147 int16_t param_P9;
148 int8_t param_P10;
149 int8_t param_P11;
150 } __attribute__((packed)) compensation_params_;
151
152 struct FloatParams { // The BMP388 float point compensation trim parameters
153 float param_T1;
154 float param_T2;
155 float param_T3;
156 float param_P1;
157 float param_P2;
158 float param_P3;
159 float param_P4;
160 float param_P5;
161 float param_P6;
162 float param_P7;
163 float param_P8;
164 float param_P9;
168
169 union { // Copy of the BMP388's chip id register
170 struct {
171 uint8_t chip_id_nvm : 4;
172 uint8_t chip_id_fixed : 4;
174 uint8_t reg;
175 } chip_id_ = {.reg = 0};
176
177 union { // Copy of the BMP388's event register
178 struct {
179 uint8_t por_detected : 1;
181 uint8_t reg;
182 } event_ = {.reg = 0};
183
184 union { // Copy of the BMP388's interrupt status register
185 struct {
186 uint8_t fwm_int : 1;
187 uint8_t ffull_int : 1;
188 uint8_t : 1;
189 uint8_t drdy : 1;
191 uint8_t reg;
192 } int_status_ = {.reg = 0};
193
194 union { // Copy of the BMP388's power control register
195 struct {
196 uint8_t press_en : 1;
197 uint8_t temp_en : 1;
198 uint8_t : 2;
199 uint8_t mode : 2;
201 uint8_t reg;
202 } pwr_ctrl_ = {.reg = 0};
203
204 union { // Copy of the BMP388's oversampling register
205 struct {
206 uint8_t osr_p : 3;
207 uint8_t osr_t : 3;
209 uint8_t reg;
210 } osr_ = {.reg = 0};
211
212 union { // Copy of the BMP388's output data rate register
213 struct {
214 uint8_t odr_sel : 5;
216 uint8_t reg;
217 } odr_ = {.reg = 0};
218
219 union { // Copy of the BMP388's configuration register
220 struct {
221 uint8_t : 1;
222 uint8_t iir_filter : 3;
224 uint8_t reg;
225 } config_ = {.reg = 0};
226
227 // Bosch temperature compensation function
228 float bmp388_compensate_temperature_(float uncomp_temp);
229 // Bosch pressure compensation function
230 float bmp388_compensate_pressure_(float uncomp_press, float t_lin);
231
232 // interface specific functions
233 virtual bool read_byte(uint8_t a_register, uint8_t *data) = 0;
234 virtual bool write_byte(uint8_t a_register, uint8_t data) = 0;
235 virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
236 virtual bool write_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
237};
238
239} // namespace esphome::bmp3xx_base
This class simplifies creating components that periodically check a state.
Definition component.h:585
This class implements support for the BMP3XX Temperature+Pressure sensor.
Definition bmp3xx_base.h:71
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition bmp3xx_base.h:77
struct esphome::bmp3xx_base::BMP3XXComponent::@23::@30 bit
union esphome::bmp3xx_base::BMP3XXComponent::@24 event_
void set_pressure_oversampling_config(Oversampling pressure_oversampling)
Set the oversampling value for the pressure sensor. Default is 16x.
Definition bmp3xx_base.h:85
union esphome::bmp3xx_base::BMP3XXComponent::@27 osr_
struct esphome::bmp3xx_base::BMP3XXComponent::FloatParams compensation_float_params_
bool get_pressure(float &pressure)
Get a pressure measurement.
union esphome::bmp3xx_base::BMP3XXComponent::@23 chip_id_
void set_temperature_oversampling_config(Oversampling temperature_oversampling)
Set the oversampling value for the temperature sensor. Default is 16x.
Definition bmp3xx_base.h:81
bool get_measurements(float &temperature, float &pressure)
Get a temperature and pressure measurement.
union esphome::bmp3xx_base::BMP3XXComponent::@26 pwr_ctrl_
enum esphome::bmp3xx_base::BMP3XXComponent::ErrorCode NONE
bool start_forced_conversion()
Start a one shot measurement in FORCED_MODE.
void set_pressure_sensor(sensor::Sensor *pressure_sensor)
Definition bmp3xx_base.h:78
bool set_iir_filter(IIRFilter iir_filter)
Set the IIR filter setting: OFF, 2, 3, 8, 16, 32.
union esphome::bmp3xx_base::BMP3XXComponent::@29 config_
bool set_pressure_oversampling(Oversampling pressure_oversampling)
Set the pressure oversampling: OFF, X1, X2, X4, X8, X16, X32.
union esphome::bmp3xx_base::BMP3XXComponent::@25 int_status_
union esphome::bmp3xx_base::BMP3XXComponent::@28 odr_
bool get_temperature(float &temperature)
Get a temperature measurement.
bool stop_conversion()
Stop the conversion and return to SLEEP_MODE.
float bmp388_compensate_temperature_(float uncomp_temp)
void set_iir_filter_config(IIRFilter iir_filter)
Set the IIR Filter used to increase accuracy, defaults to no IIR Filter.
Definition bmp3xx_base.h:89
virtual bool write_byte(uint8_t a_register, uint8_t data)=0
bool get_measurement()
Get a temperature and pressure measurement.
virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len)=0
uint8_t reset()
Soft reset the sensor.
bool start_normal_conversion()
Start continuous measurement in NORMAL_MODE.
bool set_oversampling_register(Oversampling pressure_oversampling, Oversampling temperature_oversampling)
Set the BMP388 oversampling register.
bool data_ready()
Checks if a measurement is ready.
virtual bool read_byte(uint8_t a_register, uint8_t *data)=0
bool set_mode(OperationMode mode)
Set the barometer mode.
virtual bool write_bytes(uint8_t a_register, uint8_t *data, size_t len)=0
float bmp388_compensate_pressure_(float uncomp_press, float t_lin)
bool set_temperature_oversampling(Oversampling temperature_oversampling)
Set the temperature oversampling: OFF, X1, X2, X4, X8, X16, X32.
Base-class for all sensors.
Definition sensor.h:47
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32
Oversampling
Oversampling bit fields in the control and measurement register.
Definition bmp3xx_base.h:49
OperationMode
Device mode bitfield in the control and measurement register.
Definition bmp3xx_base.h:46
IIRFilter
Infinite Impulse Response (IIR) filter bit field in the configuration register.
Definition bmp3xx_base.h:59
const void size_t len
Definition hal.h:64
uint16_t temperature
Definition sun_gtil2.cpp:12
uint8_t pressure
Definition tt21100.cpp:7