ESPHome 2026.3.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
13namespace esphome {
14namespace bmp3xx_base {
15
16static const uint8_t BMP388_ID = 0x50; // The BMP388 device ID
17static const uint8_t BMP390_ID = 0x60; // The BMP390 device ID
18static const uint8_t RESET_CODE = 0xB6; // The BMP388 reset code
19
21enum {
22 BMP388_CHIP_ID = 0x00, // Chip ID register sub-address
23 BMP388_ERR_REG = 0x02, // Error register sub-address
24 BMP388_STATUS = 0x03, // Status register sub-address
25 BMP388_DATA_0 = 0x04, // Pressure eXtended Least Significant Byte (XLSB) register sub-address
26 BMP388_DATA_1 = 0x05, // Pressure Least Significant Byte (LSB) register sub-address
27 BMP388_DATA_2 = 0x06, // Pressure Most Significant Byte (MSB) register sub-address
28 BMP388_DATA_3 = 0x07, // Temperature eXtended Least Significant Byte (XLSB) register sub-address
29 BMP388_DATA_4 = 0x08, // Temperature Least Significant Byte (LSB) register sub-address
30 BMP388_DATA_5 = 0x09, // Temperature Most Significant Byte (MSB) register sub-address
31 BMP388_SENSORTIME_0 = 0x0C, // Sensor time register 0 sub-address
32 BMP388_SENSORTIME_1 = 0x0D, // Sensor time register 1 sub-address
33 BMP388_SENSORTIME_2 = 0x0E, // Sensor time register 2 sub-address
34 BMP388_EVENT = 0x10, // Event register sub-address
35 BMP388_INT_STATUS = 0x11, // Interrupt Status register sub-address
36 BMP388_INT_CTRL = 0x19, // Interrupt Control register sub-address
37 BMP388_IF_CONFIG = 0x1A, // Interface Configuration register sub-address
38 BMP388_PWR_CTRL = 0x1B, // Power Control register sub-address
39 BMP388_OSR = 0x1C, // Oversampling register sub-address
40 BMP388_ODR = 0x1D, // Output Data Rate register sub-address
41 BMP388_CONFIG = 0x1F, // Configuration register sub-address
42 BMP388_TRIM_PARAMS = 0x31, // Trim parameter registers' base sub-address
43 BMP388_CMD = 0x7E // Command register sub-address
44};
45
47enum OperationMode { SLEEP_MODE = 0x00, FORCED_MODE = 0x01, NORMAL_MODE = 0x03 };
48
58
70
73 public:
74 void setup() override;
75 void dump_config() override;
76 void update() override;
77
78 void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
79 void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; }
80
82 void set_temperature_oversampling_config(Oversampling temperature_oversampling) {
83 this->temperature_oversampling_ = temperature_oversampling;
84 }
86 void set_pressure_oversampling_config(Oversampling pressure_oversampling) {
87 this->pressure_oversampling_ = pressure_oversampling;
88 }
91
93 uint8_t reset();
99 bool stop_conversion();
101 bool set_pressure_oversampling(Oversampling pressure_oversampling);
103 bool set_temperature_oversampling(Oversampling temperature_oversampling);
107 bool get_temperature(float &temperature);
109 bool get_pressure(float &pressure);
111 bool get_measurements(float &temperature, float &pressure);
117 bool set_oversampling_register(Oversampling pressure_oversampling, Oversampling temperature_oversampling);
119 bool data_ready();
120
121 protected:
135
136 struct { // The BMP388 compensation trim parameters (coefficients)
137 uint16_t param_T1;
138 uint16_t param_T2;
139 int8_t param_T3;
140 int16_t param_P1;
141 int16_t param_P2;
142 int8_t param_P3;
143 int8_t param_P4;
144 uint16_t param_P5;
145 uint16_t param_P6;
146 int8_t param_P7;
147 int8_t param_P8;
148 int16_t param_P9;
149 int8_t param_P10;
150 int8_t param_P11;
151 } __attribute__((packed)) compensation_params_;
152
153 struct FloatParams { // The BMP388 float point compensation trim parameters
154 float param_T1;
155 float param_T2;
156 float param_T3;
157 float param_P1;
158 float param_P2;
159 float param_P3;
160 float param_P4;
161 float param_P5;
162 float param_P6;
163 float param_P7;
164 float param_P8;
165 float param_P9;
169
170 union { // Copy of the BMP388's chip id register
171 struct {
172 uint8_t chip_id_nvm : 4;
173 uint8_t chip_id_fixed : 4;
175 uint8_t reg;
176 } chip_id_ = {.reg = 0};
177
178 union { // Copy of the BMP388's event register
179 struct {
180 uint8_t por_detected : 1;
182 uint8_t reg;
183 } event_ = {.reg = 0};
184
185 union { // Copy of the BMP388's interrupt status register
186 struct {
187 uint8_t fwm_int : 1;
188 uint8_t ffull_int : 1;
189 uint8_t : 1;
190 uint8_t drdy : 1;
192 uint8_t reg;
193 } int_status_ = {.reg = 0};
194
195 union { // Copy of the BMP388's power control register
196 struct {
197 uint8_t press_en : 1;
198 uint8_t temp_en : 1;
199 uint8_t : 2;
200 uint8_t mode : 2;
202 uint8_t reg;
203 } pwr_ctrl_ = {.reg = 0};
204
205 union { // Copy of the BMP388's oversampling register
206 struct {
207 uint8_t osr_p : 3;
208 uint8_t osr_t : 3;
210 uint8_t reg;
211 } osr_ = {.reg = 0};
212
213 union { // Copy of the BMP388's output data rate register
214 struct {
215 uint8_t odr_sel : 5;
217 uint8_t reg;
218 } odr_ = {.reg = 0};
219
220 union { // Copy of the BMP388's configuration register
221 struct {
222 uint8_t : 1;
223 uint8_t iir_filter : 3;
225 uint8_t reg;
226 } config_ = {.reg = 0};
227
228 // Bosch temperature compensation function
229 float bmp388_compensate_temperature_(float uncomp_temp);
230 // Bosch pressure compensation function
231 float bmp388_compensate_pressure_(float uncomp_press, float t_lin);
232
233 // interface specific functions
234 virtual bool read_byte(uint8_t a_register, uint8_t *data) = 0;
235 virtual bool write_byte(uint8_t a_register, uint8_t data) = 0;
236 virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
237 virtual bool write_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
238};
239
240} // namespace bmp3xx_base
241} // namespace esphome
This class simplifies creating components that periodically check a state.
Definition component.h:527
This class implements support for the BMP3XX Temperature+Pressure sensor.
Definition bmp3xx_base.h:72
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition bmp3xx_base.h:78
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:86
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:82
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:79
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:90
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__
Oversampling
Oversampling bit fields in the control and measurement register.
Definition bmp3xx_base.h:50
OperationMode
Device mode bitfield in the control and measurement register.
Definition bmp3xx_base.h:47
IIRFilter
Infinite Impulse Response (IIR) filter bit field in the configuration register.
Definition bmp3xx_base.h:60
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:817
uint16_t temperature
Definition sun_gtil2.cpp:12
uint8_t pressure
Definition tt21100.cpp:7