Crate embedded_hal_compat
source · [−]Expand description
A compatibility layer to alleviate (some) of the issues resolving from changes to embedded-hal.
This crate lets you easily mix and match drivers and hal implementations using v1.x.x
and v0.2.x
versions of embedded-hal, just add a .forward()
or a .reverse()
wherever you see trait bounds errors.
Note that no effort is made to support interoperability between alpha versions, we’ll do our best to keep
up with the latest alpha and swap to 1.0.0
on release. In the future these traits may be renamed to support more hal versions.
Forward compatibility:
Calling ForwardCompat::forward()
(or .forward()
) on v0.2.x
types creates a wrapper for use with v1.0.x
consumers, so you can drop these wrapped types into drivers expecting v1.0.x
types.
use embedded_hal_compat::ForwardCompat;
// Create e-h v0.2.x based type (mock)
let mut old = OutputPin0_2;
// Access via e-h v0.2.x methods
let _ = eh0_2::digital::v2::OutputPin::set_high(&mut old);
// Apply forward compatibility wrapper
let mut new = old.forward();
// Access via e-h v1.x.x methods
let _ = eh1_0::digital::blocking::OutputPin::set_high(&mut new);
Backwards compatibility:
Calling ReverseCompat::reverse()
(or .reverse()
) on v1.0.x
types creates a wrapper for use with v0.2.x
consumers, so you can drop these wrapped types into drivers expecting v0.2.x
types.
use embedded_hal_compat::ReverseCompat;
// Create e-h v1.x.x based type (mock)
let mut new = OutputPin1_0;
// Access via e-h v1.x.x methods
let _ = eh1_0::digital::blocking::OutputPin::set_high(&mut new);
// Apply backwards compatibility wrapper
let mut old = new.reverse();
// Access via e-h v0.2.x methods
let _ = eh0_2::digital::v2::OutputPin::set_high(&mut old);
Re-exports
Modules
Mock types for documentation, please ignore
Structs
Forward compatibility container object. This is generic over different E-H types and will provide adaption depending on the bound type.
Reverse compatibility container object. This is generic over different E-H types and will provide adaption depending on the bound type.
Traits
Helper trait to convert a type for forward compatibility
call .forward()
on e-h@0.2.x
types to create an e-h@1.x.x
compatible wrapper object
Convert a type into a forward compatibility wrapper object
call .reverse()
on e-h@1.0.x
types to create an e-h@0.2.x
compatible wrapper object