ESPHome 2025.6.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
ina2xx_i2c.cpp
Go to the documentation of this file.
1#include "ina2xx_i2c.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace ina2xx_i2c {
6
7static const char *const TAG = "ina2xx_i2c";
8
10 auto err = this->write(nullptr, 0);
11 if (err != i2c::ERROR_OK) {
12 this->mark_failed();
13 return;
14 }
15 INA2XX::setup();
16}
17
19 INA2XX::dump_config();
20 LOG_I2C_DEVICE(this);
21}
22
23bool INA2XXI2C::read_ina_register(uint8_t reg, uint8_t *data, size_t len) {
24 auto ret = this->read_register(reg, data, len, false);
25 if (ret != i2c::ERROR_OK) {
26 ESP_LOGE(TAG, "read_ina_register_ failed. Reg=0x%02X Err=%d", reg, ret);
27 }
28 return ret == i2c::ERROR_OK;
29}
30
31bool INA2XXI2C::write_ina_register(uint8_t reg, const uint8_t *data, size_t len) {
32 auto ret = this->write_register(reg, data, len);
33 if (ret != i2c::ERROR_OK) {
34 ESP_LOGE(TAG, "write_register failed. Reg=0x%02X Err=%d", reg, ret);
35 }
36 return ret == i2c::ERROR_OK;
37}
38} // namespace ina2xx_i2c
39} // namespace esphome
virtual void mark_failed()
Mark this component as failed.
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a specific register in the I²C device
Definition i2c.cpp:25
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
Definition i2c.h:190
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition i2c.h:153
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len, bool stop=true)
reads an array of bytes from a specific register in the I²C device
Definition i2c.cpp:10
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:13
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:302