ESPHome  2024.11.1
ina2xx_i2c.cpp
Go to the documentation of this file.
1 #include "ina2xx_i2c.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace ina2xx_i2c {
6 
7 static 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 
23 bool 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 
31 bool 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
void setup()
bool read_ina_register(uint8_t reg, uint8_t *data, size_t len) override
Definition: ina2xx_i2c.cpp:23
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
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition: i2c.h:149
bool write_ina_register(uint8_t reg, const uint8_t *data, size_t len) override
Definition: ina2xx_i2c.cpp:31
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:186
No error found during execution of method.
Definition: i2c_bus.h:13
std::string size_t len
Definition: helpers.h:293
virtual void mark_failed()
Mark this component as failed.
Definition: component.cpp:118
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
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