4#include <zephyr/drivers/i2c.h>
11static const char *get_speed(
uint32_t dev_config) {
12 switch (I2C_SPEED_GET(dev_config)) {
13 case I2C_SPEED_STANDARD:
17 case I2C_SPEED_FAST_PLUS:
28 if (!device_is_ready(this->
i2c_dev_)) {
29 ESP_LOGE(TAG,
"I2C dev is not ready.");
36 ESP_LOGE(TAG,
"I2C: Failed to configure device");
44 ESP_LOGV(TAG,
"Scanning I2C bus for active devices...");
61 ESP_LOGCONFIG(TAG,
" Recovery: bus successfully recovered");
67 uint8_t *read_buffer,
size_t read_count) {
68 if (!device_is_ready(this->
i2c_dev_)) {
76 if (read_count == 0 && write_count == 0) {
79 msgs[cnt++].flags = I2C_MSG_WRITE;
83 msgs[cnt].buf =
const_cast<uint8_t *
>(write_buffer);
84 msgs[cnt].len = write_count;
85 msgs[cnt++].flags = I2C_MSG_WRITE;
88 msgs[cnt].buf =
const_cast<uint8_t *
>(read_buffer);
89 msgs[cnt].len = read_count;
90 msgs[cnt++].flags = I2C_MSG_READ | I2C_MSG_RESTART;
94 msgs[cnt - 1].flags |= I2C_MSG_STOP;
103 ESP_LOGE(TAG,
"i2c transfer error %d", err);
112 return (dev_config & ~I2C_SPEED_MASK) | I2C_SPEED_SET(speed);
116#ifdef I2C_PORT_FREQUENCY_COUNT
122#ifdef I2C_PORT_FREQUENCY_COUNT
void mark_failed()
Mark this component as failed.
bool scan_
Should we scan ? Can be set in the yaml.
void dump_scan_results_()
Logs the scan results at config level, if the bus was scanned.
void i2c_scan_()
Scans the I2C bus for devices.
void dump_config() override
void set_frequency(uint32_t frequency)
ErrorCode switch_frequency(uint32_t frequency) override
ErrorCode write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count, uint8_t *read_buffer, size_t read_count) override
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
@ ERROR_OK
No error found during execution of method.
@ 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
ESPHOME_LOG_TAG(TAG, "i2c")