|
ESPHome 2025.12.0-dev
|
This Class provides the methods to read/write bytes from/to an i2c device. More...
#include <i2c.h>
Public Member Functions | |
| I2CDevice ()=default | |
| we use the C++ default constructor | |
| void | set_i2c_address (uint8_t address) |
| We store the address of the device on the bus. | |
| uint8_t | get_i2c_address () const |
| Returns the I2C address of the object. | |
| void | set_i2c_bus (I2CBus *bus) |
| we store the pointer to the I2CBus to use | |
| I2CRegister | reg (uint8_t a_register) |
| calls the I2CRegister constructor | |
| I2CRegister16 | reg16 (uint16_t a_register) |
| calls the I2CRegister16 constructor | |
| ErrorCode | read (uint8_t *data, size_t len) const |
| reads an array of bytes from the device using an I2CBus | |
| 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 | |
| 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 | write (const uint8_t *data, size_t len) const |
| writes an array of bytes to a device using an I2CBus | |
| ErrorCode | write_read (const uint8_t *write_data, size_t write_len, uint8_t *read_data, size_t read_len) const |
| writes an array of bytes to a device, then reads an array, as a single transaction | |
| 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 | read_bytes (uint8_t a_register, uint8_t *data, uint8_t len) |
| Compat APIs All methods below have been added for compatibility reasons. | |
| bool | read_bytes_raw (uint8_t *data, uint8_t len) const |
| template<size_t N> | |
| optional< std::array< uint8_t, N > > | read_bytes (uint8_t a_register) |
| template<size_t N> | |
| optional< std::array< uint8_t, N > > | read_bytes_raw () |
| bool | read_bytes_16 (uint8_t a_register, uint16_t *data, uint8_t len) |
| bool | read_byte (uint8_t a_register, uint8_t *data) |
| optional< uint8_t > | read_byte (uint8_t a_register) |
| bool | read_byte_16 (uint8_t a_register, uint16_t *data) |
| bool | write_bytes (uint8_t a_register, const uint8_t *data, uint8_t len) const |
| bool | write_bytes (uint8_t a_register, const std::vector< uint8_t > &data) const |
| template<size_t N> | |
| bool | write_bytes (uint8_t a_register, const std::array< uint8_t, N > &data) |
| bool | write_bytes_16 (uint8_t a_register, const uint16_t *data, uint8_t len) const |
| bool | write_byte (uint8_t a_register, uint8_t data) const |
| bool | write_byte_16 (uint8_t a_register, uint16_t data) const |
| ESPDEPRECATED ("The stop argument is no longer used. This will be removed from ESPHome 2026.3.0", "2025.9.0") ErrorCode read_register(uint8_t a_register | |
| ESPDEPRECATED ("The stop argument is no longer used. This will be removed from ESPHome 2026.3.0", "2025.9.0") ErrorCode read_register16(uint16_t a_register | |
| ESPDEPRECATED ("The stop argument is no longer used; use write_read() for consecutive write and read. This will be " "removed from ESPHome 2026.3.0", "2025.9.0") ErrorCode write(const uint8_t *data | |
| ESPDEPRECATED ("The stop argument is no longer used; use write_read() for consecutive write and read. This will be " "removed from ESPHome 2026.3.0", "2025.9.0") ErrorCode write_register(uint8_t a_register | |
| ESPDEPRECATED ("The stop argument is no longer used; use write_read() for consecutive write and read. This will be " "removed from ESPHome 2026.3.0", "2025.9.0") ErrorCode write_register16(uint16_t a_register | |
Data Fields | |
| uint8_t * | data |
| uint8_t size_t | len |
| uint8_t size_t bool | stop |
| size_t | len |
| size_t bool stop | const { return this->write(data, len) |
| const uint8_t * | data |
| const uint8_t size_t | len |
| const uint8_t size_t bool stop | const |
Protected Attributes | |
| uint8_t | address_ {0x00} |
| store the address of the device on the bus | |
| I2CBus * | bus_ {nullptr} |
| pointer to I2CBus instance | |
This Class provides the methods to read/write bytes from/to an i2c device.
Objects keep a list of devices found on bus as well as a pointer to the I2CBus in use.
|
default |
we use the C++ default constructor
| esphome::i2c::I2CDevice::ESPDEPRECATED | ( | "The stop argument is no longer used. This will be removed from ESPHome 2026.3.0" | , |
| "2025.9.0" | ) |
| esphome::i2c::I2CDevice::ESPDEPRECATED | ( | "The stop argument is no longer used. This will be removed from ESPHome 2026.3.0" | , |
| "2025.9.0" | ) |
| esphome::i2c::I2CDevice::ESPDEPRECATED | ( | "The stop argument is no longer used; use write_read() for consecutive write and read. This will be " "removed from ESPHome 2026.3.0" | , |
| "2025.9.0" | ) const |
| esphome::i2c::I2CDevice::ESPDEPRECATED | ( | "The stop argument is no longer used; use write_read() for consecutive write and read. This will be " "removed from ESPHome 2026.3.0" | , |
| "2025.9.0" | ) |
| esphome::i2c::I2CDevice::ESPDEPRECATED | ( | "The stop argument is no longer used; use write_read() for consecutive write and read. This will be " "removed from ESPHome 2026.3.0" | , |
| "2025.9.0" | ) |
|
inline |
|
inline |
reads an array of bytes from the device using an I2CBus
| data | pointer to an array to store the bytes |
| len | length of the buffer = number of bytes to read |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
| bool esphome::i2c::I2CDevice::read_bytes_16 | ( | uint8_t | a_register, |
| uint16_t * | data, | ||
| uint8_t | len ) |
|
inline |
|
inline |
| ErrorCode esphome::i2c::I2CDevice::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
| a_register | an 8 bits internal address of the I²C register to read from |
| data | pointer to an array to store the bytes |
| len | length of the buffer = number of bytes to read |
| ErrorCode esphome::i2c::I2CDevice::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
| a_register | the 16 bits internal address of the I²C register to read from |
| data | pointer to an array of bytes to store the information |
| len | length of the buffer = number of bytes to read |
|
inline |
calls the I2CRegister constructor
| a_register | address of the I²C register |
|
inline |
calls the I2CRegister16 constructor
| a_register | 16 bits address of the I²C register |
|
inline |
|
inline |
writes an array of bytes to a device using an I2CBus
| data | pointer to an array that contains the bytes to send |
| len | length of the buffer = number of bytes to write |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
| bool esphome::i2c::I2CDevice::write_bytes_16 | ( | uint8_t | a_register, |
| const uint16_t * | data, | ||
| uint8_t | len ) const |
|
inline |
writes an array of bytes to a device, then reads an array, as a single transaction
| write_data | pointer to an array that contains the bytes to send |
| write_len | length of the buffer = number of bytes to write |
| read_data | pointer to an array to store the bytes read |
| read_len | length of the buffer = number of bytes to read |
| ErrorCode esphome::i2c::I2CDevice::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
| a_register | the internal address of the register to read from |
| data | pointer to an array to store the bytes |
| len | length of the buffer = number of bytes to read |
| ErrorCode esphome::i2c::I2CDevice::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
| a_register | the 16 bits internal address of the register to read from |
| data | pointer to an array to store the bytes |
| len | length of the buffer = number of bytes to read |
|
protected |
|
protected |
| const uint8_t size_t bool stop esphome::i2c::I2CDevice::const |
| uint8_t size_t bool esphome::i2c::I2CDevice::stop |