diff --git a/src/timer/pins.rs b/src/timer/pins.rs index 5936a23..69437a8 100644 --- a/src/timer/pins.rs +++ b/src/timer/pins.rs @@ -27,22 +27,10 @@ impl> TriggerPin { } } -macro_rules! timer_pins { - ($TIMX:ident, [ $(($ch:ty, $pin:tt, $af_mode:expr),)+ ]) => { +macro_rules! timer_pin_impl { + ($TIMX:ident, $ch:ty, $pin:tt, $af_mode:expr, [ $(($mode:ty, $release:ident),)+]) => { $( - impl TimerPin<$TIMX> for $pin { - type Channel = $ch; - - fn setup(&self) { - self.set_alt_mode($af_mode); - } - - fn release(self) -> Self { - self.into_analog() - } - } - - impl TimerPin<$TIMX> for $pin> { + impl TimerPin<$TIMX> for $pin<$mode> { type Channel = $ch; fn setup(&self) { @@ -50,10 +38,24 @@ macro_rules! timer_pins { } fn release(self) -> Self { - self.into_open_drain_output() + self.$release() } } + )+ + }; +} +macro_rules! timer_pins { + ($TIMX:ident, [ $(($ch:ty, $pin:tt, $af_mode:expr),)+ ]) => { + $( + timer_pin_impl!($TIMX, $ch, $pin, $af_mode, [ + (Analog, into_analog), + (Output, into_open_drain_output), + (Output, into_push_pull_output), + (Input, into_floating_input), + (Input, into_pull_up_input), + (Input, into_pull_down_input), + ]); )+ }; }