1use core::{convert::Infallible, marker::PhantomData};
2use embedded_hal::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin};
3
4pub mod level {
6 #[non_exhaustive]
7 pub struct High;
9
10 #[non_exhaustive]
11 pub struct Low;
13}
14
15#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
21pub struct DummyPin<L = level::Low> {
22 _l: PhantomData<L>,
23}
24
25impl DummyPin<level::Low> {
26 pub fn new_low() -> Self {
30 DummyPin { _l: PhantomData }
31 }
32}
33
34impl DummyPin<level::High> {
35 pub fn new_high() -> Self {
39 DummyPin { _l: PhantomData }
40 }
41}
42
43impl<L> ErrorType for DummyPin<L> {
44 type Error = Infallible;
45}
46
47impl<L> OutputPin for DummyPin<L> {
48 fn set_high(&mut self) -> Result<(), Self::Error> {
49 Ok(())
50 }
51
52 fn set_low(&mut self) -> Result<(), Self::Error> {
53 Ok(())
54 }
55}
56
57impl InputPin for DummyPin<level::Low> {
58 fn is_high(&mut self) -> Result<bool, Self::Error> {
59 Ok(false)
60 }
61
62 fn is_low(&mut self) -> Result<bool, Self::Error> {
63 Ok(true)
64 }
65}
66
67impl InputPin for DummyPin<level::High> {
68 fn is_high(&mut self) -> Result<bool, Self::Error> {
69 Ok(true)
70 }
71
72 fn is_low(&mut self) -> Result<bool, Self::Error> {
73 Ok(false)
74 }
75}
76
77impl StatefulOutputPin for DummyPin<level::Low> {
78 fn is_set_high(&mut self) -> Result<bool, Self::Error> {
79 Ok(false)
80 }
81
82 fn is_set_low(&mut self) -> Result<bool, Self::Error> {
83 Ok(true)
84 }
85}
86
87impl StatefulOutputPin for DummyPin<level::High> {
88 fn is_set_high(&mut self) -> Result<bool, Self::Error> {
89 Ok(true)
90 }
91
92 fn is_set_low(&mut self) -> Result<bool, Self::Error> {
93 Ok(false)
94 }
95}