ESPHome  2024.11.1
bmp581.h
Go to the documentation of this file.
1 // All datasheet page references refer to Bosch Document Number BST-BMP581-DS004-04 (revision number 1.4)
2 
3 #pragma once
4 
8 
9 namespace esphome {
10 namespace bmp581 {
11 
12 static const uint8_t BMP581_ASIC_ID = 0x50; // BMP581's ASIC chip ID (page 51 of datasheet)
13 static const uint8_t RESET_COMMAND = 0xB6; // Soft reset command
14 
15 // BMP581 Register Addresses
16 enum {
17  BMP581_CHIP_ID = 0x01, // read chip ID
18  BMP581_INT_SOURCE = 0x15, // write interrupt sources
20  0x1D, // read measurement registers, 0x1D-0x1F are temperature XLSB to MSB and 0x20-0x22 are pressure XLSB to MSB
21  BMP581_INT_STATUS = 0x27, // read interrupt statuses
22  BMP581_STATUS = 0x28, // read sensor status
23  BMP581_DSP = 0x30, // write sensor configuration
24  BMP581_DSP_IIR = 0x31, // write IIR filter configuration
25  BMP581_OSR = 0x36, // write oversampling configuration
26  BMP581_ODR = 0x37, // write data rate and power mode configuration
27  BMP581_COMMAND = 0x7E // write sensor command
28 };
29 
30 // BMP581 Power mode operations
32  STANDBY_MODE = 0x0, // no active readings
33  NORMAL_MODE = 0x1, // read continuously at ODR configured rate and standby between
34  FORCED_MODE = 0x2, // read sensor once (only reading mode used by this component)
35  NONSTOP_MODE = 0x3 // read continuously with no standby
36 };
37 
38 // Temperature and pressure sensors can be oversampled to reduce noise
48 };
49 
50 // Infinite Impulse Response filter reduces noise caused by ambient disturbances
51 enum IIRFilter {
53  IIR_FILTER_2 = 0x1,
54  IIR_FILTER_4 = 0x2,
55  IIR_FILTER_8 = 0x3,
60 };
61 
63  public:
64  float get_setup_priority() const override { return setup_priority::DATA; }
65 
66  void dump_config() override;
67 
68  void setup() override;
69  void update() override;
70 
71  void set_temperature_sensor(sensor::Sensor *temperature_sensor) { this->temperature_sensor_ = temperature_sensor; }
72  void set_pressure_sensor(sensor::Sensor *pressure_sensor) { this->pressure_sensor_ = pressure_sensor; }
73 
74  void set_temperature_oversampling_config(Oversampling temperature_oversampling) {
75  this->temperature_oversampling_ = temperature_oversampling;
76  }
77  void set_pressure_oversampling_config(Oversampling pressure_oversampling) {
78  this->pressure_oversampling_ = pressure_oversampling;
79  }
80 
81  void set_temperature_iir_filter_config(IIRFilter iir_temperature_level) {
82  this->iir_temperature_level_ = iir_temperature_level;
83  }
84  void set_pressure_iir_filter_config(IIRFilter iir_pressure_level) { this->iir_pressure_level_ = iir_pressure_level; }
85 
86  void set_conversion_time(uint8_t conversion_time) { this->conversion_time_ = conversion_time; }
87 
88  protected:
91 
94 
97 
98  // Stores the sensors conversion time needed for a measurement based on oversampling settings and datasheet (page 12)
99  // Computed in Python during codegen
101 
102  // Checks if the BMP581 has measurement data ready by checking the sensor's interrupts
103  bool check_data_readiness_();
104 
105  // Flushes the IIR filter and primes an initial reading
106  bool prime_iir_filter_();
107 
108  // Reads temperature data from sensor and converts data to measurement in degrees Celsius
109  bool read_temperature_(float &temperature);
110  // Reads temperature and pressure data from sensor and converts data to measurements in degrees Celsius and Pa
112 
113  // Soft resets the BMP581
114  bool reset_();
115 
116  // Initiates a measurement on sensor by switching to FORCED_MODE
117  bool start_measurement_();
118 
119  // Writes the IIR filter configuration to the DSP and DSP_IIR registers
120  bool write_iir_settings_(IIRFilter temperature_iir, IIRFilter pressure_iir);
121 
122  // Writes whether to enable the data ready interrupt to the interrupt source register
123  bool write_interrupt_source_settings_(bool data_ready_enable);
124 
125  // Writes the oversampling settings to the OSR register
126  bool write_oversampling_settings_(Oversampling temperature_oversampling, Oversampling pressure_oversampling);
127 
128  // Sets the power mode on the BMP581 by writing to the ODR register
130 
131  enum ErrorCode {
132  NONE = 0,
138  } error_code_{NONE};
139 
140  // BMP581's interrupt source register (address 0x15) to configure which interrupts are enabled (page 54 of datasheet)
141  union {
142  struct {
143  uint8_t drdy_data_reg_en : 1; // Data ready interrupt enable
144  uint8_t fifo_full_en : 1; // FIFO full interrupt enable
145  uint8_t fifo_ths_en : 1; // FIFO threshold/watermark interrupt enable
146  uint8_t oor_p_en : 1; // Pressure data out-of-range interrupt enable
147  } bit;
148  uint8_t reg;
149  } int_source_ = {.reg = 0};
150 
151  // BMP581's interrupt status register (address 0x27) to determine ensor's current state (page 58 of datasheet)
152  union {
153  struct {
154  uint8_t drdy_data_reg : 1; // Data ready
155  uint8_t fifo_full : 1; // FIFO full
156  uint8_t fifo_ths : 1; // FIFO fhreshold/watermark
157  uint8_t oor_p : 1; // Pressure data out-of-range
158  uint8_t por : 1; // Power-On-Reset complete
159  } bit;
160  uint8_t reg;
161  } int_status_ = {.reg = 0};
162 
163  // BMP581's status register (address 0x28) to determine if sensor has setup correctly (page 58 of datasheet)
164  union {
165  struct {
166  uint8_t status_core_rdy : 1;
167  uint8_t status_nvm_rdy : 1; // asserted if NVM is ready of operations
168  uint8_t status_nvm_err : 1; // asserted if NVM error
169  uint8_t status_nvm_cmd_err : 1; // asserted if boot command error
170  uint8_t status_boot_err_corrected : 1; // asserted if a boot error has been corrected
171  uint8_t : 2;
172  uint8_t st_crack_pass : 1; // asserted if crack check has executed without detecting a crack
173  } bit;
174  uint8_t reg;
175  } status_ = {.reg = 0};
176 
177  // BMP581's dsp register (address 0x30) to configure data registers iir selection (page 61 of datasheet)
178  union {
179  struct {
180  uint8_t comp_pt_en : 2; // enable temperature and pressure compensation
181  uint8_t iir_flush_forced_en : 1; // IIR filter is flushed in forced mode
182  uint8_t shdw_sel_iir_t : 1; // temperature data register value selected before or after iir
183  uint8_t fifo_sel_iir_t : 1; // FIFO temperature data register value secected before or after iir
184  uint8_t shdw_sel_iir_p : 1; // pressure data register value selected before or after iir
185  uint8_t fifo_sel_iir_p : 1; // FIFO pressure data register value selected before or after iir
186  uint8_t oor_sel_iir_p : 1; // pressure out-of-range value selected before or after iir
187  } bit;
188  uint8_t reg;
189  } dsp_config_ = {.reg = 0};
190 
191  // BMP581's iir register (address 0x31) to configure iir filtering(page 62 of datasheet)
192  union {
193  struct {
194  uint8_t set_iir_t : 3; // Temperature IIR filter coefficient
195  uint8_t set_iir_p : 3; // Pressure IIR filter coefficient
196  } bit;
197  uint8_t reg;
198  } iir_config_ = {.reg = 0};
199 
200  // BMP581's OSR register (address 0x36) to configure Over-Sampling Rates (page 64 of datasheet)
201  union {
202  struct {
203  uint8_t osr_t : 3; // Temperature oversampling
204  uint8_t osr_p : 3; // Pressure oversampling
205  uint8_t press_en : 1; // Enables pressure measurement
206  } bit;
207  uint8_t reg;
208  } osr_config_ = {.reg = 0};
209 
210  // BMP581's odr register (address 0x37) to configure output data rate and power mode (page 64 of datasheet)
211  union {
212  struct {
213  uint8_t pwr_mode : 2; // power mode of sensor
214  uint8_t odr : 5; // output data rate
215  uint8_t deep_dis : 1; // deep standby disabled if asserted
216  } bit;
217  uint8_t reg;
218  } odr_config_ = {.reg = 0};
219 };
220 
221 } // namespace bmp581
222 } // namespace esphome
float get_setup_priority() const override
Definition: bmp581.h:64
Oversampling pressure_oversampling_
Definition: bmp581.h:93
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
bool write_iir_settings_(IIRFilter temperature_iir, IIRFilter pressure_iir)
Definition: bmp581.cpp:538
void set_pressure_sensor(sensor::Sensor *pressure_sensor)
Definition: bmp581.h:72
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: bmp581.h:71
bool read_temperature_(float &temperature)
Definition: bmp581.cpp:439
uint8_t pressure
Definition: tt21100.cpp:19
bool write_interrupt_source_settings_(bool data_ready_enable)
Definition: bmp581.cpp:564
void set_conversion_time(uint8_t conversion_time)
Definition: bmp581.h:86
void set_pressure_iir_filter_config(IIRFilter iir_pressure_level)
Definition: bmp581.h:84
sensor::Sensor * temperature_sensor_
Definition: bmp581.h:89
void set_pressure_oversampling_config(Oversampling pressure_oversampling)
Definition: bmp581.h:77
This class simplifies creating components that periodically check a state.
Definition: component.h:283
enum esphome::bmp581::BMP581Component::ErrorCode NONE
sensor::Sensor * pressure_sensor_
Definition: bmp581.h:90
struct esphome::bmp581::BMP581Component::@40::@47 bit
bool read_temperature_and_pressure_(float &temperature, float &pressure)
Definition: bmp581.cpp:467
union esphome::bmp581::BMP581Component::@46 odr_config_
bool write_power_mode_(OperationMode mode)
Definition: bmp581.cpp:585
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:183
void dump_config() override
Definition: bmp581.cpp:68
union esphome::bmp581::BMP581Component::@42 status_
Oversampling temperature_oversampling_
Definition: bmp581.h:92
uint16_t temperature
Definition: sun_gtil2.cpp:26
union esphome::bmp581::BMP581Component::@45 osr_config_
union esphome::bmp581::BMP581Component::@44 iir_config_
void set_temperature_oversampling_config(Oversampling temperature_oversampling)
Definition: bmp581.h:74
void set_temperature_iir_filter_config(IIRFilter iir_temperature_level)
Definition: bmp581.h:81
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
union esphome::bmp581::BMP581Component::@43 dsp_config_
union esphome::bmp581::BMP581Component::@40 int_source_
Base-class for all sensors.
Definition: sensor.h:57
bool write_oversampling_settings_(Oversampling temperature_oversampling, Oversampling pressure_oversampling)
Definition: bmp581.cpp:574
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
union esphome::bmp581::BMP581Component::@41 int_status_