Module embassy_embedded_hal::shared_bus::asynch::i2c
source · Expand description
Asynchronous shared I2C bus
§Example (nrf52)
ⓘ
use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice;
use embassy_sync::mutex::Mutex;
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
static I2C_BUS: StaticCell<Mutex<NoopRawMutex, Twim<TWISPI0>>> = StaticCell::new();
let config = twim::Config::default();
let i2c = Twim::new(p.TWISPI0, Irqs, p.P0_03, p.P0_04, config);
let i2c_bus = Mutex::new(i2c);
let i2c_bus = I2C_BUS.init(i2c_bus);
// Device 1, using embedded-hal-async compatible driver for QMC5883L compass
let i2c_dev1 = I2cDevice::new(i2c_bus);
let compass = QMC5883L::new(i2c_dev1).await.unwrap();
// Device 2, using embedded-hal-async compatible driver for Mpu6050 accelerometer
let i2c_dev2 = I2cDevice::new(i2c_bus);
let mpu = Mpu6050::new(i2c_dev2);
Structs§
- I2C device on a shared bus.
- I2C device on a shared bus, with its own configuration.