This Class provides the methods to read and write bytes from an I2CBus.
More...
#include <i2c_bus.h>
|
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. More...
|
|
virtual ErrorCode | readv (uint8_t address, ReadBuffer *buffers, size_t count)=0 |
| This virtual method reads bytes from an I2CBus into an array of ReadBuffer. More...
|
|
virtual ErrorCode | write (uint8_t address, const uint8_t *buffer, size_t len) |
|
virtual ErrorCode | write (uint8_t address, const uint8_t *buffer, size_t len, bool stop) |
| Creates a WriteBuffer and calls the writev() method to send the bytes from this buffer. More...
|
|
virtual ErrorCode | writev (uint8_t address, WriteBuffer *buffers, size_t cnt) |
|
virtual ErrorCode | writev (uint8_t address, WriteBuffer *buffers, size_t count, bool stop)=0 |
| This virtual method writes bytes to an I2CBus from an array of WriteBuffer. More...
|
|
|
std::vector< std::pair< uint8_t, bool > > | scan_results_ |
| array containing scan results More...
|
|
bool | scan_ {false} |
| Should we scan ? Can be set in the yaml. More...
|
|
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 40 of file i2c_bus.h.
◆ i2c_scan_()
void esphome::i2c::I2CBus::i2c_scan_ |
( |
| ) |
|
|
inlineprotected |
Scans the I2C bus for devices.
Devices presence is kept in an array of std::pair that contains the address and the corresponding bool presence flag.
Definition at line 97 of file i2c_bus.h.
◆ read()
virtual ErrorCode esphome::i2c::I2CBus::read |
( |
uint8_t |
address, |
|
|
uint8_t * |
buffer, |
|
|
size_t |
len |
|
) |
| |
|
inlinevirtual |
Creates a ReadBuffer and calls the virtual readv() method to read bytes into this buffer.
- Parameters
-
address | address of the I²C component on the i2c bus |
buffer | pointer to an array of bytes that will be used to store the data received |
len | length of the buffer = number of bytes to read |
- Returns
- an i2c::ErrorCode
Definition at line 47 of file i2c_bus.h.
◆ readv()
virtual ErrorCode esphome::i2c::I2CBus::readv |
( |
uint8_t |
address, |
|
|
ReadBuffer * |
buffers, |
|
|
size_t |
count |
|
) |
| |
|
pure virtual |
◆ write() [1/2]
virtual ErrorCode esphome::i2c::I2CBus::write |
( |
uint8_t |
address, |
|
|
const uint8_t * |
buffer, |
|
|
size_t |
len |
|
) |
| |
|
inlinevirtual |
◆ write() [2/2]
virtual ErrorCode esphome::i2c::I2CBus::write |
( |
uint8_t |
address, |
|
|
const uint8_t * |
buffer, |
|
|
size_t |
len, |
|
|
bool |
stop |
|
) |
| |
|
inlinevirtual |
Creates a WriteBuffer and calls the writev() method to send the bytes from this buffer.
- Parameters
-
address | address of the I²C component on the i2c bus |
buffer | pointer to an array of bytes that contains the data to be sent |
len | length of the buffer = number of bytes to write |
stop | true or false: True will send a stop message, releasing the bus after transmission. False will send a restart, keeping the connection active. |
- Returns
- an i2c::ErrorCode
Definition at line 73 of file i2c_bus.h.
◆ writev() [1/2]
virtual ErrorCode esphome::i2c::I2CBus::writev |
( |
uint8_t |
address, |
|
|
WriteBuffer * |
buffers, |
|
|
size_t |
cnt |
|
) |
| |
|
inlinevirtual |
◆ writev() [2/2]
virtual ErrorCode esphome::i2c::I2CBus::writev |
( |
uint8_t |
address, |
|
|
WriteBuffer * |
buffers, |
|
|
size_t |
count, |
|
|
bool |
stop |
|
) |
| |
|
pure virtual |
◆ scan_
bool esphome::i2c::I2CBus::scan_ {false} |
|
protected |
Should we scan ? Can be set in the yaml.
Definition at line 108 of file i2c_bus.h.
◆ scan_results_
std::vector<std::pair<uint8_t, bool> > esphome::i2c::I2CBus::scan_results_ |
|
protected |
array containing scan results
Definition at line 107 of file i2c_bus.h.
The documentation for this class was generated from the following file:
- /opt/build/esphome/esphome/components/i2c/i2c_bus.h