ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
bme68x_bsec2_i2c.cpp
Go to the documentation of this file.
2#include "esphome/core/hal.h"
4#include "esphome/core/log.h"
5
6#ifdef USE_BSEC2
7#include "bme68x_bsec2_i2c.h"
9
10#include <cinttypes>
11
13
14static const char *const TAG = "bme68x_bsec2_i2c.sensor";
15
16void 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
25 BME68xBSEC2Component::setup();
26}
27
28void BME68xBSEC2I2CComponent::dump_config() {
29 LOG_I2C_DEVICE(this);
30 BME68xBSEC2Component::dump_config();
31}
32
33uint32_t BME68xBSEC2I2CComponent::get_hash() {
34 char buf[22]; // "bme68x_bsec_state_" (18) + uint8_t max (3) + null
35 snprintf(buf, sizeof(buf), "bme68x_bsec_state_%u", this->address_);
36 return fnv1_hash(buf);
37}
38
39int8_t BME68xBSEC2I2CComponent::read_bytes_wrapper(uint8_t a_register, uint8_t *data, uint32_t len, void *intfPtr) {
40 ESP_LOGVV(TAG, "read_bytes_wrapper: reg = %u", a_register);
41 return static_cast<BME68xBSEC2I2CComponent *>(intfPtr)->read_bytes(a_register, data, len) ? 0 : -1;
42}
43
44int8_t BME68xBSEC2I2CComponent::write_bytes_wrapper(uint8_t a_register, const uint8_t *data, uint32_t len,
45 void *intfPtr) {
46 ESP_LOGVV(TAG, "write_bytes_wrapper: reg = %u", a_register);
47 return static_cast<BME68xBSEC2I2CComponent *>(intfPtr)->write_bytes(a_register, data, len) ? 0 : -1;
48}
49
50void BME68xBSEC2I2CComponent::delay_us(uint32_t period, void *intfPtr) {
51 ESP_LOGVV(TAG, "Delaying for %" PRIu32 "us", period);
52 delayMicroseconds(period);
53}
54
55} // namespace esphome::bme68x_bsec2_i2c
56#endif
uint8_t address_
store the address of the device on the bus
Definition i2c.h:270
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len) const
Definition i2c.h:251
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:217
const void size_t len
Definition hal.h:64
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition hal.cpp:48
uint32_t fnv1_hash(const char *str)
Calculate a FNV-1 hash of str.
Definition helpers.cpp:160
static void uint32_t