ESPHome 2025.6.3
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
12namespace esphome {
13namespace bme68x_bsec2_i2c {
14
15static const char *const TAG = "bme68x_bsec2_i2c.sensor";
16
17void BME68xBSEC2I2CComponent::setup() {
18 // must set up our bme68x_dev instance before calling setup()
19 this->bme68x_.intf_ptr = (void *) this;
20 this->bme68x_.intf = BME68X_I2C_INTF;
21 this->bme68x_.read = BME68xBSEC2I2CComponent::read_bytes_wrapper;
22 this->bme68x_.write = BME68xBSEC2I2CComponent::write_bytes_wrapper;
23 this->bme68x_.delay_us = BME68xBSEC2I2CComponent::delay_us;
24 this->bme68x_.amb_temp = 25;
25
26 BME68xBSEC2Component::setup();
27}
28
29void BME68xBSEC2I2CComponent::dump_config() {
30 LOG_I2C_DEVICE(this);
31 BME68xBSEC2Component::dump_config();
32}
33
34uint32_t BME68xBSEC2I2CComponent::get_hash() { return fnv1_hash("bme68x_bsec_state_" + to_string(this->address_)); }
35
36int8_t BME68xBSEC2I2CComponent::read_bytes_wrapper(uint8_t a_register, uint8_t *data, uint32_t len, void *intfPtr) {
37 ESP_LOGVV(TAG, "read_bytes_wrapper: reg = %u", a_register);
38 return static_cast<BME68xBSEC2I2CComponent *>(intfPtr)->read_bytes(a_register, data, len) ? 0 : -1;
39}
40
41int8_t BME68xBSEC2I2CComponent::write_bytes_wrapper(uint8_t a_register, const uint8_t *data, uint32_t len,
42 void *intfPtr) {
43 ESP_LOGVV(TAG, "write_bytes_wrapper: reg = %u", a_register);
44 return static_cast<BME68xBSEC2I2CComponent *>(intfPtr)->write_bytes(a_register, data, len) ? 0 : -1;
45}
46
47void BME68xBSEC2I2CComponent::delay_us(uint32_t period, void *intfPtr) {
48 ESP_LOGVV(TAG, "Delaying for %" PRIu32 "us", period);
49 delayMicroseconds(period);
50}
51
52} // namespace bme68x_bsec2_i2c
53} // namespace esphome
54#endif
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len, bool stop=true)
Definition i2c.h:252
uint8_t address_
store the address of the device on the bus
Definition i2c.h:273
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:216
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint32_t fnv1_hash(const std::string &str)
Calculate a FNV-1 hash of str.
Definition helpers.cpp:186
std::string size_t len
Definition helpers.h:302
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition core.cpp:31
std::string to_string(int value)
Definition helpers.cpp:82