17 uint8_t *
get(
size_t size) {
18 if (size <= STACK_SIZE) {
19 return this->stack_buffer_;
21 this->heap_buffer_ = std::unique_ptr<uint8_t[]>(
new uint8_t[size]);
22 return this->heap_buffer_.get();
26 uint8_t stack_buffer_[STACK_SIZE];
27 std::unique_ptr<uint8_t[]> heap_buffer_;
75 size_t read_count) = 0;
87 ESPDEPRECATED(
"This method is deprecated and will be removed in ESPHome 2026.3.0. Use write_readv() instead.",
91 for (
size_t i = 0; i !=
count; i++) {
102 for (
size_t i = 0; i !=
count; i++) {
111 ESPDEPRECATED(
"This method is deprecated and will be removed in ESPHome 2026.3.0. Use write_readv() instead.",
114 size_t total_len = 0;
115 for (
size_t i = 0; i !=
count; i++) {
123 for (
size_t i = 0; i !=
count; i++) {
This Class provides the methods to read and write bytes from an I2CBus.
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...
bool scan_
Should we scan ? Can be set in the yaml.
std::vector< std::pair< uint8_t, bool > > scan_results_
array containing scan results
virtual ~I2CBus()=default
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
ReadBuffer * read_buffers
const WriteBuffer size_t bool stop
SmallBufferWithHeapFallback< 128 > buffer_alloc
const WriteBuffer * write_buffers
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 writev(uint8_t address
ErrorCode read(uint8_t address, uint8_t *buffer, size_t len)
virtual int get_port() const =0
Returns the I2C port number.
Helper class for efficient buffer allocation - uses stack for small sizes, heap for large.
uint8_t * get(size_t size)
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
@ ERROR_CRC
bytes received with a CRC error
@ ERROR_OK
No error found during execution of method.
@ ERROR_TOO_LARGE
requested a transfer larger than buffers can hold
@ ERROR_INVALID_ARGUMENT
method called invalid argument(s)
@ NO_ERROR
No error found during execution of method.
@ ERROR_TIMEOUT
timeout while waiting to receive bytes
@ ERROR_NOT_ACKNOWLEDGED
I2C bus acknowledgment not received.
@ ERROR_NOT_INITIALIZED
call method to a not initialized bus
@ ERROR_UNKNOWN
miscellaneous I2C error during execution
Providing packet encoding functions for exchanging data with a remote host.
the ReadBuffer structure stores a pointer to a read buffer and its length
size_t len
length of the buffer
uint8_t * data
pointer to the read buffer
the WriteBuffer structure stores a pointer to a write buffer and its length
size_t len
length of the buffer
const uint8_t * data
pointer to the write buffer