Skip to content

Commit 23c3d11

Browse files
committed
port chars
1 parent f96d2fd commit 23c3d11

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

src/gpio.rs

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ where
205205
}
206206

207207
/// Partially erased pin
208-
pub struct PXx<MODE, const P: u8> {
208+
pub struct PXx<MODE, const P: char> {
209209
i: u8,
210210
_mode: PhantomData<MODE>,
211211
}
212212

213-
impl<MODE, const P: u8> PinExt for PXx<MODE, P> {
213+
impl<MODE, const P: char> PinExt for PXx<MODE, P> {
214214
type Mode = MODE;
215215

216216
#[inline(always)]
@@ -219,11 +219,11 @@ impl<MODE, const P: u8> PinExt for PXx<MODE, P> {
219219
}
220220
#[inline(always)]
221221
fn port_id(&self) -> u8 {
222-
P
222+
P as u8 - 0x41
223223
}
224224
}
225225

226-
impl<MODE, const P: u8> OutputPin for PXx<Output<MODE>, P> {
226+
impl<MODE, const P: char> OutputPin for PXx<Output<MODE>, P> {
227227
type Error = Infallible;
228228

229229
fn set_high(&mut self) -> Result<(), Self::Error> {
@@ -243,7 +243,7 @@ impl<MODE, const P: u8> OutputPin for PXx<Output<MODE>, P> {
243243
}
244244
}
245245

246-
impl<MODE, const P: u8> StatefulOutputPin for PXx<Output<MODE>, P> {
246+
impl<MODE, const P: char> StatefulOutputPin for PXx<Output<MODE>, P> {
247247
fn is_set_high(&self) -> Result<bool, Self::Error> {
248248
self.is_set_low().map(|v| !v)
249249
}
@@ -254,9 +254,9 @@ impl<MODE, const P: u8> StatefulOutputPin for PXx<Output<MODE>, P> {
254254
}
255255
}
256256

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> {}
258258

259-
impl<const P: u8> InputPin for PXx<Output<OpenDrain>, P> {
259+
impl<const P: char> InputPin for PXx<Output<OpenDrain>, P> {
260260
type Error = Infallible;
261261

262262
fn is_high(&self) -> Result<bool, Self::Error> {
@@ -269,7 +269,7 @@ impl<const P: u8> InputPin for PXx<Output<OpenDrain>, P> {
269269
}
270270
}
271271

272-
impl<MODE, const P: u8> InputPin for PXx<Input<MODE>, P> {
272+
impl<MODE, const P: char> InputPin for PXx<Input<MODE>, P> {
273273
type Error = Infallible;
274274

275275
fn is_high(&self) -> Result<bool, Self::Error> {
@@ -282,7 +282,7 @@ impl<MODE, const P: u8> InputPin for PXx<Input<MODE>, P> {
282282
}
283283
}
284284

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>() {
286286
let offset = 2 * { N };
287287
let offset2 = 4 * { N };
288288
let mode = A as u32;
@@ -304,16 +304,16 @@ fn _set_alternate_mode<const P: u8, const N: u8, const A: u8>() {
304304
}
305305

306306
/// Pin
307-
pub struct PX<MODE, const P: u8, const N: u8> {
307+
pub struct PX<MODE, const P: char, const N: u8> {
308308
_mode: PhantomData<MODE>,
309309
}
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> {
311311
const fn new() -> Self {
312312
Self { _mode: PhantomData }
313313
}
314314
}
315315

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> {
317317
type Mode = MODE;
318318

319319
#[inline(always)]
@@ -322,11 +322,11 @@ impl<MODE, const P: u8, const N: u8> PinExt for PX<MODE, P, N> {
322322
}
323323
#[inline(always)]
324324
fn port_id(&self) -> u8 {
325-
P
325+
P as u8 - 0x41
326326
}
327327
}
328328

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> {
330330
/// Configures the pin to operate alternate mode
331331
pub fn into_alternate<const A: u8>(self) -> PX<Alternate<AF<A>>, P, N> {
332332
less_than_16::<A>();
@@ -663,7 +663,7 @@ impl<MODE, const P: u8, const N: u8> PX<MODE, P, N> {
663663
}
664664
}
665665

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> {
667667
/// Set pin speed
668668
pub fn set_speed(self, speed: Speed) -> Self {
669669
let offset = 2 * { N };
@@ -678,7 +678,7 @@ impl<MODE, const P: u8, const N: u8> PX<Output<MODE>, P, N> {
678678
}
679679
}
680680

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> {
682682
/// Enables / disables the internal pull up
683683
pub fn internal_pull_up(&mut self, on: bool) {
684684
let offset = 2 * { N };
@@ -691,7 +691,7 @@ impl<const P: u8, const N: u8> PX<Output<OpenDrain>, P, N> {
691691
}
692692
}
693693

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> {
695695
/// Set pin speed
696696
pub fn set_speed(self, speed: Speed) -> Self {
697697
let offset = 2 * { N };
@@ -719,7 +719,7 @@ impl<MODE, const P: u8, const N: u8> PX<Alternate<MODE>, P, N> {
719719
}
720720
}
721721

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> {
723723
/// Turns pin alternate configuration pin into open drain
724724
pub fn set_open_drain(self) -> PX<AlternateOD<MODE>, P, N> {
725725
let offset = { N };
@@ -733,7 +733,7 @@ impl<MODE, const P: u8, const N: u8> PX<Alternate<MODE>, P, N> {
733733
}
734734
}
735735

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> {
737737
/// Erases the pin number from the type
738738
///
739739
/// 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> {
750750
/// This is useful when you want to collect the pins into an array where you
751751
/// need all the elements to have the same type
752752
pub fn downgrade2(self) -> Pin<MODE> {
753-
Pin::new(P, N)
753+
Pin::new(P as u8 - 0x41, N)
754754
}
755755
}
756756

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> {
758758
type Error = Infallible;
759759

760760
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> {
774774
}
775775
}
776776

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> {
778778
fn is_set_high(&self) -> Result<bool, Self::Error> {
779779
self.is_set_low().map(|v| !v)
780780
}
@@ -785,9 +785,9 @@ impl<MODE, const P: u8, const N: u8> StatefulOutputPin for PX<Output<MODE>, P, N
785785
}
786786
}
787787

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> {}
789789

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> {
791791
type Error = Infallible;
792792

793793
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> {
800800
}
801801
}
802802

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> {
804804
type Error = Infallible;
805805

806806
fn is_high(&self) -> Result<bool, Self::Error> {
@@ -862,7 +862,7 @@ macro_rules! gpio {
862862
}
863863
}
864864

865-
gpio!(GPIOA, gpioa, PA, 0, PAn, [
865+
gpio!(GPIOA, gpioa, PA, 'A', PAn, [
866866
PA0: (pa0, 0, Input<Floating>),
867867
PA1: (pa1, 1, Input<Floating>),
868868
PA2: (pa2, 2, Input<Floating>),
@@ -881,7 +881,7 @@ gpio!(GPIOA, gpioa, PA, 0, PAn, [
881881
PA15: (pa15, 15, Input<Floating>),
882882
]);
883883

884-
gpio!(GPIOB, gpiob, PB, 1, PBn, [
884+
gpio!(GPIOB, gpiob, PB, 'B', PBn, [
885885
PB0: (pb0, 0, Input<Floating>),
886886
PB1: (pb1, 1, Input<Floating>),
887887
PB2: (pb2, 2, Input<Floating>),
@@ -900,7 +900,7 @@ gpio!(GPIOB, gpiob, PB, 1, PBn, [
900900
PB15: (pb15, 15, Input<Floating>),
901901
]);
902902

903-
gpio!(GPIOC, gpioc, PC, 2, PCn, [
903+
gpio!(GPIOC, gpioc, PC, 'C', PCn, [
904904
PC0: (pc0, 0, Input<Floating>),
905905
PC1: (pc1, 1, Input<Floating>),
906906
PC2: (pc2, 2, Input<Floating>),
@@ -920,7 +920,7 @@ gpio!(GPIOC, gpioc, PC, 2, PCn, [
920920
]);
921921

922922
#[cfg(feature = "gpiod")]
923-
gpio!(GPIOD, gpiod, PD, 3, PDn, [
923+
gpio!(GPIOD, gpiod, PD, 'D', PDn, [
924924
PD0: (pd0, 0, Input<Floating>),
925925
PD1: (pd1, 1, Input<Floating>),
926926
PD2: (pd2, 2, Input<Floating>),
@@ -940,7 +940,7 @@ gpio!(GPIOD, gpiod, PD, 3, PDn, [
940940
]);
941941

942942
#[cfg(feature = "gpioe")]
943-
gpio!(GPIOE, gpioe, PE, 4, PEn, [
943+
gpio!(GPIOE, gpioe, PE, 'E', PEn, [
944944
PE0: (pe0, 0, Input<Floating>),
945945
PE1: (pe1, 1, Input<Floating>),
946946
PE2: (pe2, 2, Input<Floating>),
@@ -960,7 +960,7 @@ gpio!(GPIOE, gpioe, PE, 4, PEn, [
960960
]);
961961

962962
#[cfg(feature = "gpiof")]
963-
gpio!(GPIOF, gpiof, PF, 5, PFn, [
963+
gpio!(GPIOF, gpiof, PF, 'F', PFn, [
964964
PF0: (pf0, 0, Input<Floating>),
965965
PF1: (pf1, 1, Input<Floating>),
966966
PF2: (pf2, 2, Input<Floating>),
@@ -980,7 +980,7 @@ gpio!(GPIOF, gpiof, PF, 5, PFn, [
980980
]);
981981

982982
#[cfg(feature = "gpiog")]
983-
gpio!(GPIOG, gpiog, PG, 6, PGn, [
983+
gpio!(GPIOG, gpiog, PG, 'G', PGn, [
984984
PG0: (pg0, 0, Input<Floating>),
985985
PG1: (pg1, 1, Input<Floating>),
986986
PG2: (pg2, 2, Input<Floating>),
@@ -1000,7 +1000,7 @@ gpio!(GPIOG, gpiog, PG, 6, PGn, [
10001000
]);
10011001

10021002
#[cfg(not(feature = "stm32f401"))]
1003-
gpio!(GPIOH, gpioh, PH, 7, PHn, [
1003+
gpio!(GPIOH, gpioh, PH, 'H', PHn, [
10041004
PH0: (ph0, 0, Input<Floating>),
10051005
PH1: (ph1, 1, Input<Floating>),
10061006
PH2: (ph2, 2, Input<Floating>),
@@ -1020,13 +1020,13 @@ gpio!(GPIOH, gpioh, PH, 7, PHn, [
10201020
]);
10211021

10221022
#[cfg(feature = "stm32f401")]
1023-
gpio!(GPIOH, gpioh, PH, 7, PHn, [
1023+
gpio!(GPIOH, gpioh, PH, 'H', PHn, [
10241024
PH0: (ph0, 0, Input<Floating>),
10251025
PH1: (ph1, 1, Input<Floating>),
10261026
]);
10271027

10281028
#[cfg(feature = "gpioi")]
1029-
gpio!(GPIOI, gpioi, PI, 8, PIn, [
1029+
gpio!(GPIOI, gpioi, PI, 'I', PIn, [
10301030
PI0: (pi0, 0, Input<Floating>),
10311031
PI1: (pi1, 1, Input<Floating>),
10321032
PI2: (pi2, 2, Input<Floating>),
@@ -1046,7 +1046,7 @@ gpio!(GPIOI, gpioi, PI, 8, PIn, [
10461046
]);
10471047

10481048
#[cfg(feature = "gpioj")]
1049-
gpio!(GPIOJ, gpioj, PJ, 9, PJn, [
1049+
gpio!(GPIOJ, gpioj, PJ, 'J', PJn, [
10501050
PJ0: (pj0, 0, Input<Floating>),
10511051
PJ1: (pj1, 1, Input<Floating>),
10521052
PJ2: (pj2, 2, Input<Floating>),
@@ -1066,7 +1066,7 @@ gpio!(GPIOJ, gpioj, PJ, 9, PJn, [
10661066
]);
10671067

10681068
#[cfg(feature = "gpiok")]
1069-
gpio!(GPIOK, gpiok, PK, 10, PKn, [
1069+
gpio!(GPIOK, gpiok, PK, 'K', PKn, [
10701070
PK0: (pk0, 0, Input<Floating>),
10711071
PK1: (pk1, 1, Input<Floating>),
10721072
PK2: (pk2, 2, Input<Floating>),
@@ -1183,29 +1183,29 @@ impl<MODE> InputPin for Pin<Input<MODE>> {
11831183
}
11841184
}
11851185

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> {
11881188
const fn ptr() -> *const crate::pac::gpioa::RegisterBlock {
11891189
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 _,
11931193
#[cfg(feature = "gpiod")]
1194-
3 => crate::pac::GPIOD::ptr() as _,
1194+
'D' => crate::pac::GPIOD::ptr() as _,
11951195
#[cfg(feature = "gpioe")]
1196-
4 => crate::pac::GPIOE::ptr() as _,
1196+
'E' => crate::pac::GPIOE::ptr() as _,
11971197
#[cfg(feature = "gpiof")]
1198-
5 => crate::pac::GPIOF::ptr() as _,
1198+
'F' => crate::pac::GPIOF::ptr() as _,
11991199
#[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 _,
12021202
#[cfg(feature = "gpioi")]
1203-
8 => crate::pac::GPIOI::ptr() as _,
1203+
'I' => crate::pac::GPIOI::ptr() as _,
12041204
#[cfg(feature = "gpioj")]
1205-
9 => crate::pac::GPIOJ::ptr() as _,
1205+
'J' => crate::pac::GPIOJ::ptr() as _,
12061206
#[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(),
12091209
}
12101210
}
12111211
}

0 commit comments

Comments
 (0)