inverted_pin/lib.rs
1//! This provides implementations of the input/output pin [`embedded-hal`] traits with inverted logic.
2//!
3//! For example, an `InvertedPin` can wrap an `OutputPin` and when setting it low, it will set the
4//! wrapped `OutputPin` high. It works similarly for an `InputPin` as well.
5//!
6//! This is useful when dealing with pins that use a logic that is inverted with respect to what
7//! the rest of the system expects.
8//!
9//! Since an `InvertedPin` implements the `OutputPin` and `InputPin` traits as well, it can be used
10//! just like any other `OutputPin` or `InputPin` and serves as a drop-in replacement of the wrapped pin.
11//!
12//! [`embedded-hal`]: https://github.com/rust-embedded/embedded-hal
13//!
14//! ## Usage examples
15//!
16//! ### Output `InvertedPin` interaction
17//!
18//! ```no_run
19//! # use embedded_hal::digital::OutputPin;
20//! use linux_embedded_hal::SysfsPin;
21//! use inverted_pin::InvertedPin;
22//!
23//! let pin = SysfsPin::new(25);
24//! let mut inverted_pin = InvertedPin::new(pin);
25//!
26//! // This calls `pin.set_low()`
27//! inverted_pin.set_high().unwrap();
28//! ```
29//!
30//! ### Input `InvertedPin` interaction
31//!
32//! ```no_run
33//! # use embedded_hal::digital::InputPin;
34//! use linux_embedded_hal::SysfsPin;
35//! use inverted_pin::InvertedPin;
36//!
37//! let pin = SysfsPin::new(25);
38//! let mut inverted_pin = InvertedPin::new(pin);
39//!
40//! // This returns the result of calling `pin.is_low()`
41//! inverted_pin.is_high().unwrap();
42//! ```
43
44#![deny(unsafe_code, missing_docs)]
45#![no_std]
46
47mod inverted;
48pub use crate::inverted::InvertedPin;