21 lines
535 B
Rust
21 lines
535 B
Rust
// src/bus/mod.rs
|
|
|
|
use core::cell::RefCell;
|
|
use embedded_hal_bus::i2c::RefCellDevice;
|
|
use esp_hal::i2c::master::I2c;
|
|
use esp_hal::Async;
|
|
|
|
/// The underlying I2C peripheral type
|
|
pub type I2cInner = I2c<'static, Async>;
|
|
|
|
/// RefCell to share the bus on a single core.
|
|
pub type SharedI2c = RefCell<I2cInner>;
|
|
|
|
/// A handle to a shared I2C device.
|
|
pub type I2cDevice = RefCellDevice<'static, I2cInner>;
|
|
|
|
/// New I2C device handle from the shared bus.
|
|
pub fn new_device(bus: &'static SharedI2c) -> I2cDevice {
|
|
RefCellDevice::new(bus)
|
|
}
|