10static const char *
const TAG =
"i2c";
12void I2CBus::i2c_scan_() {
14#if defined(USE_ESP32) && defined(USE_LOGGER)
15 auto previous = esp_log_level_get(
"*");
16 esp_log_level_set(
"*", ESP_LOG_NONE);
27#if defined(USE_ESP32) && defined(USE_LOGGER)
28 esp_log_level_set(
"*", previous);
42 std::vector<uint8_t> v{};
43 v.push_back(a_register);
49 std::vector<uint8_t> v(
len + 2);
50 v.push_back(a_register >> 8);
51 v.push_back(a_register);
59 for (
size_t i = 0; i <
len; i++)
66 std::unique_ptr<uint16_t[]> temp{
new uint16_t[
len]};
67 for (
size_t i = 0; i <
len; i++)
109 uint8_t value = 0x00;
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
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_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
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)
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
uint16_t htoi2cs(uint16_t hostshort)
Providing packet encoding functions for exchanging data with a remote host.
constexpr T convert_big_endian(T val)
Convert a value between host byte order and big endian (most significant byte first) order.