I2C Component

Installation

The component requires ESP-IDF 5.3 and higher and is installed using IDF Component Manager.

Add this to the idf_component.yml in the project main directory or in the component directory:

dependencies:
  plasmapper/pl_i2c: "^1.0.3"

Add this to the source code:

#include "pl_i2c.h"

Add extern "C" to the app_main function:

extern "C" void app_main(void) {...}

Add this to the sdkconfig.defaults in the project directory or configure the values using Project Configuration:

CONFIG_COMPILER_CXX_RTTI=y

Features

  1. PL::I2C - an I2C interface class that is used for several I2C controllers that use the same interface. PL::I2C::Initialize() initializes the I2C interface.

  2. PL::I2CController - an I2C controller class that is used for communication with a single I2C target. PL::I2CController::Initialize() initializes the I2C interface and the I2C controller. PL::I2CController::Read() performs an I2C read operation. PL::I2CController::Write() performs an I2C write operation. Operation timeout can be get and set using PL::I2CController::GetTimeout() and PL::I2CController::SetTimeout().

I2C target is not implemented yet.

Thread safety

Class method thread safety is implemented by having the PL::Lockable as a base class and creating the class object lock guard at the beginning of the methods.

PL::I2CController::Initialize(), :PL::I2CController::Read() and PL::I2CController::Write() lock both the PL::I2CController and the PL::I2C objects for the duration of the method.

Examples

API reference