Skip to content

Commit ac27fa6

Browse files
committed
timer: allow more pin configurations
1 parent 6aa9567 commit ac27fa6

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/timer/pins.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,35 @@ impl<TIM, PIN: TimerPin<TIM>> TriggerPin<TIM, PIN> {
2727
}
2828
}
2929

30-
macro_rules! timer_pins {
31-
($TIMX:ident, [ $(($ch:ty, $pin:tt, $af_mode:expr),)+ ]) => {
30+
macro_rules! timer_pin_impl {
31+
($TIMX:ident, $ch:ty, $pin:tt, $af_mode:expr, [ $(($mode:ty, $release:ident),)+]) => {
3232
$(
33-
impl TimerPin<$TIMX> for $pin<Analog> {
34-
type Channel = $ch;
35-
36-
fn setup(&self) {
37-
self.set_alt_mode($af_mode);
38-
}
39-
40-
fn release(self) -> Self {
41-
self.into_analog()
42-
}
43-
}
44-
45-
impl TimerPin<$TIMX> for $pin<Output<OpenDrain>> {
33+
impl TimerPin<$TIMX> for $pin<$mode> {
4634
type Channel = $ch;
4735

4836
fn setup(&self) {
4937
self.set_alt_mode($af_mode);
5038
}
5139

5240
fn release(self) -> Self {
53-
self.into_open_drain_output()
41+
self.$release()
5442
}
5543
}
44+
)+
45+
};
46+
}
5647

48+
macro_rules! timer_pins {
49+
($TIMX:ident, [ $(($ch:ty, $pin:tt, $af_mode:expr),)+ ]) => {
50+
$(
51+
timer_pin_impl!($TIMX, $ch, $pin, $af_mode, [
52+
(Analog, into_analog),
53+
(Output<OpenDrain>, into_open_drain_output),
54+
(Output<PushPull>, into_push_pull_output),
55+
(Input<Floating>, into_floating_input),
56+
(Input<PullUp>, into_pull_up_input),
57+
(Input<PullDown>, into_pull_down_input),
58+
]);
5759
)+
5860
};
5961
}

0 commit comments

Comments
 (0)