ESPHome 2025.5.0
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 float get_setup_priority() const override;
77 void update() override;
78
79 void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
80 void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; }
81
83 void set_temperature_oversampling_config(Oversampling temperature_oversampling) {
84 this->temperature_oversampling_ = temperature_oversampling;
85 }
87 void set_pressure_oversampling_config(Oversampling pressure_oversampling) {
88 this->pressure_oversampling_ = pressure_oversampling;
89 }
92
94 uint8_t reset();
100 bool stop_conversion();
102 bool set_pressure_oversampling(Oversampling pressure_oversampling);
104 bool set_temperature_oversampling(Oversampling temperature_oversampling);
108 bool get_temperature(float &temperature);
110 bool get_pressure(float &pressure);
112 bool get_measurements(float &temperature, float &pressure);
118 bool set_oversampling_register(Oversampling pressure_oversampling, Oversampling temperature_oversampling);
120 bool data_ready();
121
122 protected:
136
137 struct { // The BMP388 compensation trim parameters (coefficients)
138 uint16_t param_T1;
139 uint16_t param_T2;
140 int8_t param_T3;
141 int16_t param_P1;
142 int16_t param_P2;
143 int8_t param_P3;
144 int8_t param_P4;
145 uint16_t param_P5;
146 uint16_t param_P6;
147 int8_t param_P7;
148 int8_t param_P8;
149 int16_t param_P9;
150 int8_t param_P10;
151 int8_t param_P11;
152 } __attribute__((packed)) compensation_params_;
153
154 struct FloatParams { // The BMP388 float point compensation trim parameters
155 float param_T1;
156 float param_T2;
157 float param_T3;
158 float param_P1;
159 float param_P2;
160 float param_P3;
161 float param_P4;
162 float param_P5;
163 float param_P6;
164 float param_P7;
165 float param_P8;
166 float param_P9;
170
171 union { // Copy of the BMP388's chip id register
172 struct {
173 uint8_t chip_id_nvm : 4;
174 uint8_t chip_id_fixed : 4;
176 uint8_t reg;
177 } chip_id_ = {.reg = 0};
178
179 union { // Copy of the BMP388's event register
180 struct {
181 uint8_t por_detected : 1;
183 uint8_t reg;
184 } event_ = {.reg = 0};
185
186 union { // Copy of the BMP388's interrupt status register
187 struct {
188 uint8_t fwm_int : 1;
189 uint8_t ffull_int : 1;
190 uint8_t : 1;
191 uint8_t drdy : 1;
193 uint8_t reg;
194 } int_status_ = {.reg = 0};
195
196 union { // Copy of the BMP388's power control register
197 struct {
198 uint8_t press_en : 1;
199 uint8_t temp_en : 1;
200 uint8_t : 2;
201 uint8_t mode : 2;
203 uint8_t reg;
204 } pwr_ctrl_ = {.reg = 0};
205
206 union { // Copy of the BMP388's oversampling register
207 struct {
208 uint8_t osr_p : 3;
209 uint8_t osr_t : 3;
211 uint8_t reg;
212 } osr_ = {.reg = 0};
213
214 union { // Copy of the BMP388's output data rate register
215 struct {
216 uint8_t odr_sel : 5;
218 uint8_t reg;
219 } odr_ = {.reg = 0};
220
221 union { // Copy of the BMP388's configuration register
222 struct {
223 uint8_t : 1;
224 uint8_t iir_filter : 3;
226 uint8_t reg;
227 } config_ = {.reg = 0};
228
229 // Bosch temperature compensation function
230 float bmp388_compensate_temperature_(float uncomp_temp);
231 // Bosch pressure compensation function
232 float bmp388_compensate_pressure_(float uncomp_press, float t_lin);
233
234 // interface specific functions
235 virtual bool read_byte(uint8_t a_register, uint8_t *data) = 0;
236 virtual bool write_byte(uint8_t a_register, uint8_t data) = 0;
237 virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
238 virtual bool write_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
239};
240
241} // namespace bmp3xx_base
242} // namespace esphome
This class simplifies creating components that periodically check a state.
Definition component.h:301
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:79
void set_pressure_oversampling_config(Oversampling pressure_oversampling)
Set the oversampling value for the pressure sensor. Default is 16x.
Definition bmp3xx_base.h:87
union esphome::bmp3xx_base::BMP3XXComponent::@26 event_
struct esphome::bmp3xx_base::BMP3XXComponent::FloatParams compensation_float_params_
bool get_pressure(float &pressure)
Get a pressure measurement.
void set_temperature_oversampling_config(Oversampling temperature_oversampling)
Set the oversampling value for the temperature sensor. Default is 16x.
Definition bmp3xx_base.h:83
bool get_measurements(float &temperature, float &pressure)
Get a temperature and pressure measurement.
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:80
union esphome::bmp3xx_base::BMP3XXComponent::@25 chip_id_
union esphome::bmp3xx_base::BMP3XXComponent::@31 config_
bool set_iir_filter(IIRFilter iir_filter)
Set the IIR filter setting: OFF, 2, 3, 8, 16, 32.
bool set_pressure_oversampling(Oversampling pressure_oversampling)
Set the pressure oversampling: OFF, X1, X2, X4, X8, X16, X32.
struct esphome::bmp3xx_base::BMP3XXComponent::@25::@32 bit
union esphome::bmp3xx_base::BMP3XXComponent::@30 odr_
union esphome::bmp3xx_base::BMP3XXComponent::@28 pwr_ctrl_
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)
float get_setup_priority() const override
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:91
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.
union esphome::bmp3xx_base::BMP3XXComponent::@27 int_status_
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
union esphome::bmp3xx_base::BMP3XXComponent::@29 osr_
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:57
struct @67::@68 __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:301
uint16_t temperature
Definition sun_gtil2.cpp:12
uint8_t pressure
Definition tt21100.cpp:7