Module imxrt_hal::lpi2c

source ·
Expand description

Low-power inter-integrated circuit.

The Lpi2c driver implements all embedded-hal I2C traits. Use these traits to perform common I2C I/O. The driver also exposes lower-level APIs for the LPI2C controller.

Example

Demonstrates how to create an LPI2C peripheral, and perform a write-read with a device. This example skips the LPI2C clock configuration. To understand LPI2C clock configuration, see the ccm::lpi2c_clk documentation.

use imxrt_hal as hal;
use imxrt_ral as ral;
use hal::lpi2c::{self, Lpi2c};
use ral::{ccm::CCM, lpi2c::LPI2C3};
use eh02::blocking::i2c::WriteRead;

let mut pads = // Handle to all processor pads...

let mut ccm = unsafe { CCM::instance() };
let mut i2c3 = unsafe { LPI2C3::instance() };

const LPI2C_400KHz: lpi2c::Timing = lpi2c::Timing::ideal(LPI2C_CLK_HZ, lpi2c::ClockSpeed::KHz400);

let mut i2c3 = Lpi2c::new(
    i2c3,
    lpi2c::Pins {
        scl: pads.gpio_ad_b1.p07,
        sda: pads.gpio_ad_b1.p06,
    },
    &LPI2C_400KHz,
);

let mut input = [0; 3];
let output = [0x74];

i2c3.write_read(MY_DEVICE_ADDRESS, &output, &mut input).ok()?;

// Release the driver components...
let (i2c3, pins) = i2c3.release();

// Re-construct without pins...
let mut i2c3 = Lpi2c::without_pins(i2c3, &LPI2C_400KHz);

Limitations

This driver supports standard, fast, and fast+ modes. High speed mode is not yet supported, and supporting the mode was not considered in the initial driver design.

Structs

Enums