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
use core::convert::Infallible;
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
#[derive(Debug, Clone, Copy)]
pub struct LastStateDummyPin {
is_high: bool,
}
impl LastStateDummyPin {
pub fn new(is_high: bool) -> Self {
LastStateDummyPin { is_high }
}
pub fn new_low() -> Self {
LastStateDummyPin { is_high: false }
}
pub fn new_high() -> Self {
LastStateDummyPin { is_high: true }
}
}
impl OutputPin for LastStateDummyPin {
type Error = Infallible;
fn set_high(&mut self) -> Result<(), Self::Error> {
self.is_high = true;
Ok(())
}
fn set_low(&mut self) -> Result<(), Self::Error> {
self.is_high = false;
Ok(())
}
}
impl InputPin for LastStateDummyPin {
type Error = Infallible;
fn is_high(&self) -> Result<bool, Self::Error> {
Ok(self.is_high)
}
fn is_low(&self) -> Result<bool, Self::Error> {
Ok(!self.is_high)
}
}
impl ToggleableOutputPin for LastStateDummyPin {
type Error = Infallible;
fn toggle(&mut self) -> Result<(), Self::Error> {
self.is_high = !self.is_high;
Ok(())
}
}
impl StatefulOutputPin for LastStateDummyPin {
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(self.is_high)
}
fn is_set_low(&self) -> Result<bool, Self::Error> {
Ok(!self.is_high)
}
}