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)

Functions

esp_err_t i2cdev_init()

Init I2Cdev lib.

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

Return

ESP_OK on success

esp_err_t i2cdev_done()

Finish work with I2CDev lib.

Uninstall i2c drivers

Return

ESP_OK on success

esp_err_t i2c_dev_create_mutex(i2c_dev_t *dev)

Create mutex for device descriptor.

Return

ESP_OK on success

Parameters
  • [out] dev: Device descriptor

esp_err_t i2c_dev_delete_mutex(i2c_dev_t *dev)

Delete mutex for device descriptor.

Return

ESP_OK on success

Parameters
  • [out] dev: Device descriptor

esp_err_t i2c_dev_take_mutex(i2c_dev_t *dev)

Take device mutex.

Return

ESP_OK on success

Parameters
  • [out] dev: Device descriptor

esp_err_t i2c_dev_give_mutex(i2c_dev_t *dev)

Give device mutex.

Return

ESP_OK on success

Parameters
  • [out] dev: Device descriptor

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.

Return

ESP_OK on success

Parameters
  • [in] dev: Device descriptor

  • [in] out_data: Pointer to data to send if non-null

  • [in] out_size: Size of data to send

  • [out] in_data: Pointer to input data buffer

  • [in] in_size: Number of byte to read

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.

Return

ESP_OK on success

Parameters
  • [in] dev: Device descriptor

  • [in] out_reg: Pointer to register address to send if non-null

  • [in] out_reg_size: Size of register address

  • [in] out_data: Pointer to data to send

  • [in] out_size: Size of data to send

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().

Return

ESP_OK on success

Parameters
  • [in] dev: Device descriptor

  • [in] reg: Register address

  • [out] in_data: Pointer to input data buffer

  • [in] in_size: Number of byte to read

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().

Return

ESP_OK on success

Parameters
  • [in] dev: Device descriptor

  • [in] reg: Register address

  • [in] out_data: Pointer to data to send

  • [in] out_size: Size of data to send

struct i2c_dev_t
#include <i2cdev.h>

I2C device descriptor.