ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
ina2xx_i2c.cpp
Go to the documentation of this file.
1#include "ina2xx_i2c.h"
2#include "esphome/core/log.h"
3
5
6static const char *const TAG = "ina2xx_i2c";
7
9 auto err = this->write(nullptr, 0);
10 if (err != i2c::ERROR_OK) {
11 this->mark_failed();
12 return;
13 }
14 INA2XX::setup();
15}
16
18 INA2XX::dump_config();
19 LOG_I2C_DEVICE(this);
20}
21
22bool INA2XXI2C::read_ina_register(uint8_t reg, uint8_t *data, size_t len) {
23 auto ret = this->read_register(reg, data, len);
24 if (ret != i2c::ERROR_OK) {
25 ESP_LOGE(TAG, "read_ina_register_ failed. Reg=0x%02X Err=%d", reg, ret);
26 }
27 return ret == i2c::ERROR_OK;
28}
29
30bool INA2XXI2C::write_ina_register(uint8_t reg, const uint8_t *data, size_t len) {
31 auto ret = this->write_register(reg, data, len);
32 if (ret != i2c::ERROR_OK) {
33 ESP_LOGE(TAG, "write_register failed. Reg=0x%02X Err=%d", reg, ret);
34 }
35 return ret == i2c::ERROR_OK;
36}
37} // namespace esphome::ina2xx_i2c
void mark_failed()
Mark this component as failed.
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len) const
writes an array of bytes to a specific register in the I²C device
Definition i2c.cpp:34
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
Definition i2c.h:183
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition i2c.h:152
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
Definition i2c.cpp:25
bool read_ina_register(uint8_t reg, uint8_t *data, size_t len) override
bool write_ina_register(uint8_t reg, const uint8_t *data, size_t len) override
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:14
const void size_t len
Definition hal.h:64