use core::{convert::Infallible, marker::PhantomData};
use embedded_hal::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin};
pub mod level {
#[non_exhaustive]
pub struct High;
#[non_exhaustive]
pub struct Low;
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct DummyPin<L = level::Low> {
_l: PhantomData<L>,
}
impl DummyPin<level::Low> {
pub fn new_low() -> Self {
DummyPin { _l: PhantomData }
}
}
impl DummyPin<level::High> {
pub fn new_high() -> Self {
DummyPin { _l: PhantomData }
}
}
impl<L> ErrorType for DummyPin<L> {
type Error = Infallible;
}
impl<L> OutputPin for DummyPin<L> {
fn set_high(&mut self) -> Result<(), Self::Error> {
Ok(())
}
fn set_low(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}
impl InputPin for DummyPin<level::Low> {
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok(false)
}
fn is_low(&mut self) -> Result<bool, Self::Error> {
Ok(true)
}
}
impl InputPin for DummyPin<level::High> {
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok(true)
}
fn is_low(&mut self) -> Result<bool, Self::Error> {
Ok(false)
}
}
impl StatefulOutputPin for DummyPin<level::Low> {
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
Ok(false)
}
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
Ok(true)
}
}
impl StatefulOutputPin for DummyPin<level::High> {
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
Ok(true)
}
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
Ok(false)
}
}