stm32f4xx_hal/gpio/
alt.rs1mod f4;
2pub use f4::*;
3
4macro_rules! extipin {
5 ($( $(#[$attr:meta])* $PX:ident,)*) => {
6 fn make_interrupt_source(&mut self, _syscfg: &mut $crate::syscfg::SysCfg) {
7 match self {
8 $(
9 $(#[$attr])*
10 Self::$PX(p) => p.make_interrupt_source(_syscfg),
11 )*
12 _ => {},
13 }
14
15 }
16
17 fn trigger_on_edge(&mut self, _exti: &mut $crate::pac::EXTI, _level: $crate::gpio::Edge) {
18 match self {
19 $(
20 $(#[$attr])*
21 Self::$PX(p) => p.trigger_on_edge(_exti, _level),
22 )*
23 _ => {},
24 }
25 }
26
27 fn enable_interrupt(&mut self, _exti: &mut $crate::pac::EXTI) {
28 match self {
29 $(
30 $(#[$attr])*
31 Self::$PX(p) => p.enable_interrupt(_exti),
32 )*
33 _ => {},
34 }
35 }
36 fn disable_interrupt(&mut self, _exti: &mut $crate::pac::EXTI) {
37 match self {
38 $(
39 $(#[$attr])*
40 Self::$PX(p) => p.disable_interrupt(_exti),
41 )*
42 _ => {},
43 }
44 }
45 fn clear_interrupt_pending_bit(&mut self) {
46 match self {
47 $(
48 $(#[$attr])*
49 Self::$PX(p) => p.clear_interrupt_pending_bit(),
50 )*
51 _ => {},
52 }
53 }
54 fn check_interrupt(&self) -> bool {
55 match self {
56 $(
57 $(#[$attr])*
58 Self::$PX(p) => p.check_interrupt(),
59 )*
60 _ => false,
61 }
62 }
63 };
64}
65use extipin;
66
67macro_rules! pin {
68 ( $($(#[$docs:meta])* <$name:ident, $Otype:ident> for $(no: $NoPin:ident,)? [$(
69 $(#[$attr:meta])* $PX:ident<$A:literal $(, Speed::$Speed:ident)?>,
70 )*],)*) => {
71 $(
72 #[derive(Debug)]
73 $(#[$docs])*
74 pub enum $name {
75 $(
76 None($NoPin<$Otype>),
77 )?
78
79 $(
80 $(#[$attr])*
81 $PX(gpio::$PX<$crate::gpio::Alternate<$A, $Otype>>),
82 )*
83 }
84
85 impl crate::Sealed for $name { }
86
87 #[allow(unreachable_patterns)]
88 impl $crate::gpio::ReadPin for $name {
89 fn is_low(&self) -> bool {
90 match self {
91 $(
92 $(#[$attr])*
93 Self::$PX(p) => p.is_low(),
94 )*
95 _ => false,
96 }
97 }
98 }
99
100 #[allow(unreachable_patterns)]
101 impl $crate::gpio::PinSpeed for $name {
102 fn set_speed(&mut self, _speed: $crate::gpio::Speed) {
103 match self {
104 $(
105 $(#[$attr])*
106 Self::$PX(p) => p.set_speed(_speed),
107 )*
108 _ => {}
109 }
110 }
111 }
112
113 #[allow(unreachable_patterns)]
114 impl $crate::gpio::PinPull for $name {
115 fn set_internal_resistor(&mut self, _pull: $crate::gpio::Pull) {
116 match self {
117 $(
118 $(#[$attr])*
119 Self::$PX(p) => p.set_internal_resistor(_pull),
120 )*
121 _ => {}
122 }
123 }
124 }
125
126 #[allow(unreachable_patterns)]
127 impl $crate::gpio::ExtiPin for $name {
128 extipin! { $( $(#[$attr])* $PX, )* }
129 }
130
131 $(
132 impl From<$NoPin<$Otype>> for $name {
133 fn from(p: $NoPin<$Otype>) -> Self {
134 Self::None(p)
135 }
136 }
137 )?
138
139 $(
140 $(#[$attr])*
141 impl<MODE> From<gpio::$PX<MODE>> for $name
142 where
143 MODE: $crate::gpio::marker::NotAlt + $crate::gpio::PinMode
144 {
145 fn from(p: gpio::$PX<MODE>) -> Self {
146 Self::$PX(p.into_mode() $(.speed($crate::gpio::Speed::$Speed))?)
147 }
148 }
149
150 $(#[$attr])*
151 impl From<gpio::$PX<$crate::gpio::Alternate<$A, $Otype>>> for $name {
152 fn from(p: gpio::$PX<$crate::gpio::Alternate<$A, $Otype>>) -> Self {
153 Self::$PX(p $(.speed($crate::gpio::Speed::$Speed))?)
154 }
155 }
156
157 $(#[$attr])*
158 #[allow(irrefutable_let_patterns)]
159 impl<MODE> TryFrom<$name> for gpio::$PX<MODE>
160 where
161 MODE: $crate::gpio::PinMode,
162 $crate::gpio::Alternate<$A, $Otype>: $crate::gpio::PinMode,
163 {
164 type Error = ();
165
166 fn try_from(a: $name) -> Result<Self, Self::Error> {
167 if let $name::$PX(p) = a {
168 Ok(p.into_mode())
169 } else {
170 Err(())
171 }
172 }
173 }
174 )*
175 )*
176 };
177
178 ( $($(#[$docs:meta])* <$name:ident> default:$DefaultOtype:ident for $(no: $NoPin:ident,)? [$(
179 $(#[$attr:meta])* $PX:ident<$A:literal>,
180 )*],)*) => {
181 $(
182 #[derive(Debug)]
183 $(#[$docs])*
184 pub enum $name<Otype = $DefaultOtype> {
185 $(
186 None($NoPin<Otype>),
187 )?
188
189 $(
190 $(#[$attr])*
191 $PX(gpio::$PX<$crate::gpio::Alternate<$A, Otype>>),
192 )*
193 }
194
195 impl<Otype> crate::Sealed for $name<Otype> { }
196
197 #[allow(unreachable_patterns)]
198 impl<Otype> $crate::gpio::ReadPin for $name<Otype> {
199 fn is_low(&self) -> bool {
200 match self {
201 $(
202 $(#[$attr])*
203 Self::$PX(p) => p.is_low(),
204 )*
205 _ => false,
206 }
207 }
208 }
209
210 #[allow(unreachable_patterns)]
211 impl<Otype> $crate::gpio::PinSpeed for $name<Otype> {
212 fn set_speed(&mut self, _speed: $crate::gpio::Speed) {
213 match self {
214 $(
215 $(#[$attr])*
216 Self::$PX(p) => p.set_speed(_speed),
217 )*
218 _ => {}
219 }
220 }
221 }
222
223 #[allow(unreachable_patterns)]
224 impl<Otype> $crate::gpio::PinPull for $name<Otype> {
225 fn set_internal_resistor(&mut self, _pull: $crate::gpio::Pull) {
226 match self {
227 $(
228 $(#[$attr])*
229 Self::$PX(p) => p.set_internal_resistor(_pull),
230 )*
231 _ => {}
232 }
233 }
234 }
235
236 #[allow(unreachable_patterns)]
237 impl<Otype> $crate::gpio::ExtiPin for $name<Otype> {
238 extipin! { $( $(#[$attr])* $PX, )* }
239 }
240
241 $(
242 impl<Otype> From<$NoPin<Otype>> for $name<Otype> {
243 fn from(p: $NoPin<Otype>) -> Self {
244 Self::None(p)
245 }
246 }
247 )?
248
249 $(
250 $(#[$attr])*
251 impl<MODE, Otype> From<gpio::$PX<MODE>> for $name<Otype>
252 where
253 MODE: $crate::gpio::marker::NotAlt + $crate::gpio::PinMode,
254 $crate::gpio::Alternate<$A, Otype>: $crate::gpio::PinMode,
255 {
256 fn from(p: gpio::$PX<MODE>) -> Self {
257 Self::$PX(p.into_mode())
258 }
259 }
260
261 $(#[$attr])*
262 impl<Otype> From<gpio::$PX<$crate::gpio::Alternate<$A, Otype>>> for $name<Otype> {
263 fn from(p: gpio::$PX<$crate::gpio::Alternate<$A, Otype>>) -> Self {
264 Self::$PX(p)
265 }
266 }
267
268 $(#[$attr])*
269 #[allow(irrefutable_let_patterns)]
270 impl<MODE, Otype> TryFrom<$name<Otype>> for gpio::$PX<MODE>
271 where
272 MODE: $crate::gpio::PinMode,
273 $crate::gpio::Alternate<$A, Otype>: $crate::gpio::PinMode,
274 {
275 type Error = ();
276
277 fn try_from(a: $name<Otype>) -> Result<Self, Self::Error> {
278 if let $name::$PX(p) = a {
279 Ok(p.into_mode())
280 } else {
281 Err(())
282 }
283 }
284 }
285 )*
286 )*
287 };
288}
289use pin;
290
291#[cfg(feature = "can1")]
293pub trait CanCommon {
294 type Rx;
295 type Tx;
296}
297
298#[cfg(feature = "dfsdm")]
300pub trait DfsdmBasic {
301 type Ckin0;
302 type Ckin1;
303 type Ckout;
304 type Datin0;
305 type Datin1;
306}
307#[cfg(feature = "dfsdm")]
308pub trait DfsdmGeneral: DfsdmBasic {
309 type Ckin2;
310 type Ckin3;
311 type Datin2;
312 type Datin3;
313}
314#[cfg(feature = "dfsdm")]
315pub trait DfsdmAdvanced: DfsdmGeneral {
316 type Ckin4;
317 type Ckin5;
318 type Ckin6;
319 type Ckin7;
320 type Datin4;
321 type Datin5;
322 type Datin6;
323 type Datin7;
324}
325
326pub trait SerialAsync {
328 type Rx<Otype>;
330 type Tx<Otype>;
332}
333pub trait SerialSync {
335 type Ck;
336}
337pub trait SerialFlowControl {
339 type Cts;
341 type Rts;
343}
344
345pub trait I2cCommon {
347 type Scl;
348 type Sda;
349 type Smba;
350}
351
352pub trait I2sCommon {
354 type Ck: crate::gpio::PinSpeed;
355 type Sd;
356 type Ws: crate::gpio::ReadPin + crate::gpio::ExtiPin;
357}
358pub trait I2sMaster {
359 type Mck;
360}
361pub trait I2sExtPin {
362 type ExtSd;
363}
364
365#[cfg(feature = "quadspi")]
368pub trait QuadSpiBanks {
369 type Bank1;
370 type Bank2;
371}
372#[cfg(feature = "quadspi")]
373pub trait QuadSpiBank {
374 type Io0: crate::gpio::PinSpeed;
375 type Io1: crate::gpio::PinSpeed;
376 type Io2: crate::gpio::PinSpeed;
377 type Io3: crate::gpio::PinSpeed;
378 type Ncs: crate::gpio::PinSpeed;
379}
380
381#[cfg(feature = "sai1")]
384pub trait SaiChannels {
385 type A;
386 type B;
387}
388#[cfg(feature = "sai1")]
389pub trait SaiChannel {
390 type Fs;
391 type Mclk;
392 type Sck;
393 type Sd;
394}
395
396#[cfg(feature = "spdifrx")]
399pub trait SPdifIn<const C: u8> {
400 type In;
401}
402
403pub trait SpiCommon {
405 type Miso;
406 type Mosi;
407 type Nss;
408 type Sck;
409}
410
411pub trait TimCPin<const C: u8> {
415 type Ch<Otype>;
416}
417
418pub trait TimNCPin<const C: u8> {
420 type ChN<Otype>;
421}
422
423pub trait TimBkin {
425 type Bkin;
426}
427
428pub trait TimEtr {
430 type Etr;
431}