@@ -205,12 +205,12 @@ where
205
205
}
206
206
207
207
/// Partially erased pin
208
- pub struct PXx < MODE , const P : u8 > {
208
+ pub struct PXx < MODE , const P : char > {
209
209
i : u8 ,
210
210
_mode : PhantomData < MODE > ,
211
211
}
212
212
213
- impl < MODE , const P : u8 > PinExt for PXx < MODE , P > {
213
+ impl < MODE , const P : char > PinExt for PXx < MODE , P > {
214
214
type Mode = MODE ;
215
215
216
216
#[ inline( always) ]
@@ -219,11 +219,11 @@ impl<MODE, const P: u8> PinExt for PXx<MODE, P> {
219
219
}
220
220
#[ inline( always) ]
221
221
fn port_id ( & self ) -> u8 {
222
- P
222
+ P as u8 - 0x41
223
223
}
224
224
}
225
225
226
- impl < MODE , const P : u8 > OutputPin for PXx < Output < MODE > , P > {
226
+ impl < MODE , const P : char > OutputPin for PXx < Output < MODE > , P > {
227
227
type Error = Infallible ;
228
228
229
229
fn set_high ( & mut self ) -> Result < ( ) , Self :: Error > {
@@ -243,7 +243,7 @@ impl<MODE, const P: u8> OutputPin for PXx<Output<MODE>, P> {
243
243
}
244
244
}
245
245
246
- impl < MODE , const P : u8 > StatefulOutputPin for PXx < Output < MODE > , P > {
246
+ impl < MODE , const P : char > StatefulOutputPin for PXx < Output < MODE > , P > {
247
247
fn is_set_high ( & self ) -> Result < bool , Self :: Error > {
248
248
self . is_set_low ( ) . map ( |v| !v)
249
249
}
@@ -254,9 +254,9 @@ impl<MODE, const P: u8> StatefulOutputPin for PXx<Output<MODE>, P> {
254
254
}
255
255
}
256
256
257
- impl < MODE , const P : u8 > toggleable:: Default for PXx < Output < MODE > , P > { }
257
+ impl < MODE , const P : char > toggleable:: Default for PXx < Output < MODE > , P > { }
258
258
259
- impl < const P : u8 > InputPin for PXx < Output < OpenDrain > , P > {
259
+ impl < const P : char > InputPin for PXx < Output < OpenDrain > , P > {
260
260
type Error = Infallible ;
261
261
262
262
fn is_high ( & self ) -> Result < bool , Self :: Error > {
@@ -269,7 +269,7 @@ impl<const P: u8> InputPin for PXx<Output<OpenDrain>, P> {
269
269
}
270
270
}
271
271
272
- impl < MODE , const P : u8 > InputPin for PXx < Input < MODE > , P > {
272
+ impl < MODE , const P : char > InputPin for PXx < Input < MODE > , P > {
273
273
type Error = Infallible ;
274
274
275
275
fn is_high ( & self ) -> Result < bool , Self :: Error > {
@@ -282,7 +282,7 @@ impl<MODE, const P: u8> InputPin for PXx<Input<MODE>, P> {
282
282
}
283
283
}
284
284
285
- fn _set_alternate_mode < const P : u8 , const N : u8 , const A : u8 > ( ) {
285
+ fn _set_alternate_mode < const P : char , const N : u8 , const A : u8 > ( ) {
286
286
let offset = 2 * { N } ;
287
287
let offset2 = 4 * { N } ;
288
288
let mode = A as u32 ;
@@ -304,16 +304,16 @@ fn _set_alternate_mode<const P: u8, const N: u8, const A: u8>() {
304
304
}
305
305
306
306
/// Pin
307
- pub struct PX < MODE , const P : u8 , const N : u8 > {
307
+ pub struct PX < MODE , const P : char , const N : u8 > {
308
308
_mode : PhantomData < MODE > ,
309
309
}
310
- impl < MODE , const P : u8 , const N : u8 > PX < MODE , P , N > {
310
+ impl < MODE , const P : char , const N : u8 > PX < MODE , P , N > {
311
311
const fn new ( ) -> Self {
312
312
Self { _mode : PhantomData }
313
313
}
314
314
}
315
315
316
- impl < MODE , const P : u8 , const N : u8 > PinExt for PX < MODE , P , N > {
316
+ impl < MODE , const P : char , const N : u8 > PinExt for PX < MODE , P , N > {
317
317
type Mode = MODE ;
318
318
319
319
#[ inline( always) ]
@@ -322,11 +322,11 @@ impl<MODE, const P: u8, const N: u8> PinExt for PX<MODE, P, N> {
322
322
}
323
323
#[ inline( always) ]
324
324
fn port_id ( & self ) -> u8 {
325
- P
325
+ P as u8 - 0x41
326
326
}
327
327
}
328
328
329
- impl < MODE , const P : u8 , const N : u8 > PX < MODE , P , N > {
329
+ impl < MODE , const P : char , const N : u8 > PX < MODE , P , N > {
330
330
/// Configures the pin to operate alternate mode
331
331
pub fn into_alternate < const A : u8 > ( self ) -> PX < Alternate < AF < A > > , P , N > {
332
332
less_than_16 :: < A > ( ) ;
@@ -663,7 +663,7 @@ impl<MODE, const P: u8, const N: u8> PX<MODE, P, N> {
663
663
}
664
664
}
665
665
666
- impl < MODE , const P : u8 , const N : u8 > PX < Output < MODE > , P , N > {
666
+ impl < MODE , const P : char , const N : u8 > PX < Output < MODE > , P , N > {
667
667
/// Set pin speed
668
668
pub fn set_speed ( self , speed : Speed ) -> Self {
669
669
let offset = 2 * { N } ;
@@ -678,7 +678,7 @@ impl<MODE, const P: u8, const N: u8> PX<Output<MODE>, P, N> {
678
678
}
679
679
}
680
680
681
- impl < const P : u8 , const N : u8 > PX < Output < OpenDrain > , P , N > {
681
+ impl < const P : char , const N : u8 > PX < Output < OpenDrain > , P , N > {
682
682
/// Enables / disables the internal pull up
683
683
pub fn internal_pull_up ( & mut self , on : bool ) {
684
684
let offset = 2 * { N } ;
@@ -691,7 +691,7 @@ impl<const P: u8, const N: u8> PX<Output<OpenDrain>, P, N> {
691
691
}
692
692
}
693
693
694
- impl < MODE , const P : u8 , const N : u8 > PX < Alternate < MODE > , P , N > {
694
+ impl < MODE , const P : char , const N : u8 > PX < Alternate < MODE > , P , N > {
695
695
/// Set pin speed
696
696
pub fn set_speed ( self , speed : Speed ) -> Self {
697
697
let offset = 2 * { N } ;
@@ -719,7 +719,7 @@ impl<MODE, const P: u8, const N: u8> PX<Alternate<MODE>, P, N> {
719
719
}
720
720
}
721
721
722
- impl < MODE , const P : u8 , const N : u8 > PX < Alternate < MODE > , P , N > {
722
+ impl < MODE , const P : char , const N : u8 > PX < Alternate < MODE > , P , N > {
723
723
/// Turns pin alternate configuration pin into open drain
724
724
pub fn set_open_drain ( self ) -> PX < AlternateOD < MODE > , P , N > {
725
725
let offset = { N } ;
@@ -733,7 +733,7 @@ impl<MODE, const P: u8, const N: u8> PX<Alternate<MODE>, P, N> {
733
733
}
734
734
}
735
735
736
- impl < MODE , const P : u8 , const N : u8 > PX < MODE , P , N > {
736
+ impl < MODE , const P : char , const N : u8 > PX < MODE , P , N > {
737
737
/// Erases the pin number from the type
738
738
///
739
739
/// This is useful when you want to collect the pins into an array where you
@@ -750,11 +750,11 @@ impl<MODE, const P: u8, const N: u8> PX<MODE, P, N> {
750
750
/// This is useful when you want to collect the pins into an array where you
751
751
/// need all the elements to have the same type
752
752
pub fn downgrade2 ( self ) -> Pin < MODE > {
753
- Pin :: new ( P , N )
753
+ Pin :: new ( P as u8 - 0x41 , N )
754
754
}
755
755
}
756
756
757
- impl < MODE , const P : u8 , const N : u8 > OutputPin for PX < Output < MODE > , P , N > {
757
+ impl < MODE , const P : char , const N : u8 > OutputPin for PX < Output < MODE > , P , N > {
758
758
type Error = Infallible ;
759
759
760
760
fn set_high ( & mut self ) -> Result < ( ) , Self :: Error > {
@@ -774,7 +774,7 @@ impl<MODE, const P: u8, const N: u8> OutputPin for PX<Output<MODE>, P, N> {
774
774
}
775
775
}
776
776
777
- impl < MODE , const P : u8 , const N : u8 > StatefulOutputPin for PX < Output < MODE > , P , N > {
777
+ impl < MODE , const P : char , const N : u8 > StatefulOutputPin for PX < Output < MODE > , P , N > {
778
778
fn is_set_high ( & self ) -> Result < bool , Self :: Error > {
779
779
self . is_set_low ( ) . map ( |v| !v)
780
780
}
@@ -785,9 +785,9 @@ impl<MODE, const P: u8, const N: u8> StatefulOutputPin for PX<Output<MODE>, P, N
785
785
}
786
786
}
787
787
788
- impl < MODE , const P : u8 , const N : u8 > toggleable:: Default for PX < Output < MODE > , P , N > { }
788
+ impl < MODE , const P : char , const N : u8 > toggleable:: Default for PX < Output < MODE > , P , N > { }
789
789
790
- impl < const P : u8 , const N : u8 > InputPin for PX < Output < OpenDrain > , P , N > {
790
+ impl < const P : char , const N : u8 > InputPin for PX < Output < OpenDrain > , P , N > {
791
791
type Error = Infallible ;
792
792
793
793
fn is_high ( & self ) -> Result < bool , Self :: Error > {
@@ -800,7 +800,7 @@ impl<const P: u8, const N: u8> InputPin for PX<Output<OpenDrain>, P, N> {
800
800
}
801
801
}
802
802
803
- impl < MODE , const P : u8 , const N : u8 > InputPin for PX < Input < MODE > , P , N > {
803
+ impl < MODE , const P : char , const N : u8 > InputPin for PX < Input < MODE > , P , N > {
804
804
type Error = Infallible ;
805
805
806
806
fn is_high ( & self ) -> Result < bool , Self :: Error > {
@@ -862,7 +862,7 @@ macro_rules! gpio {
862
862
}
863
863
}
864
864
865
- gpio ! ( GPIOA , gpioa, PA , 0 , PAn , [
865
+ gpio ! ( GPIOA , gpioa, PA , 'A' , PAn , [
866
866
PA0 : ( pa0, 0 , Input <Floating >) ,
867
867
PA1 : ( pa1, 1 , Input <Floating >) ,
868
868
PA2 : ( pa2, 2 , Input <Floating >) ,
@@ -881,7 +881,7 @@ gpio!(GPIOA, gpioa, PA, 0, PAn, [
881
881
PA15 : ( pa15, 15 , Input <Floating >) ,
882
882
] ) ;
883
883
884
- gpio ! ( GPIOB , gpiob, PB , 1 , PBn , [
884
+ gpio ! ( GPIOB , gpiob, PB , 'B' , PBn , [
885
885
PB0 : ( pb0, 0 , Input <Floating >) ,
886
886
PB1 : ( pb1, 1 , Input <Floating >) ,
887
887
PB2 : ( pb2, 2 , Input <Floating >) ,
@@ -900,7 +900,7 @@ gpio!(GPIOB, gpiob, PB, 1, PBn, [
900
900
PB15 : ( pb15, 15 , Input <Floating >) ,
901
901
] ) ;
902
902
903
- gpio ! ( GPIOC , gpioc, PC , 2 , PCn , [
903
+ gpio ! ( GPIOC , gpioc, PC , 'C' , PCn , [
904
904
PC0 : ( pc0, 0 , Input <Floating >) ,
905
905
PC1 : ( pc1, 1 , Input <Floating >) ,
906
906
PC2 : ( pc2, 2 , Input <Floating >) ,
@@ -920,7 +920,7 @@ gpio!(GPIOC, gpioc, PC, 2, PCn, [
920
920
] ) ;
921
921
922
922
#[ cfg( feature = "gpiod" ) ]
923
- gpio ! ( GPIOD , gpiod, PD , 3 , PDn , [
923
+ gpio ! ( GPIOD , gpiod, PD , 'D' , PDn , [
924
924
PD0 : ( pd0, 0 , Input <Floating >) ,
925
925
PD1 : ( pd1, 1 , Input <Floating >) ,
926
926
PD2 : ( pd2, 2 , Input <Floating >) ,
@@ -940,7 +940,7 @@ gpio!(GPIOD, gpiod, PD, 3, PDn, [
940
940
] ) ;
941
941
942
942
#[ cfg( feature = "gpioe" ) ]
943
- gpio ! ( GPIOE , gpioe, PE , 4 , PEn , [
943
+ gpio ! ( GPIOE , gpioe, PE , 'E' , PEn , [
944
944
PE0 : ( pe0, 0 , Input <Floating >) ,
945
945
PE1 : ( pe1, 1 , Input <Floating >) ,
946
946
PE2 : ( pe2, 2 , Input <Floating >) ,
@@ -960,7 +960,7 @@ gpio!(GPIOE, gpioe, PE, 4, PEn, [
960
960
] ) ;
961
961
962
962
#[ cfg( feature = "gpiof" ) ]
963
- gpio ! ( GPIOF , gpiof, PF , 5 , PFn , [
963
+ gpio ! ( GPIOF , gpiof, PF , 'F' , PFn , [
964
964
PF0 : ( pf0, 0 , Input <Floating >) ,
965
965
PF1 : ( pf1, 1 , Input <Floating >) ,
966
966
PF2 : ( pf2, 2 , Input <Floating >) ,
@@ -980,7 +980,7 @@ gpio!(GPIOF, gpiof, PF, 5, PFn, [
980
980
] ) ;
981
981
982
982
#[ cfg( feature = "gpiog" ) ]
983
- gpio ! ( GPIOG , gpiog, PG , 6 , PGn , [
983
+ gpio ! ( GPIOG , gpiog, PG , 'G' , PGn , [
984
984
PG0 : ( pg0, 0 , Input <Floating >) ,
985
985
PG1 : ( pg1, 1 , Input <Floating >) ,
986
986
PG2 : ( pg2, 2 , Input <Floating >) ,
@@ -1000,7 +1000,7 @@ gpio!(GPIOG, gpiog, PG, 6, PGn, [
1000
1000
] ) ;
1001
1001
1002
1002
#[ cfg( not( feature = "stm32f401" ) ) ]
1003
- gpio ! ( GPIOH , gpioh, PH , 7 , PHn , [
1003
+ gpio ! ( GPIOH , gpioh, PH , 'H' , PHn , [
1004
1004
PH0 : ( ph0, 0 , Input <Floating >) ,
1005
1005
PH1 : ( ph1, 1 , Input <Floating >) ,
1006
1006
PH2 : ( ph2, 2 , Input <Floating >) ,
@@ -1020,13 +1020,13 @@ gpio!(GPIOH, gpioh, PH, 7, PHn, [
1020
1020
] ) ;
1021
1021
1022
1022
#[ cfg( feature = "stm32f401" ) ]
1023
- gpio ! ( GPIOH , gpioh, PH , 7 , PHn , [
1023
+ gpio ! ( GPIOH , gpioh, PH , 'H' , PHn , [
1024
1024
PH0 : ( ph0, 0 , Input <Floating >) ,
1025
1025
PH1 : ( ph1, 1 , Input <Floating >) ,
1026
1026
] ) ;
1027
1027
1028
1028
#[ cfg( feature = "gpioi" ) ]
1029
- gpio ! ( GPIOI , gpioi, PI , 8 , PIn , [
1029
+ gpio ! ( GPIOI , gpioi, PI , 'I' , PIn , [
1030
1030
PI0 : ( pi0, 0 , Input <Floating >) ,
1031
1031
PI1 : ( pi1, 1 , Input <Floating >) ,
1032
1032
PI2 : ( pi2, 2 , Input <Floating >) ,
@@ -1046,7 +1046,7 @@ gpio!(GPIOI, gpioi, PI, 8, PIn, [
1046
1046
] ) ;
1047
1047
1048
1048
#[ cfg( feature = "gpioj" ) ]
1049
- gpio ! ( GPIOJ , gpioj, PJ , 9 , PJn , [
1049
+ gpio ! ( GPIOJ , gpioj, PJ , 'J' , PJn , [
1050
1050
PJ0 : ( pj0, 0 , Input <Floating >) ,
1051
1051
PJ1 : ( pj1, 1 , Input <Floating >) ,
1052
1052
PJ2 : ( pj2, 2 , Input <Floating >) ,
@@ -1066,7 +1066,7 @@ gpio!(GPIOJ, gpioj, PJ, 9, PJn, [
1066
1066
] ) ;
1067
1067
1068
1068
#[ cfg( feature = "gpiok" ) ]
1069
- gpio ! ( GPIOK , gpiok, PK , 10 , PKn , [
1069
+ gpio ! ( GPIOK , gpiok, PK , 'K' , PKn , [
1070
1070
PK0 : ( pk0, 0 , Input <Floating >) ,
1071
1071
PK1 : ( pk1, 1 , Input <Floating >) ,
1072
1072
PK2 : ( pk2, 2 , Input <Floating >) ,
@@ -1183,29 +1183,29 @@ impl<MODE> InputPin for Pin<Input<MODE>> {
1183
1183
}
1184
1184
}
1185
1185
1186
- struct Gpio < const P : u8 > ;
1187
- impl < const P : u8 > Gpio < P > {
1186
+ struct Gpio < const P : char > ;
1187
+ impl < const P : char > Gpio < P > {
1188
1188
const fn ptr ( ) -> * const crate :: pac:: gpioa:: RegisterBlock {
1189
1189
match P {
1190
- 0 => crate :: pac:: GPIOA :: ptr ( ) ,
1191
- 1 => crate :: pac:: GPIOB :: ptr ( ) as _ ,
1192
- 2 => crate :: pac:: GPIOC :: ptr ( ) as _ ,
1190
+ 'A' => crate :: pac:: GPIOA :: ptr ( ) ,
1191
+ 'B' => crate :: pac:: GPIOB :: ptr ( ) as _ ,
1192
+ 'C' => crate :: pac:: GPIOC :: ptr ( ) as _ ,
1193
1193
#[ cfg( feature = "gpiod" ) ]
1194
- 3 => crate :: pac:: GPIOD :: ptr ( ) as _ ,
1194
+ 'D' => crate :: pac:: GPIOD :: ptr ( ) as _ ,
1195
1195
#[ cfg( feature = "gpioe" ) ]
1196
- 4 => crate :: pac:: GPIOE :: ptr ( ) as _ ,
1196
+ 'E' => crate :: pac:: GPIOE :: ptr ( ) as _ ,
1197
1197
#[ cfg( feature = "gpiof" ) ]
1198
- 5 => crate :: pac:: GPIOF :: ptr ( ) as _ ,
1198
+ 'F' => crate :: pac:: GPIOF :: ptr ( ) as _ ,
1199
1199
#[ cfg( feature = "gpiog" ) ]
1200
- 6 => crate :: pac:: GPIOG :: ptr ( ) as _ ,
1201
- 7 => crate :: pac:: GPIOH :: ptr ( ) as _ ,
1200
+ 'G' => crate :: pac:: GPIOG :: ptr ( ) as _ ,
1201
+ 'H' => crate :: pac:: GPIOH :: ptr ( ) as _ ,
1202
1202
#[ cfg( feature = "gpioi" ) ]
1203
- 8 => crate :: pac:: GPIOI :: ptr ( ) as _ ,
1203
+ 'I' => crate :: pac:: GPIOI :: ptr ( ) as _ ,
1204
1204
#[ cfg( feature = "gpioj" ) ]
1205
- 9 => crate :: pac:: GPIOJ :: ptr ( ) as _ ,
1205
+ 'J' => crate :: pac:: GPIOJ :: ptr ( ) as _ ,
1206
1206
#[ cfg( feature = "gpiok" ) ]
1207
- 10 => crate :: pac:: GPIOK :: ptr ( ) as _ ,
1208
- _ => 0 as _ ,
1207
+ 'K' => crate :: pac:: GPIOK :: ptr ( ) as _ ,
1208
+ _ => crate :: pac :: GPIOA :: ptr ( ) ,
1209
1209
}
1210
1210
}
1211
1211
}
0 commit comments