i2cdev - I2C master thread-safe functions for communication with I2C slave

group i2cdev

ESP-IDF I2C master thread-safe functions for communication with I2C slave.

Copyright (C) 2018 Ruslan V. Uss https://github.com/UncleRus

MIT Licensed as described in the file LICENSE

Defines

I2CDEV_MAX_STRETCH_TIME
I2C_DEV_TAKE_MUTEX(dev)
I2C_DEV_GIVE_MUTEX(dev)
I2C_DEV_CHECK(dev, X)
I2C_DEV_CHECK_LOGE(dev, X, msg, ...)

Functions

esp_err_t i2cdev_init()

Init library.

The function must be called before any other functions of this library.

Returns

ESP_OK on success

esp_err_t i2cdev_done()

Finish work with library.

Uninstall i2c drivers.

Returns

ESP_OK on success

esp_err_t i2c_dev_create_mutex(i2c_dev_t *dev)

Create mutex for device descriptor.

Parameters

dev – Device descriptor

Returns

ESP_OK on success

esp_err_t i2c_dev_delete_mutex(i2c_dev_t *dev)

Delete mutex for device descriptor.

Parameters

dev – Device descriptor

Returns

ESP_OK on success

esp_err_t i2c_dev_take_mutex(i2c_dev_t *dev)

Take device mutex.

Parameters

dev – Device descriptor

Returns

ESP_OK on success

esp_err_t i2c_dev_give_mutex(i2c_dev_t *dev)

Give device mutex.

Parameters

dev – Device descriptor

Returns

ESP_OK on success

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.

Issue a send operation of out_data register address, followed by reading in_size bytes from slave into in_data . Function is thread-safe.

Parameters
  • dev – Device descriptor

  • out_data – Pointer to data to send if non-null

  • out_size – Size of data to send

  • [out] in_data – Pointer to input data buffer

  • in_size – Number of byte to read

Returns

ESP_OK on success

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.

Write out_size bytes from out_data to slave into out_reg register address. Function is thread-safe.

Parameters
  • dev – Device descriptor

  • out_reg – Pointer to register address to send if non-null

  • out_reg_size – Size of register address

  • out_data – Pointer to data to send

  • out_size – Size of data to send

Returns

ESP_OK on success

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.

Shortcut to i2c_dev_read().

Parameters
  • dev – Device descriptor

  • reg – Register address

  • [out] in_data – Pointer to input data buffer

  • in_size – Number of byte to read

Returns

ESP_OK on success

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.

Shortcut to i2c_dev_write().

Parameters
  • dev – Device descriptor

  • reg – Register address

  • out_data – Pointer to data to send

  • out_size – Size of data to send

Returns

ESP_OK on success

struct i2c_dev_t
#include <i2cdev.h>

I2C device descriptor.