12#define LOG_I2C_DEVICE(this) ESP_LOGCONFIG(TAG, " Address: 0x%02X", this->address_);
52 explicit operator uint8_t()
const {
return get(); }
107 explicit operator uint8_t()
const {
return get(); }
223 std::array<uint8_t, N> res;
224 if (!this->
read_bytes(a_register, res.data(), N)) {
230 std::array<uint8_t, N> res;
239 bool read_byte(uint8_t a_register, uint8_t *data,
bool stop =
true) {
252 bool write_bytes(uint8_t a_register,
const uint8_t *data, uint8_t
len,
bool stop =
true) {
256 bool write_bytes(uint8_t a_register,
const std::vector<uint8_t> &data) {
257 return write_bytes(a_register, data.data(), data.size());
260 template<
size_t N>
bool write_bytes(uint8_t a_register,
const std::array<uint8_t, N> &data) {
261 return write_bytes(a_register, data.data(), data.size());
266 bool write_byte(uint8_t a_register, uint8_t data,
bool stop =
true) {
This Class provides the methods to read and write bytes from an I2CBus.
virtual ErrorCode read(uint8_t address, uint8_t *buffer, size_t len)
Creates a ReadBuffer and calls the virtual readv() method to read bytes into this buffer.
virtual ErrorCode write(uint8_t address, const uint8_t *buffer, size_t len)
This Class provides the methods to read/write bytes from/to an i2c device.
bool read_bytes_raw(uint8_t *data, uint8_t len)
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
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::array< uint8_t, N > &data)
bool write_bytes(uint8_t a_register, const std::vector< uint8_t > &data)
bool write_bytes_16(uint8_t a_register, const uint16_t *data, uint8_t len)
void set_i2c_bus(I2CBus *bus)
we store the pointer to the I2CBus to use
uint8_t get_i2c_address() const
Returns the I2C address of the object.
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
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
optional< std::array< uint8_t, N > > read_bytes_raw()
I2CBus * bus_
pointer to I2CBus instance
optional< uint8_t > read_byte(uint8_t a_register)
uint8_t address_
store the address of the device on the bus
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
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
bool read_byte_16(uint8_t a_register, uint16_t *data)
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
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
optional< std::array< uint8_t, N > > read_bytes(uint8_t a_register)
void set_i2c_address(uint8_t address)
We store the address of the device on the bus.
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)
I2CRegister16 reg16(uint16_t a_register)
calls the I2CRegister16 constructor
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
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 write_byte_16(uint8_t a_register, uint16_t data)
I2CDevice()=default
we use the C++ default constructor
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(I2CDevice *parent, uint16_t a_register)
protected constructor that store the owning object and the register address.
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(I2CDevice *parent, uint8_t a_register)
protected constructor that stores the owning object and the register address.
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.
uint16_t htoi2cs(uint16_t hostshort)
Providing packet encoding functions for exchanging data with a remote host.
constexpr14 T convert_big_endian(T val)
Convert a value between host byte order and big endian (most significant byte first) order.