This provides implementations of the input/output pin [embedded-hal
] traits with inverted logic.
For example, an InvertedOutputPin
wraps an OutputPin
and when setting it low, it will set the
wrapped OutputPin
high.
This is useful when dealing with pins that use a logic that is inverted with respect to what the rest of the system expects.
This example demonstrates how the same driver can operate with either a normal or an inverted output pin.
```rust use embeddedhal::digital::v2::OutputPin; use invertedpin::InvertedOutputPin; use linuxembeddedhal::Pin;
struct Driver
{ output: P, }
impl
Driver
where
P: OutputPin
fn do_something(&mut self) -> Result<(), E> {
// ...
self.output.set_high()
}
fn destroy(self) -> P {
self.output
}
}
fn main() { // The same driver can operate with either a normal or an inverted pin. let realpin = Pin::new(25); let mut driverwithrealpin = Driver::new(realpin); driverwithrealpin.dosomething().unwrap(); let realpin = driverwithreal_pin.destroy();
let inverted_pin = InvertedOutputPin::new(real_pin);
let mut driver_with_inverted_pin = Driver::new(inverted_pin);
driver_with_inverted_pin.do_something().unwrap();
} ```
For questions, issues, feature requests, and other changes, please file an issue in the github project.
This crate is guaranteed to compile on stable Rust 1.35 and up. It might compile with older versions but that may change in any new patch release.
Licensed under either of
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.