ESPHome 2025.5.0
Loading...
Searching...
No Matches
bme68x_bsec2_i2c.cpp
Go to the documentation of this file.
3#include "esphome/core/log.h"
4
5#ifdef USE_BSEC2
6#include "bme68x_bsec2_i2c.h"
8
9#include <cinttypes>
10
11namespace esphome {
12namespace bme68x_bsec2_i2c {
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() { return fnv1_hash("bme68x_bsec_state_" + to_string(this->address_)); }
34
35int8_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
40int8_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
46void 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
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:301
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition core.cpp:30
std::string to_string(int value)
Definition helpers.cpp:82