This Class provides the methods to read and write bytes from an I2CBus.
More...
#include <i2c_bus.h>
|
virtual | ~I2CBus ()=default |
|
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 ReadBuffer.
|
|
ErrorCode | read (uint8_t address, uint8_t *buffer, size_t len) |
|
ErrorCode | write (uint8_t address, const uint8_t *buffer, size_t len, bool stop=true) |
|
| ESPDEPRECATED ("This method is deprecated and will be removed in ESPHome 2026.3.0. Use write_readv() instead.", "2025.9.0") ErrorCode readv(uint8_t address |
|
| for (size_t i=0;i !=count;i++) |
|
| if (err !=ERROR_OK) return err |
|
| for (size_t i=0;i !=count;i++) |
|
| ESPDEPRECATED ("This method is deprecated and will be removed in ESPHome 2026.3.0. Use write_readv() instead.", "2025.9.0") ErrorCode writev(uint8_t address |
|
This Class provides the methods to read and write bytes from an I2CBus.
- Note
- The I2CBus virtual class follows a Factory design pattern that provides all the interfaces methods required by clients while deferring the actual implementation of these methods to a subclasses. I2C-bus specification and user manual can be found here https://www.nxp.com/docs/en/user-guide/UM10204.pdf and an interesting I²C Application note https://www.nxp.com/docs/en/application-note/AN10216.pdf
Definition at line 60 of file i2c_bus.h.
◆ ~I2CBus()
virtual esphome::i2c::I2CBus::~I2CBus |
( |
| ) |
|
|
virtualdefault |
◆ ESPDEPRECATED() [1/2]
esphome::i2c::I2CBus::ESPDEPRECATED |
( |
"This method is deprecated and will be removed in ESPHome 2026.3.0. Use write_readv() instead." | , |
|
|
"2025.9.0" | ) |
◆ ESPDEPRECATED() [2/2]
esphome::i2c::I2CBus::ESPDEPRECATED |
( |
"This method is deprecated and will be removed in ESPHome 2026.3.0. Use write_readv() instead." | , |
|
|
"2025.9.0" | ) |
◆ for() [1/2]
esphome::i2c::I2CBus::for |
( |
size_t | i = 0; i != count; i++ | ) |
|
|
inline |
◆ for() [2/2]
esphome::i2c::I2CBus::for |
( |
size_t | i = 0; i != count; i++ | ) |
|
|
inline |
◆ if()
◆ read()
ErrorCode esphome::i2c::I2CBus::read |
( |
uint8_t | address, |
|
|
uint8_t * | buffer, |
|
|
size_t | len ) |
|
inline |
◆ write()
ErrorCode esphome::i2c::I2CBus::write |
( |
uint8_t | address, |
|
|
const uint8_t * | buffer, |
|
|
size_t | len, |
|
|
bool | stop = true ) |
|
inline |
◆ write_readv()
virtual ErrorCode esphome::i2c::I2CBus::write_readv |
( |
uint8_t | address, |
|
|
const uint8_t * | write_buffer, |
|
|
size_t | write_count, |
|
|
uint8_t * | read_buffer, |
|
|
size_t | read_count ) |
|
pure virtual |
This virtual method writes bytes to an I2CBus from an array, then reads bytes into an array of ReadBuffer.
- Parameters
-
address | address of the I²C device on the i2c bus |
write_buffer | pointer to data |
write_count | number of bytes to write |
read_buffer | pointer to an array to receive data |
read_count | number of bytes to read transmission. False will send a restart, keeping the connection active. |
- Returns
- an i2c::ErrorCode
This is a pure virtual method that must be implemented in the subclass.
Implemented in esphome::i2c::ArduinoI2CBus, esphome::i2c::IDFI2CBus, and esphome::tca9548a::TCA9548AChannel.
◆ buffer
uint8_t* esphome::i2c::I2CBus::buffer = buffer_alloc.get(total_len) |
◆ buffer_alloc
◆ count [1/2]
Initial value:
Definition at line 89 of file i2c_bus.h.
◆ count [2/2]
◆ err
◆ ERROR_OK
return esphome::i2c::I2CBus::ERROR_OK |
◆ pos
size_t esphome::i2c::I2CBus::pos = 0 |
◆ read_buffers
◆ scan_
bool esphome::i2c::I2CBus::scan_ {false} |
Should we scan ? Can be set in the yaml.
Definition at line 136 of file i2c_bus.h.
◆ scan_results_
std::vector<std::pair<uint8_t, bool> > esphome::i2c::I2CBus::scan_results_ |
array containing scan results
Definition at line 135 of file i2c_bus.h.
◆ stop
const WriteBuffer size_t bool esphome::i2c::I2CBus::stop |
Initial value:= true) {
size_t total_len = 0;
for (
size_t i = 0; i !=
count; i++) {
}
for (
size_t i = 0; i !=
count; i++) {
}
}
protected:
void i2c_scan_()
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...
SmallBufferWithHeapFallback< 128 > buffer_alloc
const WriteBuffer * write_buffers
Helper class for efficient buffer allocation - uses stack for small sizes, heap for large.
uint8_t * get(size_t size)
size_t len
length of the buffer
Definition at line 113 of file i2c_bus.h.
◆ write_buffers
The documentation for this class was generated from the following file: