pw_i2c#

Cross-platform I2C API with interactive debugging

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();
cc_library(
  # ...
  deps = [
    # ...
    "@pigweed//pw_i2c:address",
    "@pigweed//pw_i2c:device",
    # ...
  ] + select({
    "@platforms//os:freertos": [
      "@pigweed//pw_i2c_rp2040:initiator",
    ],
    "//conditions:default": [
      # Fake example of a custom implementation.
      "//lib/pw_i2c_my_device:initiator",
    ],
  }),
)

pw_i2c provides C++ libraries and helpers for interacting with I2C devices.

Quickstart

How to set up pw_i2c in your build system and interact with an I2C device via the C++ API.

Guides

How to mock up I2C transactions, configure and read from a device’s register, communicate with an I2C device over RPC, and more.

Reference

API references for pw::i2c::Initiator, pw::i2c::Address, pw::i2c::Device, and more.

Implementations

A summary of the existing pw_i2c implementations and a guide on how to create your own.