shared-bus

shared-bus is a crate to allow sharing bus peripherals safely between multiple devices.
Typical usage of this crate might look like this:
extern crate shared_bus;
// Create your bus peripheral as usual:
let i2c = i2c1;
let manager = new;
// 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 = new;
Mutex Implementation
To do its job, 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
stdis available, activate thestdfeature to enable the implementation ofBusMutexforstd::sync::Mutex. - If your device used
cortex-m, activate thecortexmfeature to enable the implementation ofBusMutexforcortex_m::interrupt::Mutex. - If neither is the case, you need to implement a mutex yourself:
extern crate shared_bus;
extern crate cortex_m;
// You need a newtype because you can't implement foreign traits on
// foreign types.
;
type MyBusManager<L, P> = BusManager;
I am welcoming patches containing mutex implementations for other platforms!
License
shared-bus is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.