ESPHome
2024.12.2
|
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 More... | |
void | set_i2c_address (uint8_t address) |
We store the address of the device on the bus. More... | |
void | set_i2c_bus (I2CBus *bus) |
we store the pointer to the I2CBus to use More... | |
I2CRegister | reg (uint8_t a_register) |
calls the I2CRegister constructor More... | |
I2CRegister16 | reg16 (uint16_t a_register) |
calls the I2CRegister16 constructor More... | |
ErrorCode | read (uint8_t *data, size_t len) |
reads an array of bytes from the device using an I2CBus More... | |
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 More... | |
ErrorCode | read_register16 (uint16_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 More... | |
ErrorCode | write (const uint8_t *data, size_t len, bool stop=true) |
writes an array of bytes to a device using an I2CBus More... | |
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 More... | |
ErrorCode | write_register16 (uint16_t a_register, const uint8_t *data, size_t len, bool stop=true) |
write an array of bytes to a specific register in the I²C device More... | |
bool | read_bytes (uint8_t a_register, uint8_t *data, uint8_t len) |
Compat APIs All methods below have been added for compatibility reasons. More... | |
bool | read_bytes_raw (uint8_t *data, uint8_t len) |
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, bool stop=true) |
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, bool stop=true) |
bool | write_bytes (uint8_t a_register, const std::vector< uint8_t > &data) |
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) |
bool | write_byte (uint8_t a_register, uint8_t data, bool stop=true) |
bool | write_byte_16 (uint8_t a_register, uint16_t data) |
Protected Attributes | |
uint8_t | address_ {0x00} |
store the address of the device on the bus More... | |
I2CBus * | bus_ {nullptr} |
pointer to I2CBus instance More... | |
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
|
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, | ||
bool | stop = true |
||
) |
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 |
stop | (true/false): True will send a stop message, releasing the bus after transmission. False will send a restart, keeping the connection active. |
ErrorCode esphome::i2c::I2CDevice::read_register16 | ( | uint16_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
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 |
stop | (true/false): True will send a stop message, releasing the bus after transmission. False will send a restart, keeping the connection active. |
|
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 |
|
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 |
stop | (true/false): True will send a stop message, releasing the bus after transmission. False will send a restart, keeping the connection active. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
bool esphome::i2c::I2CDevice::write_bytes_16 | ( | uint8_t | a_register, |
const uint16_t * | data, | ||
uint8_t | len | ||
) |
ErrorCode esphome::i2c::I2CDevice::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
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 |
stop | (true/false): True will send a stop message, releasing the bus after transmission. False will send a restart, keeping the connection active. |
ErrorCode esphome::i2c::I2CDevice::write_register16 | ( | uint16_t | a_register, |
const uint8_t * | data, | ||
size_t | len, | ||
bool | stop = true |
||
) |
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 |
stop | (true/false): True will send a stop message, releasing the bus after transmission. False will send a restart, keeping the connection active. |
|
protected |
|
protected |