25 ESP_LOGE(TAG,
"Wrong chip ID 0x%02X, expected 0x%02X",
id, expected);
50 buffer[0] = a_register >> 8;
57 for (
size_t i = 0; i <
count; i++) {
60 if (this->
bus_->
write_readv(this->address_,
reinterpret_cast<const uint8_t *
>(&entry),
sizeof(entry),
nullptr, 0) !=
62 ESP_LOGW(TAG,
"Writing register 0x%02X (table entry %u) to 0x%02X failed", entry.
reg,
static_cast<unsigned>(i),
73 for (
size_t i = 0; i <
len; i++)
82 const uint8_t updated = (data & ~mask) | (value & mask);
83 ESP_LOGV(TAG,
"Register 0x%02X: 0x%02X -> 0x%02X", a_register, data, updated);
88 const size_t size = 1 +
len * 2;
93 for (
size_t i = 0; i <
len; i++) {
94 const uint16_t word = data[i];
95 buffer[1 + i * 2] = word >> 8;
102 const uint8_t
buffer[3] = {a_register,
static_cast<uint8_t
>(data >> 8),
static_cast<uint8_t
>(data)};
107 const uint8_t
buffer[3] = {a_register,
static_cast<uint8_t
>(data),
static_cast<uint8_t
>(data >> 8)};
127 uint8_t value = 0x00;
148 uint8_t value = 0x00;
Helper class for efficient buffer allocation - uses stack for small sizes, heap for large This is use...
virtual ErrorCode write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count, uint8_t *read_buffer, size_t read_count)=0
This virtual method writes bytes to an I2CBus from an array, then reads bytes into an array of ReadBu...
std::vector< std::pair< uint8_t, bool > > scan_results_
array containing scan results
void i2c_scan_()
Scans the I2C bus for devices.
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
ErrorCode write_register16(uint16_t a_register, const uint8_t *data, size_t len) const
write an array of bytes to a specific register in the I²C device
bool write_byte_16_le(uint8_t a_register, uint16_t data) const
Write a 16-bit value least significant byte first.
bool write_bytes_16(uint8_t a_register, const uint16_t *data, uint8_t len) const
I2CBus * bus_
pointer to I2CBus instance
uint8_t address_
store the address of the device on the bus
bool write_byte(uint8_t a_register, uint8_t data) const
bool read_byte(uint8_t a_register, uint8_t *data)
ErrorCode read_register16(uint16_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
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
bool read_bytes_16(uint8_t a_register, uint16_t *data, uint8_t len)
bool write_byte_16(uint8_t a_register, uint16_t data) const
bool update_register(uint8_t a_register, uint8_t mask, uint8_t value)
Read a register, replace the bits in mask with those of value and write it back.
bool write_registers(const I2CRegValue *table, size_t count) const
Write each register and value of table in order, stopping at the first failure.
This class is used to create I2CRegister16 objects that act as proxies to read/write internal registe...
uint16_t register_
the internal 16 bits address of the register
I2CRegister16 & operator&=(uint8_t value)
overloads the compound &= operator.
I2CRegister16 & operator|=(uint8_t value)
overloads the compound |= operator.
I2CDevice * parent_
I2CDevice object pointer.
uint8_t get() const
returns the register value
I2CRegister16 & operator=(uint8_t value)
overloads the = operator.
This class is used to create I2CRegister objects that act as proxies to read/write internal registers...
I2CRegister & operator|=(uint8_t value)
overloads the compound |= operator.
uint8_t get() const
returns the register value
I2CRegister & operator&=(uint8_t value)
overloads the compound &= operator.
I2CDevice * parent_
I2CDevice object pointer.
uint8_t register_
the internal address of the register
I2CRegister & operator=(uint8_t value)
overloads the = operator.
uint16_t i2ctohs(uint16_t i2cshort)
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
@ ERROR_OK
No error found during execution of method.
@ ERROR_UNKNOWN
miscellaneous I2C error during execution
void log_wrong_chip_id(uint8_t id, uint8_t expected)
Out of line so each check_chip_id() caller only pays for a call.
ESPHOME_LOG_TAG(TAG, "i2c")
constexpr T convert_big_endian(T val)
Convert a value between host byte order and big endian (most significant byte first) order.
void progmem_memcpy(void *dst, const void *src, size_t len)
One register write for I2CDevice::write_registers(); tables of these may live in PROGMEM.