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
//! General Purpose Input / Output

use core::marker::PhantomData;

use crate::rcc::Rcc;

/// 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, rcc: &mut Rcc) -> Self::Parts;
}

/// 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;

/// Analog mode (type state)
pub struct Analog;

/// Output mode (type state)
pub struct Output<MODE> {
    _mode: PhantomData<MODE>,
}

/// Push pull output (type state)
pub struct PushPull;

mod sealed {
    pub trait Sealed {}
}

/// Marker trait for valid pin modes (type state).
///
/// It can not be implemented by outside types.
pub trait PinMode: sealed::Sealed {
    // These constants are used to implement the pin configuration code.
    // They are not part of public API.

    #[doc(hidden)]
    const PUPDR: u8;
    #[doc(hidden)]
    const MODER: u8;
    #[doc(hidden)]
    const OTYPER: Option<u8> = None;
}

impl sealed::Sealed for Input<Floating> {}
impl PinMode for Input<Floating> {
    const PUPDR: u8 = 0b00;
    const MODER: u8 = 0b00;
}

impl sealed::Sealed for Input<PullDown> {}
impl PinMode for Input<PullDown> {
    const PUPDR: u8 = 0b10;
    const MODER: u8 = 0b00;
}

impl sealed::Sealed for Input<PullUp> {}
impl PinMode for Input<PullUp> {
    const PUPDR: u8 = 0b01;
    const MODER: u8 = 0b00;
}

impl sealed::Sealed for Analog {}
impl PinMode for Analog {
    const PUPDR: u8 = 0b00;
    const MODER: u8 = 0b11;
}

impl sealed::Sealed for Output<OpenDrain> {}
impl PinMode for Output<OpenDrain> {
    const PUPDR: u8 = 0b00;
    const MODER: u8 = 0b01;
    const OTYPER: Option<u8> = Some(0b1);
}

impl sealed::Sealed for Output<PushPull> {}
impl PinMode for Output<PushPull> {
    const PUPDR: u8 = 0b00;
    const MODER: u8 = 0b01;
    const OTYPER: Option<u8> = Some(0b0);
}

/// GPIO Pin speed selection
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Speed {
    Low = 0,
    Medium = 1,
    High = 2,
    VeryHigh = 3,
}

#[allow(dead_code)]
pub enum AltMode {
    AF0 = 0,
    AF1 = 1,
    AF2 = 2,
    AF3 = 3,
    AF4 = 4,
    AF5 = 5,
    AF6 = 6,
    AF7 = 7,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Port {
    PA,
    PB,
    PC,
    PD,
    PE,
    PH,
}

macro_rules! gpio {
    ($GPIOX:ident, $gpiox:ident, $iopxenr:ident, $PXx:ident, [
        $($PXi:ident: ($pxi:ident, $i:expr, $MODE:ty),)+
    ]) => {
        /// GPIO
        pub mod $gpiox {
            use core::marker::PhantomData;

            use crate::hal::digital::v2::{toggleable, InputPin, OutputPin, StatefulOutputPin};
            use crate::pac::$GPIOX;
            use crate::rcc::Rcc;
            use super::{
                Floating, GpioExt, Input, OpenDrain, Output, Speed,
                PullDown, PullUp, PushPull, AltMode, Analog, Port,
                PinMode,
            };

            /// GPIO parts
            pub struct Parts {
                $(
                    /// Pin
                    pub $pxi: $PXi<$MODE>,
                )+
            }

            impl GpioExt for $GPIOX {
                type Parts = Parts;

                fn split(self, rcc: &mut Rcc) -> Parts {
                    rcc.rb.iopenr.modify(|_, w| w.$iopxenr().set_bit());

                    Parts {
                        $(
                            $pxi: $PXi {
                                _mode: PhantomData,
                            },
                        )+
                    }
                }
            }

            /// Partially erased pin
            pub struct $PXx<MODE> {
                i: u8,
                _mode: PhantomData<MODE>,
            }

            impl<MODE> $PXx<MODE> {
                /// The port this pin is part of.
                pub const PORT: Port = Port::$PXx;

                /// Returns the port this pin is part of.
                pub fn port(&self) -> Port {
                    Port::$PXx
                }

                /// Returns this pin's number inside its port.
                pub fn pin_number(&self) -> u8 {
                    self.i
                }
            }

            impl<MODE> OutputPin for $PXx<Output<MODE>> {
                type Error = void::Void;

                fn set_high(&mut self) -> Result<(), Self::Error> {
                    // NOTE(unsafe) atomic write to a stateless register
                    unsafe { (*$GPIOX::ptr()).bsrr.write(|w| w.bits(1 << self.i)) };
                    Ok(())
                }

                fn set_low(&mut self) -> Result<(), Self::Error> {
                    // NOTE(unsafe) atomic write to a stateless register
                    unsafe { (*$GPIOX::ptr()).bsrr.write(|w| w.bits(1 << (self.i + 16))) };
                    Ok(())
                }
            }

            impl<MODE> StatefulOutputPin for $PXx<Output<MODE>> {
                fn is_set_high(&self) -> Result<bool, Self::Error> {
                    let is_high = self.is_set_low()?;
                    Ok(is_high)
                }

                fn is_set_low(&self) -> Result<bool, Self::Error> {
                    // NOTE(unsafe) atomic read with no side effects
                    let is_low = unsafe { (*$GPIOX::ptr()).odr.read().bits() & (1 << self.i) == 0 };
                    Ok(is_low)
                }
            }

            impl<MODE> toggleable::Default for $PXx<Output<MODE>> {}

            impl<MODE> InputPin for $PXx<Output<MODE>> {
                type Error = void::Void;

                fn is_high(&self) -> Result<bool, Self::Error> {
                    let is_high = !self.is_low()?;
                    Ok(is_high)
                }

                fn is_low(&self) -> Result<bool, Self::Error> {
                    // NOTE(unsafe) atomic read with no side effects
                    let is_low = unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << self.i) == 0 };
                    Ok(is_low)
                }
            }

            impl<MODE> InputPin for $PXx<Input<MODE>> {
                type Error = void::Void;

                fn is_high(&self) -> Result<bool, Self::Error> {
                    let is_high = !self.is_low()?;
                    Ok(is_high)
                }

                fn is_low(&self) -> Result<bool, Self::Error> {
                    // NOTE(unsafe) atomic read with no side effects
                    let is_low = unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << self.i) == 0 };
                    Ok(is_low)
                }
            }

            $(
                /// Pin
                pub struct $PXi<MODE> {
                    _mode: PhantomData<MODE>,
                }

                impl<MODE> $PXi<MODE> {
                    /// The port this pin is part of.
                    pub const PORT: Port = Port::$PXx;

                    /// The pin's number inside its port.
                    pub const PIN_NUMBER: u8 = $i;

                    /// Returns the port this pin is part of.
                    pub fn port(&self) -> Port {
                        Port::$PXx
                    }

                    /// Returns this pin's number inside its port.
                    pub fn pin_number(&self) -> u8 {
                        $i
                    }
                }

                impl<MODE: PinMode> $PXi<MODE> {
                    /// Puts `self` into mode `M`.
                    ///
                    /// This violates the type state constraints from `MODE`, so callers must
                    /// ensure they use this properly.
                    fn mode<M: PinMode>(&mut self) {
                        let offset = 2 * $i;
                        unsafe {
                            &(*$GPIOX::ptr()).pupdr.modify(|r, w| {
                                w.bits((r.bits() & !(0b11 << offset)) | (u32::from(M::PUPDR) << offset))
                            });

                            if let Some(otyper) = M::OTYPER {
                                &(*$GPIOX::ptr()).otyper.modify(|r, w| {
                                    w.bits(r.bits() & !(0b1 << $i) | (u32::from(otyper) << $i))
                                });
                            }

                            &(*$GPIOX::ptr()).moder.modify(|r, w| {
                                w.bits((r.bits() & !(0b11 << offset)) | (u32::from(M::MODER) << offset))
                            });
                        }
                    }

                    fn with_mode<M, F, R>(
                        &mut self,
                        f: F
                    ) -> R
                    where
                        M: PinMode,
                        F: FnOnce(&mut $PXi<M>) -> R,
                    {
                        struct ResetMode<'a, ORIG: PinMode> {
                            pin: &'a mut $PXi<ORIG>,
                        }

                        impl<'a, ORIG: PinMode> Drop for ResetMode<'a, ORIG> {
                            fn drop(&mut self) {
                                self.pin.mode::<ORIG>();
                            }
                        }

                        self.mode::<M>();

                        // This will reset the pin back to the original mode when dropped.
                        // (so either when `with_mode` returns or when `f` unwinds)
                        let _resetti = ResetMode { pin: self };

                        let mut witness = $PXi {
                            _mode: PhantomData
                        };

                        f(&mut witness)
                    }

                    /// Configures the pin to operate as a floating input pin.
                    pub fn into_floating_input(
                        mut self,
                    ) -> $PXi<Input<Floating>> {
                        self.mode::<Input<Floating>>();
                        $PXi {
                            _mode: PhantomData
                        }
                    }

                    /// Temporarily configures this pin as a floating input.
                    ///
                    /// The closure `f` is called with the reconfigured pin. After it returns,
                    /// the pin will be configured back.
                    pub fn with_floating_input<R>(
                        &mut self,
                        f: impl FnOnce(&mut $PXi<Input<Floating>>) -> R,
                    ) -> R {
                        self.with_mode(f)
                    }

                    /// Configures the pin to operate as a pulled-down input pin.
                    pub fn into_pull_down_input(
                        mut self,
                    ) -> $PXi<Input<PullDown>> {
                        self.mode::<Input<PullDown>>();
                        $PXi {
                            _mode: PhantomData
                        }
                    }

                    /// Temporarily configures this pin as a pulled-down input.
                    ///
                    /// The closure `f` is called with the reconfigured pin. After it returns,
                    /// the pin will be configured back.
                    pub fn with_pull_down_input<R>(
                        &mut self,
                        f: impl FnOnce(&mut $PXi<Input<PullDown>>) -> R,
                    ) -> R {
                        self.with_mode(f)
                    }

                    /// Configures the pin to operate as a pulled-up input pin.
                    pub fn into_pull_up_input(
                        mut self,
                    ) -> $PXi<Input<PullUp>> {
                        self.mode::<Input<PullUp>>();
                        $PXi {
                            _mode: PhantomData
                        }
                    }

                    /// Temporarily configures this pin as a pulled-up input.
                    ///
                    /// The closure `f` is called with the reconfigured pin. After it returns,
                    /// the pin will be configured back.
                    pub fn with_pull_up_input<R>(
                        &mut self,
                        f: impl FnOnce(&mut $PXi<Input<PullUp>>) -> R,
                    ) -> R {
                        self.with_mode(f)
                    }

                    /// Configures the pin to operate as an analog pin.
                    pub fn into_analog(
                        mut self,
                    ) -> $PXi<Analog> {
                        self.mode::<Analog>();
                        $PXi {
                            _mode: PhantomData
                        }
                    }

                    /// Temporarily configures this pin as an analog pin.
                    ///
                    /// The closure `f` is called with the reconfigured pin. After it returns,
                    /// the pin will be configured back.
                    pub fn with_analog<R>(
                        &mut self,
                        f: impl FnOnce(&mut $PXi<Analog>) -> R,
                    ) -> R {
                        self.with_mode(f)
                    }

                    /// Configures the pin to operate as an open drain output pin.
                    pub fn into_open_drain_output(
                        mut self,
                    ) -> $PXi<Output<OpenDrain>> {
                        self.mode::<Output<OpenDrain>>();
                        $PXi {
                            _mode: PhantomData
                        }
                    }

                    /// Temporarily configures this pin as an open drain output.
                    ///
                    /// The closure `f` is called with the reconfigured pin. After it returns,
                    /// the pin will be configured back.
                    pub fn with_open_drain_output<R>(
                        &mut self,
                        f: impl FnOnce(&mut $PXi<Output<OpenDrain>>) -> R,
                    ) -> R {
                        self.with_mode(f)
                    }

                    /// Configures the pin to operate as an push-pull output pin.
                    pub fn into_push_pull_output(
                        mut self,
                    ) -> $PXi<Output<PushPull>> {
                        self.mode::<Output<PushPull>>();
                        $PXi {
                            _mode: PhantomData
                        }
                    }

                    /// Temporarily configures this pin as a push-pull output.
                    ///
                    /// The closure `f` is called with the reconfigured pin. After it returns,
                    /// the pin will be configured back.
                    pub fn with_push_pull_output<R>(
                        &mut self,
                        f: impl FnOnce(&mut $PXi<Output<PushPull>>) -> R,
                    ) -> R {
                        self.with_mode(f)
                    }

                    /// Set pin speed.
                    pub fn set_speed(self, speed: Speed) -> Self {
                        let offset = 2 * $i;
                        unsafe {
                            &(*$GPIOX::ptr()).ospeedr.modify(|r, w| {
                                w.bits((r.bits() & !(0b11 << offset)) | ((speed as u32) << offset))
                            })
                        };
                        self
                    }

                    #[allow(dead_code)]
                    pub(crate) fn set_alt_mode(&self, mode: AltMode) {
                        let mode = mode as u32;
                        let offset = 2 * $i;
                        let offset2 = 4 * $i;
                        unsafe {
                            if offset2 < 32 {
                                &(*$GPIOX::ptr()).afrl.modify(|r, w| {
                                    w.bits((r.bits() & !(0b1111 << offset2)) | (mode << offset2))
                                });
                            } else {
                                let offset2 = offset2 - 32;
                                &(*$GPIOX::ptr()).afrh.modify(|r, w| {
                                    w.bits((r.bits() & !(0b1111 << offset2)) | (mode << offset2))
                                });
                            }
                            &(*$GPIOX::ptr()).moder.modify(|r, w| {
                                w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))
                            });
                        }
                    }
                }

                impl<MODE> $PXi<Output<MODE>> {
                    /// 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 downgrade(self) -> $PXx<Output<MODE>> {
                        $PXx {
                            i: $i,
                            _mode: self._mode,
                        }
                    }
                }

                impl<MODE> OutputPin for $PXi<Output<MODE>> {
                    type Error = void::Void;

                    fn set_high(&mut self) -> Result<(), Self::Error> {
                        // NOTE(unsafe) atomic write to a stateless register
                        unsafe { (*$GPIOX::ptr()).bsrr.write(|w| w.bits(1 << $i)) };
                        Ok(())
                    }

                    fn set_low(&mut self) -> Result<(), Self::Error> {
                        // NOTE(unsafe) atomic write to a stateless register
                        unsafe { (*$GPIOX::ptr()).bsrr.write(|w| w.bits(1 << ($i + 16))) };
                        Ok(())
                    }
                }

                impl<MODE> StatefulOutputPin for $PXi<Output<MODE>> {

                    fn is_set_high(&self) -> Result<bool, Self::Error> {
                        let is_set_high = !self.is_set_low()?;
                        Ok(is_set_high)
                    }

                    fn is_set_low(&self) -> Result<bool, Self::Error> {
                        // NOTE(unsafe) atomic read with no side effects
                        let is_set_low = unsafe { (*$GPIOX::ptr()).odr.read().bits() & (1 << $i) == 0 };
                        Ok(is_set_low)
                    }
                }

                impl<MODE> toggleable::Default for $PXi<Output<MODE>> {}

                impl<MODE> InputPin for $PXi<Output<MODE>> {
                    type Error = void::Void;

                    fn is_high(&self) -> Result<bool, Self::Error> {
                        let is_high = !self.is_low()?;
                        Ok(is_high)
                    }

                    fn is_low(&self) -> Result<bool, Self::Error> {
                        // NOTE(unsafe) atomic read with no side effects
                        let is_low = unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << $i) == 0 };
                        Ok(is_low)
                    }
                }

                impl<MODE> $PXi<Input<MODE>> {
                    /// 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 downgrade(self) -> $PXx<Input<MODE>> {
                        $PXx {
                            i: $i,
                            _mode: self._mode,
                        }
                    }
                }

                impl<MODE> InputPin for $PXi<Input<MODE>> {
                    type Error = void::Void;

                    fn is_high(&self) -> Result<bool, Self::Error> {
                        let is_high = !self.is_low()?;
                        Ok(is_high)
                    }

                    fn is_low(&self) -> Result<bool, Self::Error> {
                        // NOTE(unsafe) atomic read with no side effects
                        let is_low = unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << $i) == 0 };
                        Ok(is_low)
                    }
                }
            )+
        }
    }
}

gpio!(GPIOA, gpioa, iopaen, PA, [
    PA0: (pa0, 0, Analog),
    PA1: (pa1, 1, Analog),
    PA2: (pa2, 2, Analog),
    PA3: (pa3, 3, Analog),
    PA4: (pa4, 4, Analog),
    PA5: (pa5, 5, Analog),
    PA6: (pa6, 6, Analog),
    PA7: (pa7, 7, Analog),
    PA8: (pa8, 8, Analog),
    PA9: (pa9, 9, Analog),
    PA10: (pa10, 10, Analog),
    PA11: (pa11, 11, Analog),
    PA12: (pa12, 12, Analog),
    PA13: (pa13, 13, Analog),
    PA14: (pa14, 14, Analog),
    PA15: (pa15, 15, Analog),
]);

gpio!(GPIOB, gpiob, iopben, PB, [
    PB0: (pb0, 0, Analog),
    PB1: (pb1, 1, Analog),
    PB2: (pb2, 2, Analog),
    PB3: (pb3, 3, Analog),
    PB4: (pb4, 4, Analog),
    PB5: (pb5, 5, Analog),
    PB6: (pb6, 6, Analog),
    PB7: (pb7, 7, Analog),
    PB8: (pb8, 8, Analog),
    PB9: (pb9, 9, Analog),
    PB10: (pb10, 10, Analog),
    PB11: (pb11, 11, Analog),
    PB12: (pb12, 12, Analog),
    PB13: (pb13, 13, Analog),
    PB14: (pb14, 14, Analog),
    PB15: (pb15, 15, Analog),
]);

gpio!(GPIOC, gpioc, iopcen, PC, [
    PC0: (pc0, 0, Analog),
    PC1: (pc1, 1, Analog),
    PC2: (pc2, 2, Analog),
    PC3: (pc3, 3, Analog),
    PC4: (pc4, 4, Analog),
    PC5: (pc5, 5, Analog),
    PC6: (pc6, 6, Analog),
    PC7: (pc7, 7, Analog),
    PC8: (pc8, 8, Analog),
    PC9: (pc9, 9, Analog),
    PC10: (pc10, 10, Analog),
    PC11: (pc11, 11, Analog),
    PC12: (pc12, 12, Analog),
    PC13: (pc13, 13, Analog),
    PC14: (pc14, 14, Analog),
    PC15: (pc15, 15, Analog),
]);

gpio!(GPIOD, gpiod, iopden, PD, [
    PD0: (pd0, 0, Analog),
    PD1: (pd1, 1, Analog),
    PD2: (pd2, 2, Analog),
    PD3: (pd3, 3, Analog),
    PD4: (pd4, 4, Analog),
    PD5: (pd5, 5, Analog),
    PD6: (pd6, 6, Analog),
    PD7: (pd7, 7, Analog),
    PD8: (pd8, 8, Analog),
    PD9: (pd9, 9, Analog),
    PD10: (pd10, 10, Analog),
    PD11: (pd11, 11, Analog),
    PD12: (pd12, 12, Analog),
    PD13: (pd13, 13, Analog),
    PD14: (pd14, 14, Analog),
    PD15: (pd15, 15, Analog),
]);

gpio!(GPIOE, gpioe, iopeen, PE, [
    PE0:  (pe0,  0,  Analog),
    PE1:  (pe1,  1,  Analog),
    PE2:  (pe2,  2,  Analog),
    PE3:  (pe3,  3,  Analog),
    PE4:  (pe4,  4,  Analog),
    PE5:  (pe5,  5,  Analog),
    PE6:  (pe6,  6,  Analog),
    PE7:  (pe7,  7,  Analog),
    PE8:  (pe8,  8,  Analog),
    PE9:  (pe9,  9,  Analog),
    PE10: (pe10, 10, Analog),
    PE11: (pe11, 11, Analog),
    PE12: (pe12, 12, Analog),
    PE13: (pe13, 13, Analog),
    PE14: (pe14, 14, Analog),
    PE15: (pe15, 15, Analog),
]);

gpio!(GPIOH, gpioh, iophen, PH, [
    PH0: (ph0, 0, Analog),
    PH1: (ph1, 1, Analog),
    PH9: (ph9, 9, Analog),
    PH10: (ph10, 10, Analog),
]);