esphome/esphome/components/ina2xx_spi/ina2xx_spi.cpp
Anton Viktorov b06e0746f5
INA228/INA229, INA238/INA239, INA237 power/energy/charge monitor (I2C, SPI) (#6138)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2024-05-16 16:50:28 +12:00

38 lines
841 B
C++

#include "ina2xx_spi.h"
#include "esphome/core/log.h"
namespace esphome {
namespace ina2xx_spi {
static const char *const TAG = "ina2xx_spi";
void INA2XXSPI::setup() {
this->spi_setup();
INA2XX::setup();
}
void INA2XXSPI::dump_config() {
INA2XX::dump_config();
LOG_PIN(" CS Pin: ", this->cs_);
}
bool INA2XXSPI::read_ina_register(uint8_t reg, uint8_t *data, size_t len) {
reg = (reg << 2); // top 6 bits
reg |= 0x01; // read
this->enable();
this->write_byte(reg);
this->read_array(data, len);
this->disable();
return true;
}
bool INA2XXSPI::write_ina_register(uint8_t reg, const uint8_t *data, size_t len) {
reg = (reg << 2); // top 6 bits
this->enable();
this->write_byte(reg);
this->write_array(data, len);
this->disable();
return true;
}
} // namespace ina2xx_spi
} // namespace esphome