pw_i2c_rp2040#

Raspberry Pi Pico SDK implementation for pw_i2c

Stable C++17

#include "pw_i2c_rp2040/initiator.h"

#include "hardware/i2c.h"

constexpr pw::i2c::Rp2040Initiator::Config ki2cConfig{
  .clock_frequency = 400'000,
  .sda_pin = 8,
  .scl_pin = 9,
};

 pw::i2c::Rp2040Initiator i2c_bus(ki2cConfig, i2c0);
 // Calls these Pico SDK functions:
 // * gpio_set_function(8, GPIO_FUNC_I2C)
 // * gpio_set_function(9, GPIO_FUNC_I2C)
 i2c_bus.Enable();

pw_i2c_rp2040 implements the pw_i2c interface using the Raspberry Pi Pico SDK.

The implementation is based on the I2C driver in the Pico SDK. I2C transfers use the blocking driver API which uses busy waiting under the hood.

Implementation notes#

The Enable() function calls gpio_set_function from the Pico SDK.

Under the hood this implementation uses the following Pico SDK functions which only allow specifying timeouts in microseconds:

One additional microsecond is added to each timeout value to ensure reads and writes wait at least the full duration. Ideally a single clock tick would be added but that is not currently possible with the Pico SDK APIs.