PL::I2CController class

class I2CController : public PL::Lockable

I2C controller class.

Public Functions

I2CController(std::shared_ptr<I2C> i2c, uint8_t targetAddress, uint32_t sclFrequency)

Creates an I2C controller.

Parameters:
  • i2cI2C interface

  • targetAddress – target address

  • sclFrequency – SCL frequency in Hz

virtual esp_err_t Lock(TickType_t timeout = portMAX_DELAY) override

Locks the object.

Parameters:

timeout – timeout in FreeRTOS ticks

Returns:

error code

virtual esp_err_t Unlock() override

Unlocks the object.

Returns:

error code

esp_err_t Initialize()

Initializes the controller.

Returns:

error code

esp_err_t Read(void *dest, size_t size)

Reads the data from the I2C target.

Parameters:
  • dest – destination

  • size – number of bytes to read

Returns:

error code

esp_err_t Write(const void *src, size_t size)

Writes the data to the I2C target.

Parameters:
  • src – source

  • size – number of bytes to write

Returns:

error code

int GetTimeout()

Gets the operation timeout.

Returns:

timeout in ms

esp_err_t SetTimeout(int timeout)

Sets the operation timeout.

Parameters:

timeout – timeout in ms

Returns:

error code

Public Static Attributes

static const int defaultTimeout = 1

Default operation timeout in ms.