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
202
use core::marker::PhantomData;
pub trait IsUnlocked {}
pub trait InputMode {}
pub trait OutputMode {}
pub trait OpenDrainMode {
fn pup() -> bool;
}
pub trait AlternateFunctionChoice {
fn number() -> u32;
}
pub struct Input<MODE>
where
MODE: InputMode,
{
_mode: PhantomData<MODE>,
}
impl<MODE> IsUnlocked for Input<MODE> where MODE: InputMode {}
pub struct Floating;
impl InputMode for Floating {}
impl OpenDrainMode for Floating {
fn pup() -> bool {
false
}
}
pub struct PullDown;
impl InputMode for PullDown {}
pub struct PullUp;
impl InputMode for PullUp {}
impl OpenDrainMode for PullUp {
fn pup() -> bool {
true
}
}
pub struct Tristate;
impl IsUnlocked for Tristate {}
pub struct Output<MODE>
where
MODE: OutputMode,
{
_mode: PhantomData<MODE>,
}
impl<MODE> IsUnlocked for Output<MODE> where MODE: OutputMode {}
pub struct AlternateFunction<AF, MODE>
where
AF: AlternateFunctionChoice,
MODE: OutputMode,
{
_func: PhantomData<AF>,
_mode: PhantomData<MODE>,
}
impl<AF, MODE> IsUnlocked for AlternateFunction<AF, MODE>
where
AF: AlternateFunctionChoice,
MODE: OutputMode,
{
}
pub struct PushPull;
impl OutputMode for PushPull {}
pub struct OpenDrain<ODM>
where
ODM: OpenDrainMode,
{
_pull: PhantomData<ODM>,
}
impl<ODM> OutputMode for OpenDrain<ODM> where ODM: OpenDrainMode {}
pub struct AF1;
impl AlternateFunctionChoice for AF1 {
fn number() -> u32 {
1
}
}
pub struct AF2;
impl AlternateFunctionChoice for AF2 {
fn number() -> u32 {
2
}
}
pub struct AF3;
impl AlternateFunctionChoice for AF3 {
fn number() -> u32 {
3
}
}
pub struct AF4;
impl AlternateFunctionChoice for AF4 {
fn number() -> u32 {
4
}
}
pub struct AF5;
impl AlternateFunctionChoice for AF5 {
fn number() -> u32 {
5
}
}
pub struct AF6;
impl AlternateFunctionChoice for AF6 {
fn number() -> u32 {
6
}
}
pub struct AF7;
impl AlternateFunctionChoice for AF7 {
fn number() -> u32 {
7
}
}
pub struct AF8;
impl AlternateFunctionChoice for AF8 {
fn number() -> u32 {
8
}
}
pub struct AF9;
impl AlternateFunctionChoice for AF9 {
fn number() -> u32 {
9
}
}
pub struct AF14;
impl AlternateFunctionChoice for AF14 {
fn number() -> u32 {
14
}
}
pub struct Locked;
pub enum InterruptMode {
LevelLow,
LevelHigh,
EdgeRising,
EdgeFalling,
EdgeBoth,
Disabled,
}