1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use core::{convert::Infallible, marker::PhantomData};
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
pub mod level {
pub struct High;
pub struct Low;
}
#[derive(Debug, Clone, Copy)]
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> OutputPin for DummyPin<L> {
type Error = Infallible;
fn set_high(&mut self) -> Result<(), Self::Error> {
Ok(())
}
fn set_low(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}
impl InputPin for DummyPin<level::Low> {
type Error = Infallible;
fn is_high(&self) -> Result<bool, Self::Error> {
Ok(false)
}
fn is_low(&self) -> Result<bool, Self::Error> {
Ok(true)
}
}
impl InputPin for DummyPin<level::High> {
type Error = Infallible;
fn is_high(&self) -> Result<bool, Self::Error> {
Ok(true)
}
fn is_low(&self) -> Result<bool, Self::Error> {
Ok(false)
}
}
impl<L> ToggleableOutputPin for DummyPin<L> {
type Error = Infallible;
fn toggle(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}
impl StatefulOutputPin for DummyPin<level::Low> {
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(false)
}
fn is_set_low(&self) -> Result<bool, Self::Error> {
Ok(true)
}
}
impl StatefulOutputPin for DummyPin<level::High> {
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(true)
}
fn is_set_low(&self) -> Result<bool, Self::Error> {
Ok(false)
}
}