38#include <driver/i2c.h>
39#include <freertos/FreeRTOS.h>
40#include <freertos/semphr.h>
48#if HELPER_TARGET_IS_ESP8266
49#define I2CDEV_MAX_STRETCH_TIME 0xffffffff
51#include <soc/i2c_reg.h>
52#ifdef I2C_TIME_OUT_REG_V
53#define I2CDEV_MAX_STRETCH_TIME I2C_TIME_OUT_REG_V
55#define I2CDEV_MAX_STRETCH_TIME 0x00ffffff
59extern SemaphoreHandle_t
mutex;
149 size_t out_size,
void *in_data,
size_t in_size);
165 size_t out_reg_size,
const void *out_data,
size_t out_size);
179 void *in_data,
size_t in_size);
193 const void *out_data,
size_t out_size);
195#define I2C_DEV_TAKE_MUTEX(dev) do { \
196 esp_err_t __ = i2c_dev_take_mutex(dev); \
197 if (__ != ESP_OK) return __;\
200#define I2C_DEV_GIVE_MUTEX(dev) do { \
201 esp_err_t __ = i2c_dev_give_mutex(dev); \
202 if (__ != ESP_OK) return __;\
205#define I2C_DEV_CHECK(dev, X) do { \
207 if (___ != ESP_OK) { \
208 I2C_DEV_GIVE_MUTEX(dev); \
213#define I2C_DEV_CHECK_LOGE(dev, X, msg, ...) do { \
215 if (___ != ESP_OK) { \
216 I2C_DEV_GIVE_MUTEX(dev); \
217 ESP_LOGE(TAG, msg, ## __VA_ARGS__); \
esp_err_t i2c_dev_create_mutex(i2c_dev_t *dev)
Create mutex for device descriptor.
Definition: i2cdev.c:118
esp_err_t i2c_dev_delete_mutex(i2c_dev_t *dev)
Delete mutex for device descriptor.
Definition: i2cdev.c:136
esp_err_t i2c_dev_write(const i2c_dev_t *dev, const void *out_reg, size_t out_reg_size, const void *out_data, size_t out_size)
Write to slave device.
Definition: i2cdev.c:273
esp_err_t i2cdev_done()
Finish work with library.
Definition: i2cdev.c:97
esp_err_t i2c_dev_give_mutex(i2c_dev_t *dev)
Give device mutex.
Definition: i2cdev.c:164
esp_err_t i2cdev_init()
Init library.
Definition: i2cdev.c:74
esp_err_t i2c_dev_read(const i2c_dev_t *dev, const void *out_data, size_t out_size, void *in_data, size_t in_size)
Read from slave device.
Definition: i2cdev.c:241
esp_err_t i2c_dev_take_mutex(i2c_dev_t *dev)
Take device mutex.
Definition: i2cdev.c:148
esp_err_t i2c_dev_write_reg(const i2c_dev_t *dev, uint8_t reg, const void *out_data, size_t out_size)
Write to register with an 8-bit address.
Definition: i2cdev.c:305
esp_err_t i2c_dev_read_reg(const i2c_dev_t *dev, uint8_t reg, void *in_data, size_t in_size)
Read from register with an 8-bit address.
Definition: i2cdev.c:299
i2c_port_t port
I2C port number.
Definition: i2cdev.h:66
uint8_t addr
Unshifted address.
Definition: i2cdev.h:68
i2c_config_t cfg
I2C driver configuration.
Definition: i2cdev.h:67
uint32_t timeout_ticks
Definition: i2cdev.h:70
SemaphoreHandle_t mutex
Device mutex.
Definition: i2cdev.h:69