Skip to content

Commit 14cc52a

Browse files
committed
generic IntoAf
1 parent a0d9a55 commit 14cc52a

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

src/gpio.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,11 @@ pub mod marker {
159159
/// Marker trait for active pin modes
160160
pub trait Active {}
161161

162-
macro_rules! af_marker_trait {
163-
([$($i:literal),+ $(,)?]) => {
164-
paste::paste! {
165-
$(
166-
#[doc = "Marker trait for pins with alternate function " $i " mapping"]
167-
pub trait [<IntoAf $i>] {
168-
/// Associated AFR register
169-
type AFR: super::Afr;
170-
}
171-
)+
172-
}
173-
};
162+
/// Marker trait for pins with alternate function `A` mapping
163+
pub trait IntoAf<const A: u8> {
164+
/// Associated AFR register
165+
type AFR: super::Afr;
174166
}
175-
176-
af_marker_trait!([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
177167
}
178168

179169
/// Runtime defined GPIO port (type state)
@@ -674,15 +664,15 @@ where
674664
}
675665

676666
macro_rules! af {
677-
($i:literal, $AFi:ident, $IntoAfi:ident, $into_afi_push_pull:ident, $into_afi_open_drain:ident) => {
667+
($i:literal, $AFi:ident, $into_afi_push_pull:ident, $into_afi_open_drain:ident) => {
678668
paste::paste! {
679669
#[doc = "Alternate function " $i " (type state)"]
680670
pub type $AFi<Otype> = Alternate<Otype, $i>;
681671
}
682672

683673
impl<Gpio, Index, Mode> Pin<Gpio, Index, Mode>
684674
where
685-
Self: marker::$IntoAfi,
675+
Self: marker::IntoAf<$i>,
686676
Gpio: marker::GpioStatic,
687677
Index: marker::Index,
688678
{
@@ -691,7 +681,7 @@ macro_rules! af {
691681
self,
692682
moder: &mut Gpio::MODER,
693683
otyper: &mut Gpio::OTYPER,
694-
afr: &mut <Self as marker::$IntoAfi>::AFR,
684+
afr: &mut <Self as marker::IntoAf<$i>>::AFR,
695685
) -> Pin<Gpio, Index, $AFi<PushPull>> {
696686
moder.alternate(self.index.index());
697687
otyper.push_pull(self.index.index());
@@ -704,7 +694,7 @@ macro_rules! af {
704694
self,
705695
moder: &mut Gpio::MODER,
706696
otyper: &mut Gpio::OTYPER,
707-
afr: &mut <Self as marker::$IntoAfi>::AFR,
697+
afr: &mut <Self as marker::IntoAf<$i>>::AFR,
708698
) -> Pin<Gpio, Index, $AFi<OpenDrain>> {
709699
moder.alternate(self.index.index());
710700
otyper.open_drain(self.index.index());
@@ -717,7 +707,7 @@ macro_rules! af {
717707
([$($i:literal),+ $(,)?]) => {
718708
paste::paste! {
719709
$(
720-
af!($i, [<AF $i>], [<IntoAf $i>], [<into_af $i _push_pull>], [<into_af $i _open_drain>]);
710+
af!($i, [<AF $i>], [<into_af $i _push_pull>], [<into_af $i _open_drain>]);
721711
)+
722712
}
723713
};
@@ -787,7 +777,7 @@ macro_rules! gpio {
787777
partially_erased_pin: $PXx:ident,
788778
pins: [$(
789779
$i:literal => (
790-
$PXi:ident, $pxi:ident, $MODE:ty, $AFR:ident, [$($IntoAfi:ident),*],
780+
$PXi:ident, $pxi:ident, $MODE:ty, $AFR:ident, [$($af:literal),*],
791781
),
792782
)+],
793783
}) => {
@@ -825,7 +815,7 @@ macro_rules! gpio {
825815
pub type $PXi<Mode> = Pin<$Gpiox, U<$i>, Mode>;
826816

827817
$(
828-
impl<Mode> marker::$IntoAfi for $PXi<Mode> {
818+
impl<Mode> marker::IntoAf<$af> for $PXi<Mode> {
829819
type AFR = $gpiox::$AFR;
830820
}
831821
)*
@@ -1003,7 +993,7 @@ macro_rules! gpio {
1003993
partially_erased_pin: [<P $X x>],
1004994
pins: [$(
1005995
$i => (
1006-
[<P $X $i>], [<p $x $i>], $MODE, [<AFR $LH>], [$([<IntoAf $af>]),*],
996+
[<P $X $i>], [<p $x $i>], $MODE, [<AFR $LH>], [$($af),*],
1007997
),
1008998
)+],
1009999
});

0 commit comments

Comments
 (0)