Skip to content

Commit 154ca0b

Browse files
committed
[stm32] [timer] [qei] allow configuration of pull-up/down internal resistors on QeiPin
Adjusts the macros for impl<'d, T: GeneralInstance4Channel> QeiPin<'d, T, $channel> to take a 2nd argument which pullup/down should be active for the pins.
1 parent d58c7f6 commit 154ca0b

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

embassy-stm32/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ chrono = { version = "^0.4", default-features = false, optional = true }
8585
bit_field = "0.10.2"
8686
document-features = "0.2.7"
8787

88+
paste = "1.0.15"
8889
static_assertions = { version = "1.1" }
8990
volatile-register = { version = "0.2.1" }
9091
bitflags = "2.4.2"

embassy-stm32/src/timer/qei.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::marker::PhantomData;
44

55
use embassy_hal_internal::{into_ref, PeripheralRef};
66
use stm32_metapac::timer::vals;
7-
7+
use paste::paste;
88
use super::low_level::Timer;
99
use super::{Channel1Pin, Channel2Pin, GeneralInstance4Channel};
1010
use crate::gpio::{AfType, AnyPin, Pull};
@@ -32,16 +32,29 @@ pub struct QeiPin<'d, T, Channel> {
3232
macro_rules! channel_impl {
3333
($new_chx:ident, $channel:ident, $pin_trait:ident) => {
3434
impl<'d, T: GeneralInstance4Channel> QeiPin<'d, T, $channel> {
35-
#[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance.")]
36-
pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self {
37-
into_ref!(pin);
38-
critical_section::with(|_| {
39-
pin.set_low();
40-
pin.set_as_af(pin.af_num(), AfType::input(Pull::None));
41-
});
42-
QeiPin {
43-
_pin: pin.map_into(),
44-
phantom: PhantomData,
35+
paste! {
36+
fn [<_ $new_chx>](pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, pull: Pull) -> Self {
37+
into_ref!(pin);
38+
critical_section::with(|_| {
39+
pin.set_low();
40+
pin.set_as_af(pin.af_num(), AfType::input(pull));
41+
});
42+
QeiPin {
43+
_pin: pin.map_into(),
44+
phantom: PhantomData,
45+
}
46+
}
47+
#[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance.")]
48+
pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self {
49+
Self::[<_ $new_chx>](pin, Pull::None)
50+
}
51+
#[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance with internal pull-up.")]
52+
pub fn [<$new_chx _pu>](pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self {
53+
Self::[<_ $new_chx>](pin, Pull::Up)
54+
}
55+
#[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance with internal pull-down.")]
56+
pub fn [<$new_chx _pd>](pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self {
57+
Self::[<_ $new_chx>](pin, Pull::Down)
4558
}
4659
}
4760
}

0 commit comments

Comments
 (0)