@@ -72,8 +72,6 @@ use crate::{
72
72
#[ cfg( feature = "unproven" ) ]
73
73
use crate :: hal:: digital:: v2:: { toggleable, InputPin , StatefulOutputPin } ;
74
74
75
- use typenum:: { Unsigned , U0 , U1 , U10 , U11 , U12 , U13 , U14 , U15 , U2 , U3 , U4 , U5 , U6 , U7 , U8 , U9 } ;
76
-
77
75
/// Extension trait to split a GPIO peripheral in independent pins and registers
78
76
pub trait GpioExt {
79
77
/// The Parts to split the GPIO peripheral into
@@ -208,13 +206,13 @@ impl marker::Index for Ux {
208
206
}
209
207
}
210
208
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 > {
215
213
#[ inline( always) ]
216
214
fn index ( & self ) -> u8 {
217
- Self :: U8
215
+ X
218
216
}
219
217
}
220
218
@@ -223,7 +221,7 @@ pub struct Input;
223
221
/// Output mode (type state)
224
222
pub struct Output < Otype > ( PhantomData < Otype > ) ;
225
223
/// Alternate function (type state)
226
- pub struct Alternate < Af , Otype > ( PhantomData < Af > , PhantomData < Otype > ) ;
224
+ pub struct Alternate < Otype , const AF : u8 > ( PhantomData < Otype > ) ;
227
225
/// Analog mode (type state)
228
226
pub struct Analog ;
229
227
@@ -235,10 +233,10 @@ pub struct OpenDrain;
235
233
impl marker:: Readable for Input { }
236
234
impl marker:: Readable for Output < OpenDrain > { }
237
235
impl < 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 > { }
239
237
impl marker:: Active for Input { }
240
238
impl < 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 > { }
242
240
243
241
/// Slew rate configuration
244
242
pub enum Speed {
@@ -299,18 +297,15 @@ macro_rules! modify_at {
299
297
} ;
300
298
}
301
299
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 > {
306
301
/// Erases the pin number from the type
307
302
///
308
303
/// This is useful when you want to collect the pins into an array where you
309
304
/// need all the elements to have the same type
310
305
pub fn downgrade ( self ) -> Pin < Gpio , Ux , Mode > {
311
306
Pin {
312
307
gpio : self . gpio ,
313
- index : Ux ( Index :: U8 ) ,
308
+ index : Ux ( X ) ,
314
309
_mode : self . _mode ,
315
310
}
316
311
}
@@ -633,10 +628,10 @@ where
633
628
}
634
629
635
630
macro_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) => {
637
632
paste:: paste! {
638
633
#[ doc = "Alternate function " $i " (type state)" ]
639
- pub type $AFi<Otype > = Alternate <$Ui , Otype >;
634
+ pub type $AFi<Otype > = Alternate <Otype , $i >;
640
635
}
641
636
642
637
impl <Gpio , Index , Mode > Pin <Gpio , Index , Mode >
@@ -676,7 +671,7 @@ macro_rules! af {
676
671
( [ $( $i: literal) ,+ $( , ) ?] ) => {
677
672
paste:: paste! {
678
673
$(
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>] ) ;
680
675
) +
681
676
}
682
677
} ;
@@ -746,11 +741,11 @@ macro_rules! gpio {
746
741
iopen: $iopxen: ident,
747
742
ioprst: $iopxrst: ident,
748
743
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) ,* ] ,
752
747
) ,
753
- ) +} ,
748
+ ) +] ,
754
749
} ) => {
755
750
paste:: paste!{
756
751
#[ doc = "GPIO port " $GPIOX " (type state)" ]
@@ -790,19 +785,14 @@ macro_rules! gpio {
790
785
rcc:: AHB ,
791
786
} ;
792
787
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 } ;
794
789
795
790
#[ allow( unused_imports) ]
796
791
use super :: {
797
792
Input , Output , Analog , PushPull , OpenDrain ,
798
793
AF0 , AF1 , AF2 , AF3 , AF4 , AF5 , AF6 , AF7 , AF8 , AF9 , AF10 , AF11 , AF12 , AF13 , AF14 , AF15 ,
799
794
} ;
800
795
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
-
806
796
/// GPIO parts
807
797
pub struct Parts {
808
798
/// Opaque AFRH register
@@ -841,7 +831,7 @@ macro_rules! gpio {
841
831
$(
842
832
$pxi: $PXi {
843
833
gpio: $Gpiox,
844
- index: $Ui :: new ( ) ,
834
+ index: U :: <$i> ,
845
835
_mode: PhantomData ,
846
836
} ,
847
837
) +
@@ -924,7 +914,7 @@ macro_rules! gpio {
924
914
925
915
$(
926
916
#[ doc = "Pin " $PXi]
927
- pub type $PXi<Mode > = Pin <$Gpiox, $Ui , Mode >;
917
+ pub type $PXi<Mode > = Pin <$Gpiox, U <$i> , Mode >;
928
918
929
919
$(
930
920
impl <Mode > marker:: $IntoAfi for $PXi<Mode > {
@@ -963,11 +953,11 @@ macro_rules! gpio {
963
953
iopen: [ <iop $x en>] ,
964
954
ioprst: [ <iop $x rst>] ,
965
955
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>] ) ,* ] ,
969
959
) ,
970
- ) +} ,
960
+ ) +] ,
971
961
} ) ;
972
962
) +
973
963
}
0 commit comments