unstable only.Expand description
§Low-power I2C driver
§Overview
This is the host driver for the LP_I2C peripheral, which is primarily meant to be driven by the ULP.
The driver always sends a slave sub-register address along with the device address. This makes
it incompatible with I2C devices or sensors that do not expose sub-registers, and it also means
an embedded_hal::i2c::I2c implementation cannot be provided.
§Configuration
The driver can be configured using the Config struct. To create a
configuration, you can use the Config::default() method, and then modify
the individual settings as needed, by calling with_* methods on the
Config struct.
use esp_hal::i2c::lp_i2c::Config;
let config = Config::default();You will then need to pass the configuration to LpI2c::new, and you can
also change the configuration later by calling LpI2c::apply_config.
You will also need to specify the SDA and SCL pins when you create the driver instance.
use esp_hal::i2c::lp_i2c::{Config, LpI2c};
let mut i2c = LpI2c::new(
peripherals.LP_I2C0,
config,
peripherals.GPIO2,
peripherals.GPIO3,
)?;
// You can change the configuration later:
i2c.apply_config(&Config::default())?;§Usage
// The device address does not contain the `R/W` bit!
const DEVICE_ADDR: u8 = 0x77;
const DEVICE_REG: u8 = 0x01;
let write_buffer = [0xAA];
let mut read_buffer = [0u8; 22];
i2c.write(DEVICE_ADDR, DEVICE_REG, &write_buffer)?;
i2c.read(DEVICE_ADDR, DEVICE_REG, &mut read_buffer)?;Structs§
Enums§
- Config
Error - I2C-specific configuration errors
- Error
- I2C-specific transmission errors