ESPHome  2024.11.0
bme68x_bsec2_i2c.cpp
Go to the documentation of this file.
1 #include "esphome/core/defines.h"
2 #include "esphome/core/helpers.h"
3 #include "esphome/core/log.h"
4 
5 #ifdef USE_BSEC2
6 #include "bme68x_bsec2_i2c.h"
8 
9 #include <cinttypes>
10 
11 namespace esphome {
12 namespace bme68x_bsec2_i2c {
13 
14 static const char *const TAG = "bme68x_bsec2_i2c.sensor";
15 
16 void BME68xBSEC2I2CComponent::setup() {
17  // must set up our bme68x_dev instance before calling setup()
18  this->bme68x_.intf_ptr = (void *) this;
19  this->bme68x_.intf = BME68X_I2C_INTF;
20  this->bme68x_.read = BME68xBSEC2I2CComponent::read_bytes_wrapper;
21  this->bme68x_.write = BME68xBSEC2I2CComponent::write_bytes_wrapper;
22  this->bme68x_.delay_us = BME68xBSEC2I2CComponent::delay_us;
23  this->bme68x_.amb_temp = 25;
24 
26 }
27 
28 void BME68xBSEC2I2CComponent::dump_config() {
29  LOG_I2C_DEVICE(this);
30  BME68xBSEC2Component::dump_config();
31 }
32 
33 uint32_t BME68xBSEC2I2CComponent::get_hash() { return fnv1_hash("bme68x_bsec_state_" + to_string(this->address_)); }
34 
35 int8_t BME68xBSEC2I2CComponent::read_bytes_wrapper(uint8_t a_register, uint8_t *data, uint32_t len, void *intfPtr) {
36  ESP_LOGVV(TAG, "read_bytes_wrapper: reg = %u", a_register);
37  return static_cast<BME68xBSEC2I2CComponent *>(intfPtr)->read_bytes(a_register, data, len) ? 0 : -1;
38 }
39 
40 int8_t BME68xBSEC2I2CComponent::write_bytes_wrapper(uint8_t a_register, const uint8_t *data, uint32_t len,
41  void *intfPtr) {
42  ESP_LOGVV(TAG, "write_bytes_wrapper: reg = %u", a_register);
43  return static_cast<BME68xBSEC2I2CComponent *>(intfPtr)->write_bytes(a_register, data, len) ? 0 : -1;
44 }
45 
46 void BME68xBSEC2I2CComponent::delay_us(uint32_t period, void *intfPtr) {
47  ESP_LOGVV(TAG, "Delaying for %" PRIu32 "us", period);
48  delayMicroseconds(period);
49 }
50 
51 } // namespace bme68x_bsec2_i2c
52 } // namespace esphome
53 #endif
void setup()
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
Definition: i2c.h:212
uint8_t address_
store the address of the device on the bus
Definition: i2c.h:269
std::string to_string(int value)
Definition: helpers.cpp:81
std::string size_t len
Definition: helpers.h:293
uint32_t fnv1_hash(const std::string &str)
Calculate a FNV-1 hash of str.
Definition: helpers.cpp:183
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition: core.cpp:28
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len, bool stop=true)
Definition: i2c.h:248