Crate shared_bus

source ·
Expand description

shared-bus

shared-bus is a crate to allow sharing bus peripherals safely between multiple devices.

To do so, shared-bus needs a mutex. Because each platform has its own mutex type, shared-bus uses an abstraction: BusMutex. This type needs to be implemented for your platforms mutex type to allow using this crate.

  • If std is available, activate the std feature to enable the implementation of BusMutex for std::sync::Mutex.
  • If you platform is based on cortex-m, you can activate the cortexm feature to enable the implementation of BusMutex for [cortex_m::interrupt::Mutex]
  • If neither is the case, take a look at the documentation of BusMutex for hints on how to implement it yourself.

Typical usage of this crate might look like this:

extern crate shared_bus;

// Create your bus peripheral as usual:
// let i2c = I2c::i2c1(dp.I2C1, (scl, sda), 90.khz(), clocks, &mut rcc.apb1);

let manager = shared_bus::BusManager::<std::sync::Mutex<_>, _>::new(i2c);

// You can now acquire bus handles:
let mut handle = manager.acquire();
// handle implements `i2c::{Read, Write, WriteRead}`, depending on the
// implementations of the underlying peripheral
let mut mydevice = MyDevice::new(manager.acquire());

Re-exports

pub use mutex::BusMutex;
pub use proxy::BusManager;
pub use proxy::BusProxy;

Modules

Type Definitions

Type alias for a bus manager using [cortex_m::interrupt::Mutex].
Type alias for a bus manager using std::sync::Mutex.