@@ -72,8 +72,6 @@ use crate::{
7272#[ cfg( feature = "unproven" ) ]
7373use crate :: hal:: digital:: v2:: { toggleable, InputPin , StatefulOutputPin } ;
7474
75- use typenum:: { Unsigned , U0 , U1 , U10 , U11 , U12 , U13 , U14 , U15 , U2 , U3 , U4 , U5 , U6 , U7 , U8 , U9 } ;
76-
7775/// Extension trait to split a GPIO peripheral in independent pins and registers
7876pub trait GpioExt {
7977 /// The Parts to split the GPIO peripheral into
@@ -208,13 +206,13 @@ impl marker::Index for Ux {
208206 }
209207}
210208
211- impl < U > marker :: Index for U
212- where
213- U : Unsigned ,
214- {
209+ /// Compile time defined pin number (type state)
210+ pub struct U < const X : u8 > ;
211+
212+ impl < const X : u8 > marker :: Index for U < X > {
215213 #[ inline( always) ]
216214 fn index ( & self ) -> u8 {
217- Self :: U8
215+ X
218216 }
219217}
220218
@@ -223,7 +221,7 @@ pub struct Input;
223221/// Output mode (type state)
224222pub struct Output < Otype > ( PhantomData < Otype > ) ;
225223/// Alternate function (type state)
226- pub struct Alternate < Af , Otype > ( PhantomData < Af > , PhantomData < Otype > ) ;
224+ pub struct Alternate < Otype , const AF : u8 > ( PhantomData < Otype > ) ;
227225/// Analog mode (type state)
228226pub struct Analog ;
229227
@@ -235,10 +233,10 @@ pub struct OpenDrain;
235233impl marker:: Readable for Input { }
236234impl marker:: Readable for Output < OpenDrain > { }
237235impl < Otype > marker:: OutputSpeed for Output < Otype > { }
238- impl < Af , Otype > marker:: OutputSpeed for Alternate < Af , Otype > { }
236+ impl < Otype , const AF : u8 > marker:: OutputSpeed for Alternate < Otype , AF > { }
239237impl marker:: Active for Input { }
240238impl < Otype > marker:: Active for Output < Otype > { }
241- impl < Af , Otype > marker:: Active for Alternate < Af , Otype > { }
239+ impl < Otype , const AF : u8 > marker:: Active for Alternate < Otype , AF > { }
242240
243241/// Slew rate configuration
244242pub enum Speed {
@@ -299,18 +297,15 @@ macro_rules! modify_at {
299297 } ;
300298}
301299
302- impl < Gpio , Index , Mode > Pin < Gpio , Index , Mode >
303- where
304- Index : Unsigned ,
305- {
300+ impl < Gpio , Mode , const X : u8 > Pin < Gpio , U < X > , Mode > {
306301 /// Erases the pin number from the type
307302 ///
308303 /// This is useful when you want to collect the pins into an array where you
309304 /// need all the elements to have the same type
310305 pub fn downgrade ( self ) -> Pin < Gpio , Ux , Mode > {
311306 Pin {
312307 gpio : self . gpio ,
313- index : Ux ( Index :: U8 ) ,
308+ index : Ux ( X ) ,
314309 _mode : self . _mode ,
315310 }
316311 }
@@ -633,10 +628,10 @@ where
633628}
634629
635630macro_rules! af {
636- ( $i: literal, $Ui : ty , $ AFi: ident, $IntoAfi: ident, $into_afi_push_pull: ident, $into_afi_open_drain: ident) => {
631+ ( $i: literal, $AFi: ident, $IntoAfi: ident, $into_afi_push_pull: ident, $into_afi_open_drain: ident) => {
637632 paste:: paste! {
638633 #[ doc = "Alternate function " $i " (type state)" ]
639- pub type $AFi<Otype > = Alternate <$Ui , Otype >;
634+ pub type $AFi<Otype > = Alternate <Otype , $i >;
640635 }
641636
642637 impl <Gpio , Index , Mode > Pin <Gpio , Index , Mode >
@@ -676,7 +671,7 @@ macro_rules! af {
676671 ( [ $( $i: literal) ,+ $( , ) ?] ) => {
677672 paste:: paste! {
678673 $(
679- af!( $i, [ <U $i> ] , [ < AF $i>] , [ <IntoAf $i>] , [ <into_af $i _push_pull>] , [ <into_af $i _open_drain>] ) ;
674+ af!( $i, [ <AF $i>] , [ <IntoAf $i>] , [ <into_af $i _push_pull>] , [ <into_af $i _open_drain>] ) ;
680675 ) +
681676 }
682677 } ;
@@ -746,11 +741,11 @@ macro_rules! gpio {
746741 iopen: $iopxen: ident,
747742 ioprst: $iopxrst: ident,
748743 partially_erased_pin: $PXx: ty,
749- pins: { $(
750- $PXi : ty : (
751- $pxi : ident , $Ui : ty , $MODE: ty, $AFR: ident, [ $( $IntoAfi: ident) ,* ] ,
744+ pins: [ $(
745+ $i : literal => (
746+ $PXi : ty , $pxi : ident , $MODE: ty, $AFR: ident, [ $( $IntoAfi: ident) ,* ] ,
752747 ) ,
753- ) +} ,
748+ ) +] ,
754749 } ) => {
755750 paste:: paste!{
756751 #[ doc = "GPIO port " $GPIOX " (type state)" ]
@@ -790,19 +785,14 @@ macro_rules! gpio {
790785 rcc:: AHB ,
791786 } ;
792787
793- use super :: { marker, Afr , $Gpiox, GpioExt , Moder , Ospeedr , Otyper , Pin , Pupdr , Ux } ;
788+ use super :: { marker, Afr , $Gpiox, GpioExt , Moder , Ospeedr , Otyper , Pin , Pupdr , U , Ux } ;
794789
795790 #[ allow( unused_imports) ]
796791 use super :: {
797792 Input , Output , Analog , PushPull , OpenDrain ,
798793 AF0 , AF1 , AF2 , AF3 , AF4 , AF5 , AF6 , AF7 , AF8 , AF9 , AF10 , AF11 , AF12 , AF13 , AF14 , AF15 ,
799794 } ;
800795
801- #[ allow( unused_imports) ]
802- use typenum:: {
803- U0 , U1 , U2 , U3 , U4 , U5 , U6 , U7 , U8 , U9 , U10 , U11 , U12 , U13 , U14 , U15
804- } ;
805-
806796 /// GPIO parts
807797 pub struct Parts {
808798 /// Opaque AFRH register
@@ -841,7 +831,7 @@ macro_rules! gpio {
841831 $(
842832 $pxi: $PXi {
843833 gpio: $Gpiox,
844- index: $Ui :: new ( ) ,
834+ index: U :: <$i> ,
845835 _mode: PhantomData ,
846836 } ,
847837 ) +
@@ -924,7 +914,7 @@ macro_rules! gpio {
924914
925915 $(
926916 #[ doc = "Pin " $PXi]
927- pub type $PXi<Mode > = Pin <$Gpiox, $Ui , Mode >;
917+ pub type $PXi<Mode > = Pin <$Gpiox, U <$i> , Mode >;
928918
929919 $(
930920 impl <Mode > marker:: $IntoAfi for $PXi<Mode > {
@@ -963,11 +953,11 @@ macro_rules! gpio {
963953 iopen: [ <iop $x en>] ,
964954 ioprst: [ <iop $x rst>] ,
965955 partially_erased_pin: [ <P $X x>] ,
966- pins: { $(
967- [ < P $X $i> ] : (
968- [ <p $x $i>] , [ <U $i>] , $MODE, [ <AFR $LH>] , [ $( [ <IntoAf $af>] ) ,* ] ,
956+ pins: [ $(
957+ $i => (
958+ [ <P $X $i>] , [ <p $x $i>] , $MODE, [ <AFR $LH>] , [ $( [ <IntoAf $af>] ) ,* ] ,
969959 ) ,
970- ) +} ,
960+ ) +] ,
971961 } ) ;
972962 ) +
973963 }
0 commit comments