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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
use core::pin;
use core::task;
pub mod get;
pub mod set;
pub trait Pin {
type Error;
}
pub trait InputPin: Pin {
fn poll_get(
self: pin::Pin<&mut Self>,
cx: &mut task::Context<'_>,
) -> task::Poll<Result<bool, Self::Error>>;
}
pub trait InputPinExt: InputPin {
fn get(&mut self) -> get::Get<Self>
where
Self: Unpin,
{
get::get(self)
}
}
impl<A> InputPinExt for A where A: InputPin {}
pub trait OutputPin: Pin {
fn poll_set(
self: pin::Pin<&mut Self>,
cx: &mut task::Context<'_>,
high: bool,
) -> task::Poll<Result<(), Self::Error>>;
}
pub trait OutputPinExt: OutputPin {
fn set(&mut self, high: bool) -> set::Set<Self>
where
Self: Unpin,
{
set::set(self, high)
}
}
impl<A> OutputPinExt for A where A: OutputPin {}
pub trait IntoFloatingInputPin: Pin {
type FloatingInputPin: InputPin<Error = Self::Error> + Unpin;
fn into_floating_input_pin(self) -> Result<Self::FloatingInputPin, Self::Error>;
}
pub trait IntoPullUpInputPin: Pin {
type PullUpInputPin: InputPin<Error = Self::Error> + Unpin;
fn into_pull_up_input_pin(self) -> Result<Self::PullUpInputPin, Self::Error>;
}
pub trait IntoPullDownInputPin: Pin {
type PullDownInputPin: InputPin<Error = Self::Error> + Unpin;
fn into_pull_down_input_pin(self) -> Result<Self::PullDownInputPin, Self::Error>;
}
pub trait IntoOpenDrainOutputPin: Pin {
type OpenDrainOutputPin: OutputPin<Error = Self::Error> + Unpin;
fn into_open_drain_output_pin(
self,
initial_high: bool,
) -> Result<Self::OpenDrainOutputPin, Self::Error>;
}
pub trait IntoPushPullOutputPin: Pin {
type PushPullOutputPin: OutputPin<Error = Self::Error> + Unpin;
fn into_push_pull_output_pin(
self,
initial_high: bool,
) -> Result<Self::PushPullOutputPin, Self::Error>;
}
#[derive(Clone, Copy, Debug)]
pub struct NoConnect(bool);
impl NoConnect {
pub fn new(value: bool) -> Self {
NoConnect(value)
}
}
impl Pin for NoConnect {
type Error = futures::never::Never;
}
impl InputPin for NoConnect {
fn poll_get(
self: pin::Pin<&mut Self>,
_cx: &mut task::Context<'_>,
) -> task::Poll<Result<bool, Self::Error>> {
task::Poll::Ready(Ok(false))
}
}
impl OutputPin for NoConnect {
fn poll_set(
self: pin::Pin<&mut Self>,
_cx: &mut task::Context<'_>,
_high: bool,
) -> task::Poll<Result<(), Self::Error>> {
task::Poll::Ready(Ok(()))
}
}
impl IntoFloatingInputPin for NoConnect {
type FloatingInputPin = Self;
fn into_floating_input_pin(self) -> Result<Self::FloatingInputPin, Self::Error> {
Ok(self)
}
}
impl IntoPullUpInputPin for NoConnect {
type PullUpInputPin = Self;
fn into_pull_up_input_pin(self) -> Result<Self::PullUpInputPin, Self::Error> {
Ok(self)
}
}
impl IntoPullDownInputPin for NoConnect {
type PullDownInputPin = Self;
fn into_pull_down_input_pin(self) -> Result<Self::PullDownInputPin, Self::Error> {
Ok(self)
}
}
impl IntoOpenDrainOutputPin for NoConnect {
type OpenDrainOutputPin = Self;
fn into_open_drain_output_pin(
self,
_initial_high: bool,
) -> Result<Self::OpenDrainOutputPin, Self::Error> {
Ok(self)
}
}
impl IntoPushPullOutputPin for NoConnect {
type PushPullOutputPin = Self;
fn into_push_pull_output_pin(
self,
_initial_high: bool,
) -> Result<Self::PushPullOutputPin, Self::Error> {
Ok(self)
}
}