ESPHome  2024.11.1
ina2xx_spi.cpp
Go to the documentation of this file.
1 #include "ina2xx_spi.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace ina2xx_spi {
6 
7 static const char *const TAG = "ina2xx_spi";
8 
10  this->spi_setup();
11  INA2XX::setup();
12 }
13 
15  INA2XX::dump_config();
16  LOG_PIN(" CS Pin: ", this->cs_);
17 }
18 
19 bool INA2XXSPI::read_ina_register(uint8_t reg, uint8_t *data, size_t len) {
20  reg = (reg << 2); // top 6 bits
21  reg |= 0x01; // read
22  this->enable();
23  this->write_byte(reg);
24  this->read_array(data, len);
25  this->disable();
26  return true;
27 }
28 
29 bool INA2XXSPI::write_ina_register(uint8_t reg, const uint8_t *data, size_t len) {
30  reg = (reg << 2); // top 6 bits
31  this->enable();
32  this->write_byte(reg);
33  this->write_array(data, len);
34  this->disable();
35  return true;
36 }
37 } // namespace ina2xx_spi
38 } // namespace esphome
void setup()
bool write_ina_register(uint8_t reg, const uint8_t *data, size_t len) override
Definition: ina2xx_spi.cpp:29
GPIOPin * cs_
Definition: spi.h:378
bool read_ina_register(uint8_t reg, uint8_t *data, size_t len) override
Definition: ina2xx_spi.cpp:19
std::string size_t len
Definition: helpers.h:293
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7