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 [$(
69 $(#[$attr:meta])* $PX:ident<$A:literal $(, Speed::$Speed:ident)?>,
70 )*],)*) => {
71 $(
72 #[derive(Debug)]
73 $(#[$docs])*
74 pub enum $name {
75 $(
76 $(#[$attr])*
77 $PX(gpio::$PX<$crate::gpio::Alternate<$A, $Otype>>),
78 )*
79 }
80
81 impl crate::Sealed for $name { }
82
83 #[allow(unreachable_patterns)]
84 impl $crate::gpio::ReadPin for $name {
85 fn is_low(&self) -> bool {
86 match self {
87 $(
88 $(#[$attr])*
89 Self::$PX(p) => p.is_low(),
90 )*
91 _ => false,
92 }
93 }
94 }
95
96 #[allow(unreachable_patterns)]
97 impl $crate::gpio::PinSpeed for $name {
98 fn set_speed(&mut self, _speed: $crate::gpio::Speed) {
99 match self {
100 $(
101 $(#[$attr])*
102 Self::$PX(p) => p.set_speed(_speed),
103 )*
104 _ => {}
105 }
106 }
107 }
108
109 #[allow(unreachable_patterns)]
110 impl $crate::gpio::PinPull for $name {
111 fn set_internal_resistor(&mut self, _pull: $crate::gpio::Pull) {
112 match self {
113 $(
114 $(#[$attr])*
115 Self::$PX(p) => p.set_internal_resistor(_pull),
116 )*
117 _ => {}
118 }
119 }
120 }
121
122 #[allow(unreachable_patterns)]
123 impl $crate::gpio::ExtiPin for $name {
124 extipin! { $( $(#[$attr])* $PX, )* }
125 }
126
127 $(
128 $(#[$attr])*
129 impl<MODE> From<gpio::$PX<MODE>> for $name
130 where
131 MODE: $crate::gpio::marker::NotAlt + $crate::gpio::PinMode
132 {
133 fn from(p: gpio::$PX<MODE>) -> Self {
134 Self::$PX(p.into_mode() $(.speed($crate::gpio::Speed::$Speed))?)
135 }
136 }
137
138 $(#[$attr])*
139 impl From<gpio::$PX<$crate::gpio::Alternate<$A, $Otype>>> for $name {
140 fn from(p: gpio::$PX<$crate::gpio::Alternate<$A, $Otype>>) -> Self {
141 Self::$PX(p $(.speed($crate::gpio::Speed::$Speed))?)
142 }
143 }
144
145 $(#[$attr])*
146 #[allow(irrefutable_let_patterns)]
147 impl<MODE> TryFrom<$name> for gpio::$PX<MODE>
148 where
149 MODE: $crate::gpio::PinMode,
150 $crate::gpio::Alternate<$A, $Otype>: $crate::gpio::PinMode,
151 {
152 type Error = ();
153
154 fn try_from(a: $name) -> Result<Self, Self::Error> {
155 if let $name::$PX(p) = a {
156 Ok(p.into_mode())
157 } else {
158 Err(())
159 }
160 }
161 }
162 )*
163 )*
164 };
165
166 ( $($(#[$docs:meta])* <$name:ident> default:$DefaultOtype:ident for [$(
167 $(#[$attr:meta])* $PX:ident<$A:literal>,
168 )*],)*) => {
169 $(
170 #[derive(Debug)]
171 $(#[$docs])*
172 pub enum $name<Otype = $DefaultOtype> {
173 $(
174 $(#[$attr])*
175 $PX(gpio::$PX<$crate::gpio::Alternate<$A, Otype>>),
176 )*
177 }
178
179 impl<Otype> crate::Sealed for $name<Otype> { }
180
181 #[allow(unreachable_patterns)]
182 impl<Otype> $crate::gpio::ReadPin for $name<Otype> {
183 fn is_low(&self) -> bool {
184 match self {
185 $(
186 $(#[$attr])*
187 Self::$PX(p) => p.is_low(),
188 )*
189 _ => false,
190 }
191 }
192 }
193
194 #[allow(unreachable_patterns)]
195 impl<Otype> $crate::gpio::PinSpeed for $name<Otype> {
196 fn set_speed(&mut self, _speed: $crate::gpio::Speed) {
197 match self {
198 $(
199 $(#[$attr])*
200 Self::$PX(p) => p.set_speed(_speed),
201 )*
202 _ => {}
203 }
204 }
205 }
206
207 #[allow(unreachable_patterns)]
208 impl<Otype> $crate::gpio::PinPull for $name<Otype> {
209 fn set_internal_resistor(&mut self, _pull: $crate::gpio::Pull) {
210 match self {
211 $(
212 $(#[$attr])*
213 Self::$PX(p) => p.set_internal_resistor(_pull),
214 )*
215 _ => {}
216 }
217 }
218 }
219
220 #[allow(unreachable_patterns)]
221 impl<Otype> $crate::gpio::ExtiPin for $name<Otype> {
222 extipin! { $( $(#[$attr])* $PX, )* }
223 }
224
225 $(
226 $(#[$attr])*
227 impl<MODE, Otype> From<gpio::$PX<MODE>> for $name<Otype>
228 where
229 MODE: $crate::gpio::marker::NotAlt + $crate::gpio::PinMode,
230 $crate::gpio::Alternate<$A, Otype>: $crate::gpio::PinMode,
231 {
232 fn from(p: gpio::$PX<MODE>) -> Self {
233 Self::$PX(p.into_mode())
234 }
235 }
236
237 $(#[$attr])*
238 impl<Otype> From<gpio::$PX<$crate::gpio::Alternate<$A, Otype>>> for $name<Otype> {
239 fn from(p: gpio::$PX<$crate::gpio::Alternate<$A, Otype>>) -> Self {
240 Self::$PX(p)
241 }
242 }
243
244 $(#[$attr])*
245 #[allow(irrefutable_let_patterns)]
246 impl<MODE, Otype> TryFrom<$name<Otype>> for gpio::$PX<MODE>
247 where
248 MODE: $crate::gpio::PinMode,
249 $crate::gpio::Alternate<$A, Otype>: $crate::gpio::PinMode,
250 {
251 type Error = ();
252
253 fn try_from(a: $name<Otype>) -> Result<Self, Self::Error> {
254 if let $name::$PX(p) = a {
255 Ok(p.into_mode())
256 } else {
257 Err(())
258 }
259 }
260 }
261 )*
262 )*
263 };
264}
265use pin;
266
267#[cfg(feature = "can1")]
269pub trait CanCommon {
270 type Rx;
271 type Tx;
272}
273
274#[cfg(feature = "dfsdm")]
276pub trait DfsdmBasic {
277 type Ckin0;
278 type Ckin1;
279 type Ckout;
280 type Datin0;
281 type Datin1;
282}
283#[cfg(feature = "dfsdm")]
284pub trait DfsdmGeneral: DfsdmBasic {
285 type Ckin2;
286 type Ckin3;
287 type Datin2;
288 type Datin3;
289}
290#[cfg(feature = "dfsdm")]
291pub trait DfsdmAdvanced: DfsdmGeneral {
292 type Ckin4;
293 type Ckin5;
294 type Ckin6;
295 type Ckin7;
296 type Datin4;
297 type Datin5;
298 type Datin6;
299 type Datin7;
300}
301
302pub trait SerialAsync {
304 type Rx<Otype>;
306 type Tx<Otype>;
308}
309pub trait SerialSync {
311 type Ck;
312}
313pub trait SerialFlowControl {
315 type Cts;
317 type Rts;
319}
320
321pub trait I2cCommon {
323 type Scl;
324 type Sda;
325 type Smba;
326}
327
328pub trait I2sCommon {
330 type Ck: crate::gpio::PinSpeed;
331 type Sd;
332 type Ws: crate::gpio::ReadPin + crate::gpio::ExtiPin;
333}
334pub trait I2sMaster {
335 type Mck;
336}
337pub trait I2sExtPin {
338 type ExtSd;
339}
340
341#[cfg(feature = "quadspi")]
344pub trait QuadSpiBanks {
345 type Bank1;
346 type Bank2;
347}
348#[cfg(feature = "quadspi")]
349pub trait QuadSpiBank {
350 type Io0: crate::gpio::PinSpeed;
351 type Io1: crate::gpio::PinSpeed;
352 type Io2: crate::gpio::PinSpeed;
353 type Io3: crate::gpio::PinSpeed;
354 type Ncs: crate::gpio::PinSpeed;
355}
356
357#[cfg(feature = "sai1")]
360pub trait SaiChannels {
361 type A;
362 type B;
363}
364#[cfg(feature = "sai1")]
365pub trait SaiChannel {
366 #[allow(non_upper_case_globals)]
367 const NoMclk: Option<Self::Mclk> = None;
368 type Fs;
369 type Mclk;
370 type Sck;
371 type Sd;
372}
373
374#[cfg(feature = "spdifrx")]
377pub trait SPdifIn<const C: u8> {
378 type In;
379}
380
381pub trait SpiCommon {
383 type Miso;
384 type Mosi;
385 type Nss;
386 type Sck;
387}
388
389pub trait TimCPin<const C: u8> {
393 type Ch<Otype>;
394}
395
396pub trait TimNCPin<const C: u8> {
398 type ChN<Otype>;
399}
400
401pub trait TimBkin {
403 type Bkin;
404}
405
406pub trait TimEtr {
408 type Etr;
409}