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(); }
169 ErrorCode read_register(uint8_t a_register, uint8_t *data,
size_t len,
bool stop =
true);
178 ErrorCode read_register16(uint16_t a_register, uint8_t *data,
size_t len,
bool stop =
true);
186 ErrorCode write(
const uint8_t *data,
size_t len,
bool stop =
true) {
return bus_->write(address_, data, len, stop); }
195 ErrorCode write_register(uint8_t a_register,
const uint8_t *data,
size_t len,
bool stop =
true);
204 ErrorCode write_register16(uint16_t a_register,
const uint8_t *data,
size_t len,
bool stop =
true);
212 bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len) {
213 return read_register(a_register, data, len) ==
ERROR_OK;
219 std::array<uint8_t, N> res;
220 if (!this->read_bytes(a_register, res.data(), N)) {
226 std::array<uint8_t, N> res;
227 if (!this->read_bytes_raw(res.data(), N)) {
233 bool read_bytes_16(uint8_t a_register, uint16_t *data, uint8_t len);
235 bool read_byte(uint8_t a_register, uint8_t *data,
bool stop =
true) {
236 return read_register(a_register, data, 1, stop) ==
ERROR_OK;
241 if (!this->read_byte(a_register, &data))
246 bool read_byte_16(uint8_t a_register, uint16_t *data) {
return read_bytes_16(a_register, data, 1); }
248 bool write_bytes(uint8_t a_register,
const uint8_t *data, uint8_t len,
bool stop =
true) {
249 return write_register(a_register, data, len, stop) ==
ERROR_OK;
252 bool write_bytes(uint8_t a_register,
const std::vector<uint8_t> &data) {
253 return write_bytes(a_register, data.data(), data.size());
256 template<
size_t N>
bool write_bytes(uint8_t a_register,
const std::array<uint8_t, N> &data) {
257 return write_bytes(a_register, data.data(), data.size());
260 bool write_bytes_16(uint8_t a_register,
const uint16_t *data, uint8_t len);
262 bool write_byte(uint8_t a_register, uint8_t data,
bool stop =
true) {
263 return write_bytes(a_register, &data, 1, stop);
266 bool write_byte_16(uint8_t a_register, uint16_t data) {
return write_bytes_16(a_register, &data, 1); }
269 uint8_t address_{0x00};
optional< std::array< uint8_t, N > > read_bytes(uint8_t a_register)
I2CDevice * parent_
I2CDevice object pointer.
I2CRegister(I2CDevice *parent, uint8_t a_register)
protected constructor that stores the owning object and the register address.
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
bool read_byte_16(uint8_t a_register, uint16_t *data)
uint16_t i2ctohs(uint16_t i2cshort)
uint16_t register_
the internal 16 bits address of the register
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
optional< std::array< uint8_t, N > > read_bytes_raw()
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
uint8_t register_
the internal address of the register
bool read_bytes_raw(uint8_t *data, uint8_t len)
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
uint16_t htoi2cs(uint16_t hostshort)
I2CRegister & operator|=(uint8_t value)
overloads the compound |= operator.
bool write_bytes(uint8_t a_register, const std::array< uint8_t, N > &data)
No error found during execution of method.
This Class provides the methods to read and write bytes from an I2CBus.
constexpr14 T convert_big_endian(T val)
Convert a value between host byte order and big endian (most significant byte first) order...
optional< uint8_t > read_byte(uint8_t a_register)
bool write_bytes(uint8_t a_register, const std::vector< uint8_t > &data)
I2CRegister16 reg16(uint16_t a_register)
calls the I2CRegister16 constructor
This class is used to create I2CRegister objects that act as proxies to read/write internal registers...
I2CRegister16(I2CDevice *parent, uint16_t a_register)
protected constructor that store the owning object and the register address.
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
Implementation of SPI Controller mode.
This class is used to create I2CRegister16 objects that act as proxies to read/write internal registe...
I2CRegister & operator &=(uint8_t value)
overloads the compound &= operator.
I2CDevice * parent_
I2CDevice object pointer.
I2CRegister & operator=(uint8_t value)
overloads the = operator.
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
bool write_byte_16(uint8_t a_register, uint16_t data)
void set_i2c_bus(I2CBus *bus)
we store the pointer to the I2CBus to use
This Class provides the methods to read/write bytes from/to an i2c device.
void set_i2c_address(uint8_t address)
We store the address of the device on the bus.
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len, bool stop=true)