@@ -161,6 +161,22 @@ pub mod marker {
161161
162162 /// Marker trait for active pin modes
163163 pub trait Active { }
164+
165+ macro_rules! af_marker_trait {
166+ ( [ $( $i: literal) ,+ $( , ) ?] ) => {
167+ paste:: paste! {
168+ $(
169+ #[ doc = "Marker trait for pins with alternate function " $i " mapping" ]
170+ pub trait [ <IntoAf $i>] {
171+ /// Associated AFR register
172+ type AFR : super :: Afr ;
173+ }
174+ ) +
175+ }
176+ } ;
177+ }
178+
179+ af_marker_trait ! ( [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ] ) ;
164180}
165181
166182/// Runtime defined GPIO port (type state)
@@ -618,22 +634,14 @@ where
618634
619635macro_rules! af {
620636 ( $i: literal, $Ui: ty, $AFi: ident, $IntoAfi: ident, $into_afi_push_pull: ident, $into_afi_open_drain: ident) => {
621- paste:: paste! {
622- #[ doc = "Marker trait for pins with alternate function " $i " mapping" ]
623- pub trait $IntoAfi {
624- /// Associated AFR register
625- type AFR : Afr ;
626- }
627- }
628-
629637 paste:: paste! {
630638 #[ doc = "Alternate function " $i " (type state)" ]
631639 pub type $AFi<Otype > = Alternate <$Ui, Otype >;
632640 }
633641
634642 impl <Gpio , Index , Mode > Pin <Gpio , Index , Mode >
635643 where
636- Self : $IntoAfi,
644+ Self : marker :: $IntoAfi,
637645 Gpio : marker:: GpioStatic ,
638646 Index : marker:: Index ,
639647 {
@@ -642,7 +650,7 @@ macro_rules! af {
642650 self ,
643651 moder: & mut Gpio :: MODER ,
644652 otyper: & mut Gpio :: OTYPER ,
645- afr: & mut <Self as $IntoAfi>:: AFR ,
653+ afr: & mut <Self as marker :: $IntoAfi>:: AFR ,
646654 ) -> Pin <Gpio , Index , $AFi<PushPull >> {
647655 moder. alternate( self . index. index( ) ) ;
648656 otyper. push_pull( self . index. index( ) ) ;
@@ -655,7 +663,7 @@ macro_rules! af {
655663 self ,
656664 moder: & mut Gpio :: MODER ,
657665 otyper: & mut Gpio :: OTYPER ,
658- afr: & mut <Self as $IntoAfi>:: AFR ,
666+ afr: & mut <Self as marker :: $IntoAfi>:: AFR ,
659667 ) -> Pin <Gpio , Index , $AFi<OpenDrain >> {
660668 moder. alternate( self . index. index( ) ) ;
661669 otyper. open_drain( self . index. index( ) ) ;
@@ -706,6 +714,7 @@ macro_rules! gpio_trait {
706714 } ;
707715}
708716
717+ /// Implement private::{Moder, Ospeedr, Otyper, Pupdr} traits for each opaque register structs
709718macro_rules! r_trait {
710719 (
711720 ( $GPIOX: ident, $gpioy: ident:: $xr: ident:: $enum: ident, $bitwidth: expr) ;
@@ -781,13 +790,11 @@ macro_rules! gpio {
781790 rcc:: AHB ,
782791 } ;
783792
784- use super :: { Afr , $Gpiox, GpioExt , Moder , Ospeedr , Otyper , Pin , Pupdr , Ux } ;
793+ use super :: { marker , Afr , $Gpiox, GpioExt , Moder , Ospeedr , Otyper , Pin , Pupdr , Ux } ;
785794
786795 #[ allow( unused_imports) ]
787796 use super :: {
788797 Input , Output , Analog , PushPull , OpenDrain ,
789- IntoAf0 , IntoAf1 , IntoAf2 , IntoAf3 , IntoAf4 , IntoAf5 , IntoAf6 , IntoAf7 ,
790- IntoAf8 , IntoAf9 , IntoAf10 , IntoAf11 , IntoAf12 , IntoAf13 , IntoAf14 , IntoAf15 ,
791798 AF0 , AF1 , AF2 , AF3 , AF4 , AF5 , AF6 , AF7 , AF8 , AF9 , AF10 , AF11 , AF12 , AF13 , AF14 , AF15 ,
792799 } ;
793800
@@ -920,7 +927,7 @@ macro_rules! gpio {
920927 pub type $PXi<Mode > = Pin <$Gpiox, $Ui, Mode >;
921928
922929 $(
923- impl <Mode > $IntoAfi for $PXi<Mode > {
930+ impl <Mode > marker :: $IntoAfi for $PXi<Mode > {
924931 type AFR = $AFR;
925932 }
926933 ) *
0 commit comments