-
Notifications
You must be signed in to change notification settings - Fork 214
/
gpio.rs
874 lines (779 loc) · 25.6 KB
/
gpio.rs
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
//! General Purpose Input / Output
//!
//! The GPIO pins are organised into groups of 16 pins which can be accessed through the
//! `gpioa`, `gpiob`... modules. To get access to the pins, you first need to convert them into a
//! HAL designed struct from the `pac` struct using the [split](trait.GpioExt.html#tymethod.split) function.
//! ```rust
//! // Acquire the GPIOC peripheral
//! // NOTE: `dp` is the device peripherals from the `PAC` crate
//! let mut gpioa = dp.GPIOA.split();
//! ```
//!
//! This gives you a struct containing all the pins `px0..px15`.
//! By default pins are in floating input mode. You can change their modes.
//! For example, to set `pa5` high, you would call
//!
//! ```rust
//! let output = gpioa.pa5.into_push_pull_output();
//! output.set_high();
//! ```
//!
//! ## Modes
//!
//! Each GPIO pin can be set to various modes:
//!
//! - **Alternate**: Pin mode required when the pin is driven by other peripherals
//! - **AlternateOD**: Pin mode required when the pin is driven by other peripherals and has open drain
//! - **Analog**: Analog input to be used with ADC.
//! - Input
//! - **PullUp**: Input connected to high with a weak pull up resistor. Will be high when nothing
//! is connected
//! - **PullDown**: Input connected to high with a weak pull up resistor. Will be low when nothing
//! is connected
//! - **Floating**: Input not pulled to high or low. Will be undefined when nothing is connected
//! - Output
//! - **PushPull**: Output which either drives the pin high or low
//! - **OpenDrain**: Output which leaves the gate floating, or pulls it do ground in drain
//! mode. Can be used as an input in the `open` configuration
//!
//! ## Changing modes
//! The simplest way to change the pin mode is to use the `into_<mode>` functions. These return a
//! new struct with the correct mode that you can use the input or output functions on.
//!
//! If you need a more temporary mode change, and can not use the `into_<mode>` functions for
//! ownership reasons, you can use the closure based `with_<mode>` functions to temporarily change the pin type, do
//! some output or input, and then have it change back once done.
use core::convert::Infallible;
use core::marker::PhantomData;
pub use embedded_hal::digital::v2::PinState;
use embedded_hal::digital::v2::{
InputPin, IoPin, OutputPin, StatefulOutputPin, ToggleableOutputPin,
};
use crate::pac::EXTI;
use crate::syscfg::SysCfg;
mod convert;
pub(crate) use convert::{Const, SetAlternate, SetAlternateOD};
mod partially_erased;
pub use partially_erased::{PEPin, PartiallyErasedPin};
mod erased;
pub use erased::{EPin, ErasedPin};
/// A filler pin type
pub struct NoPin;
/// Extension trait to split a GPIO peripheral in independent pins and registers
pub trait GpioExt {
/// The parts to split the GPIO into
type Parts;
/// Splits the GPIO block into independent pins and registers
fn split(self) -> Self::Parts;
}
pub trait PinExt {
type Mode;
/// Return pin number
fn pin_id(&self) -> u8;
/// Return port number
fn port_id(&self) -> u8;
}
/// Some alternate mode (type state)
pub struct Alternate<const A: u8>;
/// Some alternate mode in open drain configuration (type state)
pub struct AlternateOD<const A: u8>;
// Compatibility constants
pub const AF0: u8 = 0;
pub const AF1: u8 = 1;
pub const AF2: u8 = 2;
pub const AF3: u8 = 3;
pub const AF4: u8 = 4;
pub const AF5: u8 = 5;
pub const AF6: u8 = 6;
pub const AF7: u8 = 7;
pub const AF8: u8 = 8;
pub const AF9: u8 = 9;
pub const AF10: u8 = 10;
pub const AF11: u8 = 11;
pub const AF12: u8 = 12;
pub const AF13: u8 = 13;
pub const AF14: u8 = 14;
pub const AF15: u8 = 15;
/// Input mode (type state)
pub struct Input<MODE> {
_mode: PhantomData<MODE>,
}
/// Floating input (type state)
pub struct Floating;
/// Pulled down input (type state)
pub struct PullDown;
/// Pulled up input (type state)
pub struct PullUp;
/// Open drain input or output (type state)
pub struct OpenDrain;
/// Output mode (type state)
pub struct Output<MODE> {
_mode: PhantomData<MODE>,
}
/// Push pull output (type state)
pub struct PushPull;
/// Analog mode (type state)
pub struct Analog;
/// GPIO Pin speed selection
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Speed {
Low = 0,
Medium = 1,
High = 2,
VeryHigh = 3,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Edge {
Rising,
Falling,
RisingFalling,
}
mod sealed {
/// Marker trait that show if `ExtiPin` can be implemented
pub trait Interruptable {}
}
use sealed::Interruptable;
impl<MODE> Interruptable for Output<MODE> {}
impl<MODE> Interruptable for Input<MODE> {}
/// External Interrupt Pin
pub trait ExtiPin {
fn make_interrupt_source(&mut self, syscfg: &mut SysCfg);
fn trigger_on_edge(&mut self, exti: &mut EXTI, level: Edge);
fn enable_interrupt(&mut self, exti: &mut EXTI);
fn disable_interrupt(&mut self, exti: &mut EXTI);
fn clear_interrupt_pending_bit(&mut self);
fn check_interrupt(&self) -> bool;
}
impl<PIN> ExtiPin for PIN
where
PIN: PinExt,
PIN::Mode: Interruptable,
{
/// Make corresponding EXTI line sensitive to this pin
#[inline(always)]
fn make_interrupt_source(&mut self, syscfg: &mut SysCfg) {
let i = self.pin_id();
let port = self.port_id() as u32;
let offset = 4 * (i % 4);
match i {
0..=3 => {
syscfg.exticr1.modify(|r, w| unsafe {
w.bits((r.bits() & !(0xf << offset)) | (port << offset))
});
}
4..=7 => {
syscfg.exticr2.modify(|r, w| unsafe {
w.bits((r.bits() & !(0xf << offset)) | (port << offset))
});
}
8..=11 => {
syscfg.exticr3.modify(|r, w| unsafe {
w.bits((r.bits() & !(0xf << offset)) | (port << offset))
});
}
12..=15 => {
syscfg.exticr4.modify(|r, w| unsafe {
w.bits((r.bits() & !(0xf << offset)) | (port << offset))
});
}
_ => unreachable!(),
}
}
/// Generate interrupt on rising edge, falling edge or both
#[inline(always)]
fn trigger_on_edge(&mut self, exti: &mut EXTI, edge: Edge) {
let i = self.pin_id();
match edge {
Edge::Rising => {
exti.rtsr
.modify(|r, w| unsafe { w.bits(r.bits() | (1 << i)) });
exti.ftsr
.modify(|r, w| unsafe { w.bits(r.bits() & !(1 << i)) });
}
Edge::Falling => {
exti.ftsr
.modify(|r, w| unsafe { w.bits(r.bits() | (1 << i)) });
exti.rtsr
.modify(|r, w| unsafe { w.bits(r.bits() & !(1 << i)) });
}
Edge::RisingFalling => {
exti.rtsr
.modify(|r, w| unsafe { w.bits(r.bits() | (1 << i)) });
exti.ftsr
.modify(|r, w| unsafe { w.bits(r.bits() | (1 << i)) });
}
}
}
/// Enable external interrupts from this pin.
#[inline(always)]
fn enable_interrupt(&mut self, exti: &mut EXTI) {
exti.imr
.modify(|r, w| unsafe { w.bits(r.bits() | (1 << self.pin_id())) });
}
/// Disable external interrupts from this pin
#[inline(always)]
fn disable_interrupt(&mut self, exti: &mut EXTI) {
exti.imr
.modify(|r, w| unsafe { w.bits(r.bits() & !(1 << self.pin_id())) });
}
/// Clear the interrupt pending bit for this pin
#[inline(always)]
fn clear_interrupt_pending_bit(&mut self) {
unsafe { (*EXTI::ptr()).pr.write(|w| w.bits(1 << self.pin_id())) };
}
/// Reads the interrupt pending bit for this pin
#[inline(always)]
fn check_interrupt(&self) -> bool {
unsafe { ((*EXTI::ptr()).pr.read().bits() & (1 << self.pin_id())) != 0 }
}
}
/// Generic pin type
///
/// - `MODE` is one of the pin modes (see [Modes](crate::gpio#modes) section).
/// - `P` is port name: `A` for GPIOA, `B` for GPIOB, etc.
/// - `N` is pin number: from `0` to `15`.
pub struct Pin<MODE, const P: char, const N: u8> {
_mode: PhantomData<MODE>,
}
impl<MODE, const P: char, const N: u8> Pin<MODE, P, N> {
const fn new() -> Self {
Self { _mode: PhantomData }
}
}
impl<MODE, const P: char, const N: u8> PinExt for Pin<MODE, P, N> {
type Mode = MODE;
#[inline(always)]
fn pin_id(&self) -> u8 {
N
}
#[inline(always)]
fn port_id(&self) -> u8 {
P as u8 - b'A'
}
}
impl<MODE, const P: char, const N: u8> Pin<Output<MODE>, P, N> {
/// Set pin speed
pub fn set_speed(self, speed: Speed) -> Self {
let offset = 2 * { N };
unsafe {
(*Gpio::<P>::ptr())
.ospeedr
.modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | ((speed as u32) << offset)))
};
self
}
}
impl<const P: char, const N: u8> Pin<Output<OpenDrain>, P, N> {
/// Enables / disables the internal pull up
pub fn internal_pull_up(&mut self, on: bool) {
let offset = 2 * { N };
let value = if on { 0b01 } else { 0b00 };
unsafe {
(*Gpio::<P>::ptr())
.pupdr
.modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset)))
};
}
}
impl<const P: char, const N: u8, const A: u8> Pin<Alternate<A>, P, N> {
/// Set pin speed
pub fn set_speed(self, speed: Speed) -> Self {
let offset = 2 * { N };
unsafe {
(*Gpio::<P>::ptr())
.ospeedr
.modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | ((speed as u32) << offset)))
};
self
}
/// Enables / disables the internal pull up
pub fn internal_pull_up(self, on: bool) -> Self {
let offset = 2 * { N };
let value = if on { 0b01 } else { 0b00 };
unsafe {
(*Gpio::<P>::ptr())
.pupdr
.modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset)))
};
self
}
}
impl<const P: char, const N: u8, const A: u8> Pin<Alternate<A>, P, N> {
/// Turns pin alternate configuration pin into open drain
pub fn set_open_drain(self) -> Pin<AlternateOD<A>, P, N> {
let offset = { N };
unsafe {
(*Gpio::<P>::ptr())
.otyper
.modify(|r, w| w.bits(r.bits() | (1 << offset)))
};
Pin::new()
}
}
impl<MODE, const P: char, const N: u8> Pin<MODE, P, N> {
/// Erases the pin number from the type
///
/// This is useful when you want to collect the pins into an array where you
/// need all the elements to have the same type
pub fn erase_number(self) -> PEPin<MODE, P> {
PEPin::new(N)
}
/// Erases the pin number and the port from the type
///
/// This is useful when you want to collect the pins into an array where you
/// need all the elements to have the same type
pub fn erase(self) -> EPin<MODE> {
EPin::new(P as u8 - b'A', N)
}
}
impl<MODE, const P: char, const N: u8> Pin<MODE, P, N> {
/// Set the output of the pin regardless of its mode.
/// Primarily used to set the output value of the pin
/// before changing its mode to an output to avoid
/// a short spike of an incorrect value
#[inline(always)]
fn _set_state(&mut self, state: PinState) {
match state {
PinState::High => self._set_high(),
PinState::Low => self._set_low(),
}
}
#[inline(always)]
fn _set_high(&mut self) {
// NOTE(unsafe) atomic write to a stateless register
unsafe { (*Gpio::<P>::ptr()).bsrr.write(|w| w.bits(1 << N)) }
}
#[inline(always)]
fn _set_low(&mut self) {
// NOTE(unsafe) atomic write to a stateless register
unsafe { (*Gpio::<P>::ptr()).bsrr.write(|w| w.bits(1 << (16 + N))) }
}
#[inline(always)]
fn _is_set_low(&self) -> bool {
// NOTE(unsafe) atomic read with no side effects
unsafe { (*Gpio::<P>::ptr()).odr.read().bits() & (1 << N) == 0 }
}
#[inline(always)]
fn _is_low(&self) -> bool {
// NOTE(unsafe) atomic read with no side effects
unsafe { (*Gpio::<P>::ptr()).idr.read().bits() & (1 << N) == 0 }
}
}
impl<MODE, const P: char, const N: u8> Pin<Output<MODE>, P, N> {
#[inline(always)]
pub fn set_high(&mut self) {
self._set_high()
}
#[inline(always)]
pub fn set_low(&mut self) {
self._set_low()
}
#[inline(always)]
pub fn get_state(&self) -> PinState {
if self.is_set_low() {
PinState::Low
} else {
PinState::High
}
}
#[inline(always)]
pub fn set_state(&mut self, state: PinState) {
match state {
PinState::Low => self.set_low(),
PinState::High => self.set_high(),
}
}
#[inline(always)]
pub fn is_set_high(&self) -> bool {
!self.is_set_low()
}
#[inline(always)]
pub fn is_set_low(&self) -> bool {
self._is_set_low()
}
#[inline(always)]
pub fn toggle(&mut self) {
if self.is_set_low() {
self.set_high()
} else {
self.set_low()
}
}
}
impl<MODE, const P: char, const N: u8> OutputPin for Pin<Output<MODE>, P, N> {
type Error = Infallible;
#[inline(always)]
fn set_high(&mut self) -> Result<(), Self::Error> {
self.set_high();
Ok(())
}
#[inline(always)]
fn set_low(&mut self) -> Result<(), Self::Error> {
self.set_low();
Ok(())
}
}
impl<MODE, const P: char, const N: u8> StatefulOutputPin for Pin<Output<MODE>, P, N> {
#[inline(always)]
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(self.is_set_high())
}
#[inline(always)]
fn is_set_low(&self) -> Result<bool, Self::Error> {
Ok(self.is_set_low())
}
}
impl<MODE, const P: char, const N: u8> ToggleableOutputPin for Pin<Output<MODE>, P, N> {
type Error = Infallible;
#[inline(always)]
fn toggle(&mut self) -> Result<(), Self::Error> {
self.toggle();
Ok(())
}
}
impl<const P: char, const N: u8> Pin<Output<OpenDrain>, P, N> {
#[inline(always)]
pub fn is_high(&self) -> bool {
!self.is_low()
}
#[inline(always)]
pub fn is_low(&self) -> bool {
self._is_low()
}
}
impl<const P: char, const N: u8> InputPin for Pin<Output<OpenDrain>, P, N> {
type Error = Infallible;
#[inline(always)]
fn is_high(&self) -> Result<bool, Self::Error> {
Ok(self.is_high())
}
#[inline(always)]
fn is_low(&self) -> Result<bool, Self::Error> {
Ok(self.is_low())
}
}
impl<MODE, const P: char, const N: u8> Pin<Input<MODE>, P, N> {
#[inline(always)]
pub fn is_high(&self) -> bool {
!self.is_low()
}
#[inline(always)]
pub fn is_low(&self) -> bool {
self._is_low()
}
}
impl<MODE, const P: char, const N: u8> InputPin for Pin<Input<MODE>, P, N> {
type Error = Infallible;
#[inline(always)]
fn is_high(&self) -> Result<bool, Self::Error> {
Ok(self.is_high())
}
#[inline(always)]
fn is_low(&self) -> Result<bool, Self::Error> {
Ok(self.is_low())
}
}
impl<const P: char, const N: u8> IoPin<Self, Self> for Pin<Output<OpenDrain>, P, N> {
type Error = Infallible;
fn into_input_pin(self) -> Result<Self, Self::Error> {
Ok(self)
}
fn into_output_pin(mut self, state: PinState) -> Result<Self, Self::Error> {
self.set_state(state);
Ok(self)
}
}
impl<const P: char, const N: u8> IoPin<Pin<Input<Floating>, P, N>, Self>
for Pin<Output<PushPull>, P, N>
{
type Error = Infallible;
fn into_input_pin(self) -> Result<Pin<Input<Floating>, P, N>, Self::Error> {
Ok(self.into_floating_input())
}
fn into_output_pin(mut self, state: PinState) -> Result<Self, Self::Error> {
self.set_state(state);
Ok(self)
}
}
impl<const P: char, const N: u8> IoPin<Self, Pin<Output<PushPull>, P, N>>
for Pin<Input<Floating>, P, N>
{
type Error = Infallible;
fn into_input_pin(self) -> Result<Self, Self::Error> {
Ok(self)
}
fn into_output_pin(self, state: PinState) -> Result<Pin<Output<PushPull>, P, N>, Self::Error> {
Ok(self.into_push_pull_output_in_state(state))
}
}
macro_rules! gpio {
($GPIOX:ident, $gpiox:ident, $PEPin:ident, $port_id:expr, $PXn:ident, [
$($PXi:ident: ($pxi:ident, $i:expr, $MODE:ty),)+
]) => {
/// GPIO
pub mod $gpiox {
use crate::pac::{$GPIOX, RCC};
use crate::rcc::{Enable, Reset};
use super::{
Floating, Input,
};
/// GPIO parts
pub struct Parts {
$(
/// Pin
pub $pxi: $PXi<$MODE>,
)+
}
impl super::GpioExt for $GPIOX {
type Parts = Parts;
fn split(self) -> Parts {
unsafe {
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
let rcc = &(*RCC::ptr());
// Enable clock.
$GPIOX::enable(rcc);
$GPIOX::reset(rcc);
}
Parts {
$(
$pxi: $PXi::new(),
)+
}
}
}
pub type $PXn<MODE> = super::PEPin<MODE, $port_id>;
$(
pub type $PXi<MODE> = super::Pin<MODE, $port_id, $i>;
)+
}
}
}
gpio!(GPIOA, gpioa, PA, 'A', PAn, [
PA0: (pa0, 0, Input<Floating>),
PA1: (pa1, 1, Input<Floating>),
PA2: (pa2, 2, Input<Floating>),
PA3: (pa3, 3, Input<Floating>),
PA4: (pa4, 4, Input<Floating>),
PA5: (pa5, 5, Input<Floating>),
PA6: (pa6, 6, Input<Floating>),
PA7: (pa7, 7, Input<Floating>),
PA8: (pa8, 8, Input<Floating>),
PA9: (pa9, 9, Input<Floating>),
PA10: (pa10, 10, Input<Floating>),
PA11: (pa11, 11, Input<Floating>),
PA12: (pa12, 12, Input<Floating>),
PA13: (pa13, 13, Input<Floating>),
PA14: (pa14, 14, Input<Floating>),
PA15: (pa15, 15, Input<Floating>),
]);
gpio!(GPIOB, gpiob, PB, 'B', PBn, [
PB0: (pb0, 0, Input<Floating>),
PB1: (pb1, 1, Input<Floating>),
PB2: (pb2, 2, Input<Floating>),
PB3: (pb3, 3, Input<Floating>),
PB4: (pb4, 4, Input<Floating>),
PB5: (pb5, 5, Input<Floating>),
PB6: (pb6, 6, Input<Floating>),
PB7: (pb7, 7, Input<Floating>),
PB8: (pb8, 8, Input<Floating>),
PB9: (pb9, 9, Input<Floating>),
PB10: (pb10, 10, Input<Floating>),
PB11: (pb11, 11, Input<Floating>),
PB12: (pb12, 12, Input<Floating>),
PB13: (pb13, 13, Input<Floating>),
PB14: (pb14, 14, Input<Floating>),
PB15: (pb15, 15, Input<Floating>),
]);
gpio!(GPIOC, gpioc, PC, 'C', PCn, [
PC0: (pc0, 0, Input<Floating>),
PC1: (pc1, 1, Input<Floating>),
PC2: (pc2, 2, Input<Floating>),
PC3: (pc3, 3, Input<Floating>),
PC4: (pc4, 4, Input<Floating>),
PC5: (pc5, 5, Input<Floating>),
PC6: (pc6, 6, Input<Floating>),
PC7: (pc7, 7, Input<Floating>),
PC8: (pc8, 8, Input<Floating>),
PC9: (pc9, 9, Input<Floating>),
PC10: (pc10, 10, Input<Floating>),
PC11: (pc11, 11, Input<Floating>),
PC12: (pc12, 12, Input<Floating>),
PC13: (pc13, 13, Input<Floating>),
PC14: (pc14, 14, Input<Floating>),
PC15: (pc15, 15, Input<Floating>),
]);
#[cfg(feature = "gpiod")]
gpio!(GPIOD, gpiod, PD, 'D', PDn, [
PD0: (pd0, 0, Input<Floating>),
PD1: (pd1, 1, Input<Floating>),
PD2: (pd2, 2, Input<Floating>),
PD3: (pd3, 3, Input<Floating>),
PD4: (pd4, 4, Input<Floating>),
PD5: (pd5, 5, Input<Floating>),
PD6: (pd6, 6, Input<Floating>),
PD7: (pd7, 7, Input<Floating>),
PD8: (pd8, 8, Input<Floating>),
PD9: (pd9, 9, Input<Floating>),
PD10: (pd10, 10, Input<Floating>),
PD11: (pd11, 11, Input<Floating>),
PD12: (pd12, 12, Input<Floating>),
PD13: (pd13, 13, Input<Floating>),
PD14: (pd14, 14, Input<Floating>),
PD15: (pd15, 15, Input<Floating>),
]);
#[cfg(feature = "gpioe")]
gpio!(GPIOE, gpioe, PE, 'E', PEn, [
PE0: (pe0, 0, Input<Floating>),
PE1: (pe1, 1, Input<Floating>),
PE2: (pe2, 2, Input<Floating>),
PE3: (pe3, 3, Input<Floating>),
PE4: (pe4, 4, Input<Floating>),
PE5: (pe5, 5, Input<Floating>),
PE6: (pe6, 6, Input<Floating>),
PE7: (pe7, 7, Input<Floating>),
PE8: (pe8, 8, Input<Floating>),
PE9: (pe9, 9, Input<Floating>),
PE10: (pe10, 10, Input<Floating>),
PE11: (pe11, 11, Input<Floating>),
PE12: (pe12, 12, Input<Floating>),
PE13: (pe13, 13, Input<Floating>),
PE14: (pe14, 14, Input<Floating>),
PE15: (pe15, 15, Input<Floating>),
]);
#[cfg(feature = "gpiof")]
gpio!(GPIOF, gpiof, PF, 'F', PFn, [
PF0: (pf0, 0, Input<Floating>),
PF1: (pf1, 1, Input<Floating>),
PF2: (pf2, 2, Input<Floating>),
PF3: (pf3, 3, Input<Floating>),
PF4: (pf4, 4, Input<Floating>),
PF5: (pf5, 5, Input<Floating>),
PF6: (pf6, 6, Input<Floating>),
PF7: (pf7, 7, Input<Floating>),
PF8: (pf8, 8, Input<Floating>),
PF9: (pf9, 9, Input<Floating>),
PF10: (pf10, 10, Input<Floating>),
PF11: (pf11, 11, Input<Floating>),
PF12: (pf12, 12, Input<Floating>),
PF13: (pf13, 13, Input<Floating>),
PF14: (pf14, 14, Input<Floating>),
PF15: (pf15, 15, Input<Floating>),
]);
#[cfg(feature = "gpiog")]
gpio!(GPIOG, gpiog, PG, 'G', PGn, [
PG0: (pg0, 0, Input<Floating>),
PG1: (pg1, 1, Input<Floating>),
PG2: (pg2, 2, Input<Floating>),
PG3: (pg3, 3, Input<Floating>),
PG4: (pg4, 4, Input<Floating>),
PG5: (pg5, 5, Input<Floating>),
PG6: (pg6, 6, Input<Floating>),
PG7: (pg7, 7, Input<Floating>),
PG8: (pg8, 8, Input<Floating>),
PG9: (pg9, 9, Input<Floating>),
PG10: (pg10, 10, Input<Floating>),
PG11: (pg11, 11, Input<Floating>),
PG12: (pg12, 12, Input<Floating>),
PG13: (pg13, 13, Input<Floating>),
PG14: (pg14, 14, Input<Floating>),
PG15: (pg15, 15, Input<Floating>),
]);
#[cfg(not(feature = "stm32f401"))]
gpio!(GPIOH, gpioh, PH, 'H', PHn, [
PH0: (ph0, 0, Input<Floating>),
PH1: (ph1, 1, Input<Floating>),
PH2: (ph2, 2, Input<Floating>),
PH3: (ph3, 3, Input<Floating>),
PH4: (ph4, 4, Input<Floating>),
PH5: (ph5, 5, Input<Floating>),
PH6: (ph6, 6, Input<Floating>),
PH7: (ph7, 7, Input<Floating>),
PH8: (ph8, 8, Input<Floating>),
PH9: (ph9, 9, Input<Floating>),
PH10: (ph10, 10, Input<Floating>),
PH11: (ph11, 11, Input<Floating>),
PH12: (ph12, 12, Input<Floating>),
PH13: (ph13, 13, Input<Floating>),
PH14: (ph14, 14, Input<Floating>),
PH15: (ph15, 15, Input<Floating>),
]);
#[cfg(feature = "stm32f401")]
gpio!(GPIOH, gpioh, PH, 'H', PHn, [
PH0: (ph0, 0, Input<Floating>),
PH1: (ph1, 1, Input<Floating>),
]);
#[cfg(feature = "gpioi")]
gpio!(GPIOI, gpioi, PI, 'I', PIn, [
PI0: (pi0, 0, Input<Floating>),
PI1: (pi1, 1, Input<Floating>),
PI2: (pi2, 2, Input<Floating>),
PI3: (pi3, 3, Input<Floating>),
PI4: (pi4, 4, Input<Floating>),
PI5: (pi5, 5, Input<Floating>),
PI6: (pi6, 6, Input<Floating>),
PI7: (pi7, 7, Input<Floating>),
PI8: (pi8, 8, Input<Floating>),
PI9: (pi9, 9, Input<Floating>),
PI10: (pi10, 10, Input<Floating>),
PI11: (pi11, 11, Input<Floating>),
PI12: (pi12, 12, Input<Floating>),
PI13: (pi13, 13, Input<Floating>),
PI14: (pi14, 14, Input<Floating>),
PI15: (pi15, 15, Input<Floating>),
]);
#[cfg(feature = "gpioj")]
gpio!(GPIOJ, gpioj, PJ, 'J', PJn, [
PJ0: (pj0, 0, Input<Floating>),
PJ1: (pj1, 1, Input<Floating>),
PJ2: (pj2, 2, Input<Floating>),
PJ3: (pj3, 3, Input<Floating>),
PJ4: (pj4, 4, Input<Floating>),
PJ5: (pj5, 5, Input<Floating>),
PJ6: (pj6, 6, Input<Floating>),
PJ7: (pj7, 7, Input<Floating>),
PJ8: (pj8, 8, Input<Floating>),
PJ9: (pj9, 9, Input<Floating>),
PJ10: (pj10, 10, Input<Floating>),
PJ11: (pj11, 11, Input<Floating>),
PJ12: (pj12, 12, Input<Floating>),
PJ13: (pj13, 13, Input<Floating>),
PJ14: (pj14, 14, Input<Floating>),
PJ15: (pj15, 15, Input<Floating>),
]);
#[cfg(feature = "gpiok")]
gpio!(GPIOK, gpiok, PK, 'K', PKn, [
PK0: (pk0, 0, Input<Floating>),
PK1: (pk1, 1, Input<Floating>),
PK2: (pk2, 2, Input<Floating>),
PK3: (pk3, 3, Input<Floating>),
PK4: (pk4, 4, Input<Floating>),
PK5: (pk5, 5, Input<Floating>),
PK6: (pk6, 6, Input<Floating>),
PK7: (pk7, 7, Input<Floating>),
]);
struct Gpio<const P: char>;
impl<const P: char> Gpio<P> {
const fn ptr() -> *const crate::pac::gpioa::RegisterBlock {
match P {
'A' => crate::pac::GPIOA::ptr(),
'B' => crate::pac::GPIOB::ptr() as _,
'C' => crate::pac::GPIOC::ptr() as _,
#[cfg(feature = "gpiod")]
'D' => crate::pac::GPIOD::ptr() as _,
#[cfg(feature = "gpioe")]
'E' => crate::pac::GPIOE::ptr() as _,
#[cfg(feature = "gpiof")]
'F' => crate::pac::GPIOF::ptr() as _,
#[cfg(feature = "gpiog")]
'G' => crate::pac::GPIOG::ptr() as _,
'H' => crate::pac::GPIOH::ptr() as _,
#[cfg(feature = "gpioi")]
'I' => crate::pac::GPIOI::ptr() as _,
#[cfg(feature = "gpioj")]
'J' => crate::pac::GPIOJ::ptr() as _,
#[cfg(feature = "gpiok")]
'K' => crate::pac::GPIOK::ptr() as _,
_ => crate::pac::GPIOA::ptr(),
}
}
}