Bus sharing utilities for embedded-hal
, a Hardware Abstraction Layer (HAL) for embedded systems.
embedded-hal
provides traits for SPI and I2C buses and devices. This crate provides hardware-independent adapters for sharing a single bus between multiple devices, compatible with the traits.
This project is developed and maintained by the HAL team.
To support bus sharing, embedded-hal
provides the SpiBus
and SpiDevice
traits. SpiBus
represents an entire bus,
while SpiDevice
represents a device on that bus. For further details on these traits, please consult the
embedded-hal
documentation.
embedded-hal
trait implementations for microcontrollers should implement the SpiBus
trait.
However, device drivers should use the SpiDevice
traits, not the SpiBus
traits if at all possible
in order to allow for sharing of the bus they are connected to.
This crate provides mechanisms to connect a SpiBus
and a SpiDevice
.
In the case of I2C, the same I2c
embedded-hal
trait represents either an entire bus, or a device on a bus. This crate
provides mechanisms to obtain multiple I2c
instances out of a single I2c
instance, sharing the bus.
-
async
: enableembedded-hal-async
support. -
defmt-03
: Derivedefmt::Format
fromdefmt
0.3 for enums and structs. -
alloc
: enable implementations usingalloc
(for instance,spi::RcDevice
, which makes use ofalloc::rc::Rc
) -
portable-atomic
: Useportable-atomic
to enableatomic-device
on devices without native atomic CASportable-atomic
emulates atomic CAS functionality, allowingembedded-hal-bus
to useatomic-device
on hardware that does not natively support atomic CAS. If you enable this, you must also addportable-atomic
to your crate with a feature flag such asunsafe-assume-single-core
orcritical-section
to choose how atomic CAS is implemented. See https://docs.rs/portable-atomic/1.7.0/portable_atomic/#optional-features for more info. -
std
: enable shared bus implementations usingstd::sync::Mutex
.
This crate is guaranteed to compile on stable Rust 1.60 and up. It might compile with older versions but that may change in any new patch release.
See here for details on how the MSRV may be upgraded.
Enabling the async
Cargo features requires Rust 1.75 or higher.
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.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.