diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-09-06 00:11:59 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-09-06 00:14:03 +0200 |
| commit | a23c4b7bca15bc00f4b5c4af200f17eb0097e94b (patch) | |
| tree | f293891a3dad44dc808f31f7aa6fd7fcdb21bbe5 | |
| parent | 35f4ae378cbc9a1263e46baaeac536cae2337896 (diff) | |
stm32/afio: make af_num() unavailable in afio chips.
26 files changed, 132 insertions, 144 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json index 6edd9312a..c504f3ccd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json | |||
| @@ -17,7 +17,7 @@ | |||
| 17 | //"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf", | 17 | //"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf", |
| 18 | "rust-analyzer.cargo.features": [ | 18 | "rust-analyzer.cargo.features": [ |
| 19 | // Comment out these features when working on the examples. Most example crates do not have any cargo features. | 19 | // Comment out these features when working on the examples. Most example crates do not have any cargo features. |
| 20 | "stm32f446re", | 20 | "stm32f107rb", |
| 21 | "time-driver-any", | 21 | "time-driver-any", |
| 22 | "unstable-pac", | 22 | "unstable-pac", |
| 23 | "exti", | 23 | "exti", |
diff --git a/embassy-stm32/src/can/bxcan/mod.rs b/embassy-stm32/src/can/bxcan/mod.rs index 663b34501..8eb188560 100644 --- a/embassy-stm32/src/can/bxcan/mod.rs +++ b/embassy-stm32/src/can/bxcan/mod.rs | |||
| @@ -194,10 +194,8 @@ impl<'d> Can<'d> { | |||
| 194 | let info = T::info(); | 194 | let info = T::info(); |
| 195 | let regs = &T::info().regs; | 195 | let regs = &T::info().regs; |
| 196 | 196 | ||
| 197 | rx.set_as_af(rx.af_num(), AfType::input(Pull::None)); | 197 | set_as_af!(rx, AfType::input(Pull::None)); |
| 198 | #[cfg(afio)] | 198 | set_as_af!(tx, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 199 | rx.afio_remap(); | ||
| 200 | tx.set_as_af(tx.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | ||
| 201 | 199 | ||
| 202 | rcc::enable_and_reset::<T>(); | 200 | rcc::enable_and_reset::<T>(); |
| 203 | 201 | ||
| @@ -231,8 +229,8 @@ impl<'d> Can<'d> { | |||
| 231 | info.sce_interrupt.enable(); | 229 | info.sce_interrupt.enable(); |
| 232 | } | 230 | } |
| 233 | 231 | ||
| 234 | rx.set_as_af(rx.af_num(), AfType::input(Pull::None)); | 232 | set_as_af!(rx, AfType::input(Pull::None)); |
| 235 | tx.set_as_af(tx.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 233 | set_as_af!(tx, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 236 | 234 | ||
| 237 | Registers(T::regs()).leave_init_mode(); | 235 | Registers(T::regs()).leave_init_mode(); |
| 238 | 236 | ||
diff --git a/embassy-stm32/src/can/fdcan.rs b/embassy-stm32/src/can/fdcan.rs index 99e40ba62..d8f71e03e 100644 --- a/embassy-stm32/src/can/fdcan.rs +++ b/embassy-stm32/src/can/fdcan.rs | |||
| @@ -185,8 +185,8 @@ impl<'d> CanConfigurator<'d> { | |||
| 185 | + interrupt::typelevel::Binding<T::IT1Interrupt, IT1InterruptHandler<T>> | 185 | + interrupt::typelevel::Binding<T::IT1Interrupt, IT1InterruptHandler<T>> |
| 186 | + 'd, | 186 | + 'd, |
| 187 | ) -> CanConfigurator<'d> { | 187 | ) -> CanConfigurator<'d> { |
| 188 | rx.set_as_af(rx.af_num(), AfType::input(Pull::None)); | 188 | set_as_af!(rx, AfType::input(Pull::None)); |
| 189 | tx.set_as_af(tx.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 189 | set_as_af!(tx, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 190 | 190 | ||
| 191 | rcc::enable_and_reset::<T>(); | 191 | rcc::enable_and_reset::<T>(); |
| 192 | 192 | ||
diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs index d05faee21..bd03f1e00 100644 --- a/embassy-stm32/src/dcmi.rs +++ b/embassy-stm32/src/dcmi.rs | |||
| @@ -108,7 +108,7 @@ macro_rules! config_pins { | |||
| 108 | ($($pin:ident),*) => { | 108 | ($($pin:ident),*) => { |
| 109 | critical_section::with(|_| { | 109 | critical_section::with(|_| { |
| 110 | $( | 110 | $( |
| 111 | $pin.set_as_af($pin.af_num(), AfType::input(Pull::None)); | 111 | set_as_af!($pin, AfType::input(Pull::None)); |
| 112 | )* | 112 | )* |
| 113 | }) | 113 | }) |
| 114 | }; | 114 | }; |
diff --git a/embassy-stm32/src/dsihost.rs b/embassy-stm32/src/dsihost.rs index e97ccd9d0..deda956af 100644 --- a/embassy-stm32/src/dsihost.rs +++ b/embassy-stm32/src/dsihost.rs | |||
| @@ -78,7 +78,7 @@ impl<'d, T: Instance> DsiHost<'d, T> { | |||
| 78 | rcc::enable_and_reset::<T>(); | 78 | rcc::enable_and_reset::<T>(); |
| 79 | 79 | ||
| 80 | // Set Tearing Enable pin according to CubeMx example | 80 | // Set Tearing Enable pin according to CubeMx example |
| 81 | te.set_as_af(te.af_num(), AfType::output(OutputType::PushPull, Speed::Low)); | 81 | set_as_af!(te, AfType::output(OutputType::PushPull, Speed::Low)); |
| 82 | /* | 82 | /* |
| 83 | T::regs().wcr().modify(|w| { | 83 | T::regs().wcr().modify(|w| { |
| 84 | w.set_dsien(true); | 84 | w.set_dsien(true); |
diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index 2ae451902..5be1c9739 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs | |||
| @@ -69,7 +69,7 @@ macro_rules! config_in_pins { | |||
| 69 | critical_section::with(|_| { | 69 | critical_section::with(|_| { |
| 70 | $( | 70 | $( |
| 71 | // TODO properly create a set_as_input function | 71 | // TODO properly create a set_as_input function |
| 72 | $pin.set_as_af($pin.af_num(), AfType::input(Pull::None)); | 72 | set_as_af!($pin, AfType::input(Pull::None)); |
| 73 | )* | 73 | )* |
| 74 | }) | 74 | }) |
| 75 | } | 75 | } |
| @@ -80,7 +80,7 @@ macro_rules! config_af_pins { | |||
| 80 | ($($pin:ident),*) => { | 80 | ($($pin:ident),*) => { |
| 81 | critical_section::with(|_| { | 81 | critical_section::with(|_| { |
| 82 | $( | 82 | $( |
| 83 | $pin.set_as_af($pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 83 | set_as_af!($pin, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 84 | )* | 84 | )* |
| 85 | }) | 85 | }) |
| 86 | }; | 86 | }; |
| @@ -91,7 +91,7 @@ macro_rules! config_pins { | |||
| 91 | ($($pin:ident),*) => { | 91 | ($($pin:ident),*) => { |
| 92 | critical_section::with(|_| { | 92 | critical_section::with(|_| { |
| 93 | $( | 93 | $( |
| 94 | $pin.set_as_af($pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 94 | set_as_af!($pin, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 95 | )* | 95 | )* |
| 96 | }) | 96 | }) |
| 97 | }; | 97 | }; |
| @@ -150,8 +150,6 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 150 | { | 150 | { |
| 151 | config_in_pins!(ref_clk, rx_d0, rx_d1); | 151 | config_in_pins!(ref_clk, rx_d0, rx_d1); |
| 152 | config_af_pins!(mdio, mdc, tx_d0, tx_d1, tx_en); | 152 | config_af_pins!(mdio, mdc, tx_d0, tx_d1, tx_en); |
| 153 | #[cfg(afio)] | ||
| 154 | rx_d0.afio_remap(); | ||
| 155 | } | 153 | } |
| 156 | 154 | ||
| 157 | #[cfg(any(eth_v1b, eth_v1c))] | 155 | #[cfg(any(eth_v1b, eth_v1c))] |
| @@ -349,8 +347,6 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 349 | { | 347 | { |
| 350 | config_in_pins!(rx_clk, tx_clk, rx_d0, rx_d1, rx_d2, rx_d3, rxdv); | 348 | config_in_pins!(rx_clk, tx_clk, rx_d0, rx_d1, rx_d2, rx_d3, rxdv); |
| 351 | config_af_pins!(mdio, mdc, tx_d0, tx_d1, tx_d2, tx_d3, tx_en); | 349 | config_af_pins!(mdio, mdc, tx_d0, tx_d1, tx_d2, tx_d3, tx_en); |
| 352 | #[cfg(afio)] | ||
| 353 | rx_d0.afio_remap(); | ||
| 354 | } | 350 | } |
| 355 | 351 | ||
| 356 | #[cfg(any(eth_v1b, eth_v1c))] | 352 | #[cfg(any(eth_v1b, eth_v1c))] |
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index 034c5dd88..cf7a9901b 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs | |||
| @@ -57,7 +57,7 @@ macro_rules! config_pins { | |||
| 57 | critical_section::with(|_| { | 57 | critical_section::with(|_| { |
| 58 | $( | 58 | $( |
| 59 | // TODO: shouldn't some pins be configured as inputs? | 59 | // TODO: shouldn't some pins be configured as inputs? |
| 60 | $pin.set_as_af($pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 60 | set_as_af!($pin, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 61 | )* | 61 | )* |
| 62 | }) | 62 | }) |
| 63 | }; | 63 | }; |
diff --git a/embassy-stm32/src/fmc.rs b/embassy-stm32/src/fmc.rs index 71ca775cb..ff18a8bee 100644 --- a/embassy-stm32/src/fmc.rs +++ b/embassy-stm32/src/fmc.rs | |||
| @@ -75,7 +75,7 @@ where | |||
| 75 | macro_rules! config_pins { | 75 | macro_rules! config_pins { |
| 76 | ($($pin:ident),*) => { | 76 | ($($pin:ident),*) => { |
| 77 | $( | 77 | $( |
| 78 | $pin.set_as_af($pin.af_num(), AfType::output_pull(OutputType::PushPull, Speed::VeryHigh, Pull::Up)); | 78 | set_as_af!($pin, AfType::output_pull(OutputType::PushPull, Speed::VeryHigh, Pull::Up)); |
| 79 | )* | 79 | )* |
| 80 | }; | 80 | }; |
| 81 | } | 81 | } |
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 83fd08e23..5a8d23183 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs | |||
| @@ -150,9 +150,13 @@ impl<'d> Flex<'d> { | |||
| 150 | /// This puts the pin into the AF mode, with the requested number and AF type. This is | 150 | /// This puts the pin into the AF mode, with the requested number and AF type. This is |
| 151 | /// completely unchecked, it can attach the pin to literally any peripheral, so use with care. | 151 | /// completely unchecked, it can attach the pin to literally any peripheral, so use with care. |
| 152 | #[inline] | 152 | #[inline] |
| 153 | pub fn set_as_af_unchecked(&mut self, af_num: u8, af_type: AfType) { | 153 | pub fn set_as_af_unchecked(&mut self, #[cfg(not(afio))] af_num: u8, af_type: AfType) { |
| 154 | critical_section::with(|_| { | 154 | critical_section::with(|_| { |
| 155 | self.pin.set_as_af(af_num, af_type); | 155 | self.pin.set_as_af( |
| 156 | #[cfg(not(afio))] | ||
| 157 | af_num, | ||
| 158 | af_type, | ||
| 159 | ); | ||
| 156 | }); | 160 | }); |
| 157 | } | 161 | } |
| 158 | 162 | ||
| @@ -588,7 +592,7 @@ impl AfType { | |||
| 588 | 592 | ||
| 589 | #[inline(never)] | 593 | #[inline(never)] |
| 590 | #[cfg(gpio_v1)] | 594 | #[cfg(gpio_v1)] |
| 591 | fn set_as_af(pin_port: u8, _af_num: u8, af_type: AfType) { | 595 | fn set_as_af(pin_port: u8, af_type: AfType) { |
| 592 | let pin = unsafe { AnyPin::steal(pin_port) }; | 596 | let pin = unsafe { AnyPin::steal(pin_port) }; |
| 593 | let r = pin.block(); | 597 | let r = pin.block(); |
| 594 | let n = pin._pin() as usize; | 598 | let n = pin._pin() as usize; |
| @@ -755,8 +759,13 @@ pub(crate) trait SealedPin { | |||
| 755 | } | 759 | } |
| 756 | 760 | ||
| 757 | #[inline] | 761 | #[inline] |
| 758 | fn set_as_af(&self, af_num: u8, af_type: AfType) { | 762 | fn set_as_af(&self, #[cfg(not(afio))] af_num: u8, af_type: AfType) { |
| 759 | set_as_af(self.pin_port(), af_num, af_type) | 763 | set_as_af( |
| 764 | self.pin_port(), | ||
| 765 | #[cfg(not(afio))] | ||
| 766 | af_num, | ||
| 767 | af_type, | ||
| 768 | ) | ||
| 760 | } | 769 | } |
| 761 | 770 | ||
| 762 | #[inline] | 771 | #[inline] |
diff --git a/embassy-stm32/src/hrtim/mod.rs b/embassy-stm32/src/hrtim/mod.rs index 1d0594125..6fece5eb2 100644 --- a/embassy-stm32/src/hrtim/mod.rs +++ b/embassy-stm32/src/hrtim/mod.rs | |||
| @@ -79,10 +79,7 @@ macro_rules! advanced_channel_impl { | |||
| 79 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self { | 79 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self { |
| 80 | critical_section::with(|_| { | 80 | critical_section::with(|_| { |
| 81 | pin.set_low(); | 81 | pin.set_low(); |
| 82 | pin.set_as_af( | 82 | set_as_af!(pin, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 83 | pin.af_num(), | ||
| 84 | AfType::output(OutputType::PushPull, Speed::VeryHigh), | ||
| 85 | ); | ||
| 86 | }); | 83 | }); |
| 87 | PwmPin { | 84 | PwmPin { |
| 88 | _pin: pin.into(), | 85 | _pin: pin.into(), |
| @@ -96,10 +93,7 @@ macro_rules! advanced_channel_impl { | |||
| 96 | pub fn $new_chx(pin: Peri<'d, impl $complementary_pin_trait<T>>) -> Self { | 93 | pub fn $new_chx(pin: Peri<'d, impl $complementary_pin_trait<T>>) -> Self { |
| 97 | critical_section::with(|_| { | 94 | critical_section::with(|_| { |
| 98 | pin.set_low(); | 95 | pin.set_low(); |
| 99 | pin.set_as_af( | 96 | set_as_af!(pin, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 100 | pin.af_num(), | ||
| 101 | AfType::output(OutputType::PushPull, Speed::VeryHigh), | ||
| 102 | ); | ||
| 103 | }); | 97 | }); |
| 104 | ComplementaryPwmPin { | 98 | ComplementaryPwmPin { |
| 105 | _pin: pin.into(), | 99 | _pin: pin.into(), |
diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs index 1b885ec54..b6d3daf54 100644 --- a/embassy-stm32/src/i2s.rs +++ b/embassy-stm32/src/i2s.rs | |||
| @@ -471,8 +471,8 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 471 | config: Config, | 471 | config: Config, |
| 472 | function: Function, | 472 | function: Function, |
| 473 | ) -> Self { | 473 | ) -> Self { |
| 474 | ws.set_as_af(ws.af_num(), AfType::output(OutputType::PushPull, config.gpio_speed)); | 474 | set_as_af!(ws, AfType::output(OutputType::PushPull, config.gpio_speed)); |
| 475 | ck.set_as_af(ck.af_num(), AfType::output(OutputType::PushPull, config.gpio_speed)); | 475 | set_as_af!(ck, AfType::output(OutputType::PushPull, config.gpio_speed)); |
| 476 | 476 | ||
| 477 | let spi = Spi::new_internal(peri, None, None, { | 477 | let spi = Spi::new_internal(peri, None, None, { |
| 478 | let mut spi_config = SpiConfig::default(); | 478 | let mut spi_config = SpiConfig::default(); |
diff --git a/embassy-stm32/src/lptim/pwm.rs b/embassy-stm32/src/lptim/pwm.rs index 2f2d7ba01..96af9f4d9 100644 --- a/embassy-stm32/src/lptim/pwm.rs +++ b/embassy-stm32/src/lptim/pwm.rs | |||
| @@ -50,10 +50,7 @@ macro_rules! channel_impl { | |||
| 50 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self { | 50 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self { |
| 51 | critical_section::with(|_| { | 51 | critical_section::with(|_| { |
| 52 | pin.set_low(); | 52 | pin.set_low(); |
| 53 | pin.set_as_af( | 53 | set_as_af!(pin, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 54 | pin.af_num(), | ||
| 55 | AfType::output(OutputType::PushPull, Speed::VeryHigh), | ||
| 56 | ); | ||
| 57 | }); | 54 | }); |
| 58 | PwmPin { | 55 | PwmPin { |
| 59 | _pin: pin.into(), | 56 | _pin: pin.into(), |
| @@ -64,12 +61,12 @@ macro_rules! channel_impl { | |||
| 64 | pub fn $new_chx_with_config(pin: Peri<'d, impl $pin_trait<T>>, pin_config: PwmPinConfig) -> Self { | 61 | pub fn $new_chx_with_config(pin: Peri<'d, impl $pin_trait<T>>, pin_config: PwmPinConfig) -> Self { |
| 65 | critical_section::with(|_| { | 62 | critical_section::with(|_| { |
| 66 | pin.set_low(); | 63 | pin.set_low(); |
| 67 | pin.set_as_af( | 64 | #[cfg(gpio_v1)] |
| 68 | pin.af_num(), | 65 | set_as_af!(pin, AfType::output(pin_config.output_type, pin_config.speed)); |
| 69 | #[cfg(gpio_v1)] | 66 | #[cfg(gpio_v2)] |
| 70 | AfType::output(pin_config.output_type, pin_config.speed), | 67 | set_as_af!( |
| 71 | #[cfg(gpio_v2)] | 68 | pin, |
| 72 | AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull), | 69 | AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull) |
| 73 | ); | 70 | ); |
| 74 | }); | 71 | }); |
| 75 | PwmPin { | 72 | PwmPin { |
diff --git a/embassy-stm32/src/macros.rs b/embassy-stm32/src/macros.rs index def8dcf49..22cc2e049 100644 --- a/embassy-stm32/src/macros.rs +++ b/embassy-stm32/src/macros.rs | |||
| @@ -44,6 +44,7 @@ macro_rules! pin_trait { | |||
| 44 | ($signal:ident, $instance:path $(, $mode:path)? $(, @$afio:ident)?) => { | 44 | ($signal:ident, $instance:path $(, $mode:path)? $(, @$afio:ident)?) => { |
| 45 | #[doc = concat!(stringify!($signal), " pin trait")] | 45 | #[doc = concat!(stringify!($signal), " pin trait")] |
| 46 | pub trait $signal<T: $instance $(, M: $mode)? $(, #[cfg(afio)] $afio)?>: crate::gpio::Pin { | 46 | pub trait $signal<T: $instance $(, M: $mode)? $(, #[cfg(afio)] $afio)?>: crate::gpio::Pin { |
| 47 | #[cfg(not(afio))] | ||
| 47 | #[doc = concat!("Get the AF number needed to use this pin as ", stringify!($signal))] | 48 | #[doc = concat!("Get the AF number needed to use this pin as ", stringify!($signal))] |
| 48 | fn af_num(&self) -> u8; | 49 | fn af_num(&self) -> u8; |
| 49 | 50 | ||
| @@ -58,10 +59,6 @@ macro_rules! pin_trait_impl { | |||
| 58 | (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $pin:ident, $af:expr $(, $afio:path)?) => { | 59 | (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $pin:ident, $af:expr $(, $afio:path)?) => { |
| 59 | #[cfg(afio)] | 60 | #[cfg(afio)] |
| 60 | impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)? $(, $afio)?> for crate::peripherals::$pin { | 61 | impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)? $(, $afio)?> for crate::peripherals::$pin { |
| 61 | fn af_num(&self) -> u8 { | ||
| 62 | $af | ||
| 63 | } | ||
| 64 | |||
| 65 | fn afio_remap(&self) { | 62 | fn afio_remap(&self) { |
| 66 | // nothing | 63 | // nothing |
| 67 | } | 64 | } |
| @@ -92,10 +89,6 @@ macro_rules! pin_trait_afio_impl { | |||
| 92 | (crate::$mod:ident::$trait:ident<$mode:ident>, $instance:ident, $pin:ident, {$reg:ident, $setter:ident, $type:ident, [$($val:expr),+]}) => { | 89 | (crate::$mod:ident::$trait:ident<$mode:ident>, $instance:ident, $pin:ident, {$reg:ident, $setter:ident, $type:ident, [$($val:expr),+]}) => { |
| 93 | $( | 90 | $( |
| 94 | impl crate::$mod::$trait<crate::peripherals::$instance, crate::$mod::$mode, crate::gpio::$type<$val>> for crate::peripherals::$pin { | 91 | impl crate::$mod::$trait<crate::peripherals::$instance, crate::$mod::$mode, crate::gpio::$type<$val>> for crate::peripherals::$pin { |
| 95 | fn af_num(&self) -> u8 { | ||
| 96 | 0 | ||
| 97 | } | ||
| 98 | |||
| 99 | fn afio_remap(&self) { | 92 | fn afio_remap(&self) { |
| 100 | pin_trait_afio_impl!(@set $reg, $setter, $val); | 93 | pin_trait_afio_impl!(@set $reg, $setter, $val); |
| 101 | } | 94 | } |
| @@ -105,10 +98,6 @@ macro_rules! pin_trait_afio_impl { | |||
| 105 | (crate::$mod:ident::$trait:ident, $instance:ident, $pin:ident, {$reg:ident, $setter:ident, $type:ident, [$($val:expr),+]}) => { | 98 | (crate::$mod:ident::$trait:ident, $instance:ident, $pin:ident, {$reg:ident, $setter:ident, $type:ident, [$($val:expr),+]}) => { |
| 106 | $( | 99 | $( |
| 107 | impl crate::$mod::$trait<crate::peripherals::$instance, crate::gpio::$type<$val>> for crate::peripherals::$pin { | 100 | impl crate::$mod::$trait<crate::peripherals::$instance, crate::gpio::$type<$val>> for crate::peripherals::$pin { |
| 108 | fn af_num(&self) -> u8 { | ||
| 109 | 0 | ||
| 110 | } | ||
| 111 | |||
| 112 | fn afio_remap(&self) { | 101 | fn afio_remap(&self) { |
| 113 | pin_trait_afio_impl!(@set $reg, $setter, $val); | 102 | pin_trait_afio_impl!(@set $reg, $setter, $val); |
| 114 | } | 103 | } |
| @@ -193,11 +182,32 @@ macro_rules! new_pin { | |||
| 193 | let pin = $name; | 182 | let pin = $name; |
| 194 | #[cfg(afio)] | 183 | #[cfg(afio)] |
| 195 | pin.afio_remap(); | 184 | pin.afio_remap(); |
| 196 | pin.set_as_af(pin.af_num(), $af_type); | 185 | pin.set_as_af( |
| 186 | #[cfg(not(afio))] | ||
| 187 | pin.af_num(), | ||
| 188 | $af_type, | ||
| 189 | ); | ||
| 197 | Some(pin.into()) | 190 | Some(pin.into()) |
| 198 | }}; | 191 | }}; |
| 199 | } | 192 | } |
| 200 | 193 | ||
| 194 | /// Macro to configure a pin for alternate function use. | ||
| 195 | /// For AFIO chips (STM32F1), it calls afio_remap(). | ||
| 196 | /// For non-AFIO chips, it calls set_as_af() with the pin's af_num(). | ||
| 197 | macro_rules! set_as_af { | ||
| 198 | ($pin:expr, $af_type:expr) => { | ||
| 199 | #[cfg(afio)] | ||
| 200 | { | ||
| 201 | $pin.set_as_af($af_type); | ||
| 202 | $pin.afio_remap(); | ||
| 203 | } | ||
| 204 | #[cfg(not(afio))] | ||
| 205 | { | ||
| 206 | $pin.set_as_af($pin.af_num(), $af_type); | ||
| 207 | } | ||
| 208 | }; | ||
| 209 | } | ||
| 210 | |||
| 201 | #[cfg(afio)] | 211 | #[cfg(afio)] |
| 202 | macro_rules! if_afio { | 212 | macro_rules! if_afio { |
| 203 | ($($t:tt)*) => { | 213 | ($($t:tt)*) => { |
diff --git a/embassy-stm32/src/rcc/mco.rs b/embassy-stm32/src/rcc/mco.rs index 96e628b1a..59ccc8cb5 100644 --- a/embassy-stm32/src/rcc/mco.rs +++ b/embassy-stm32/src/rcc/mco.rs | |||
| @@ -94,7 +94,7 @@ impl<'d, T: McoInstance> Mco<'d, T> { | |||
| 94 | pub fn new(_peri: Peri<'d, T>, pin: Peri<'d, impl McoPin<T>>, source: T::Source, prescaler: McoPrescaler) -> Self { | 94 | pub fn new(_peri: Peri<'d, T>, pin: Peri<'d, impl McoPin<T>>, source: T::Source, prescaler: McoPrescaler) -> Self { |
| 95 | critical_section::with(|_| unsafe { | 95 | critical_section::with(|_| unsafe { |
| 96 | T::_apply_clock_settings(source, prescaler); | 96 | T::_apply_clock_settings(source, prescaler); |
| 97 | pin.set_as_af(pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 97 | set_as_af!(pin, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 98 | }); | 98 | }); |
| 99 | 99 | ||
| 100 | Self { phantom: PhantomData } | 100 | Self { phantom: PhantomData } |
diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs index cde2a56c2..fb8b23b79 100644 --- a/embassy-stm32/src/sai/mod.rs +++ b/embassy-stm32/src/sai/mod.rs | |||
| @@ -558,7 +558,7 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 558 | config: Config, | 558 | config: Config, |
| 559 | ) -> Self { | 559 | ) -> Self { |
| 560 | let (_sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); | 560 | let (_sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); |
| 561 | mclk.set_as_af(mclk.af_num(), ck_af_type); | 561 | set_as_af!(mclk, ck_af_type); |
| 562 | 562 | ||
| 563 | Self::new_asynchronous(peri, sck, sd, fs, dma, dma_buf, config) | 563 | Self::new_asynchronous(peri, sck, sd, fs, dma, dma_buf, config) |
| 564 | } | 564 | } |
| @@ -578,9 +578,9 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 578 | let peri = peri.peri; | 578 | let peri = peri.peri; |
| 579 | 579 | ||
| 580 | let (sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); | 580 | let (sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); |
| 581 | sd.set_as_af(sd.af_num(), sd_af_type); | 581 | set_as_af!(sd, sd_af_type); |
| 582 | sck.set_as_af(sck.af_num(), ck_af_type); | 582 | set_as_af!(sck, ck_af_type); |
| 583 | fs.set_as_af(fs.af_num(), ck_af_type); | 583 | set_as_af!(fs, ck_af_type); |
| 584 | 584 | ||
| 585 | let sub_block = S::WHICH; | 585 | let sub_block = S::WHICH; |
| 586 | let request = dma.request(); | 586 | let request = dma.request(); |
| @@ -612,7 +612,7 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 612 | let peri = peri.peri; | 612 | let peri = peri.peri; |
| 613 | 613 | ||
| 614 | let (sd_af_type, _ck_af_type) = get_af_types(config.mode, config.tx_rx); | 614 | let (sd_af_type, _ck_af_type) = get_af_types(config.mode, config.tx_rx); |
| 615 | sd.set_as_af(sd.af_num(), sd_af_type); | 615 | set_as_af!(sd, sd_af_type); |
| 616 | 616 | ||
| 617 | let sub_block = S::WHICH; | 617 | let sub_block = S::WHICH; |
| 618 | let request = dma.request(); | 618 | let request = dma.request(); |
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index 6e5d735d7..ccbd16cbf 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs | |||
| @@ -428,9 +428,9 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 428 | config: Config, | 428 | config: Config, |
| 429 | ) -> Self { | 429 | ) -> Self { |
| 430 | critical_section::with(|_| { | 430 | critical_section::with(|_| { |
| 431 | clk.set_as_af(clk.af_num(), CLK_AF); | 431 | set_as_af!(clk, CLK_AF); |
| 432 | cmd.set_as_af(cmd.af_num(), CMD_AF); | 432 | set_as_af!(cmd, CMD_AF); |
| 433 | d0.set_as_af(d0.af_num(), DATA_AF); | 433 | set_as_af!(d0, DATA_AF); |
| 434 | }); | 434 | }); |
| 435 | 435 | ||
| 436 | Self::new_inner( | 436 | Self::new_inner( |
| @@ -464,12 +464,12 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 464 | config: Config, | 464 | config: Config, |
| 465 | ) -> Self { | 465 | ) -> Self { |
| 466 | critical_section::with(|_| { | 466 | critical_section::with(|_| { |
| 467 | clk.set_as_af(clk.af_num(), CLK_AF); | 467 | set_as_af!(clk, CLK_AF); |
| 468 | cmd.set_as_af(cmd.af_num(), CMD_AF); | 468 | set_as_af!(cmd, CMD_AF); |
| 469 | d0.set_as_af(d0.af_num(), DATA_AF); | 469 | set_as_af!(d0, DATA_AF); |
| 470 | d1.set_as_af(d1.af_num(), DATA_AF); | 470 | set_as_af!(d1, DATA_AF); |
| 471 | d2.set_as_af(d2.af_num(), DATA_AF); | 471 | set_as_af!(d2, DATA_AF); |
| 472 | d3.set_as_af(d3.af_num(), DATA_AF); | 472 | set_as_af!(d3, DATA_AF); |
| 473 | }); | 473 | }); |
| 474 | 474 | ||
| 475 | Self::new_inner( | 475 | Self::new_inner( |
| @@ -510,16 +510,16 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 510 | config: Config, | 510 | config: Config, |
| 511 | ) -> Self { | 511 | ) -> Self { |
| 512 | critical_section::with(|_| { | 512 | critical_section::with(|_| { |
| 513 | clk.set_as_af(clk.af_num(), CLK_AF); | 513 | set_as_af!(clk, CLK_AF); |
| 514 | cmd.set_as_af(cmd.af_num(), CMD_AF); | 514 | set_as_af!(cmd, CMD_AF); |
| 515 | d0.set_as_af(d0.af_num(), DATA_AF); | 515 | set_as_af!(d0, DATA_AF); |
| 516 | d1.set_as_af(d1.af_num(), DATA_AF); | 516 | set_as_af!(d1, DATA_AF); |
| 517 | d2.set_as_af(d2.af_num(), DATA_AF); | 517 | set_as_af!(d2, DATA_AF); |
| 518 | d3.set_as_af(d3.af_num(), DATA_AF); | 518 | set_as_af!(d3, DATA_AF); |
| 519 | d4.set_as_af(d4.af_num(), DATA_AF); | 519 | set_as_af!(d4, DATA_AF); |
| 520 | d5.set_as_af(d5.af_num(), DATA_AF); | 520 | set_as_af!(d5, DATA_AF); |
| 521 | d6.set_as_af(d6.af_num(), DATA_AF); | 521 | set_as_af!(d6, DATA_AF); |
| 522 | d7.set_as_af(d7.af_num(), DATA_AF); | 522 | set_as_af!(d7, DATA_AF); |
| 523 | }); | 523 | }); |
| 524 | 524 | ||
| 525 | Self::new_inner( | 525 | Self::new_inner( |
| @@ -552,9 +552,9 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 552 | config: Config, | 552 | config: Config, |
| 553 | ) -> Self { | 553 | ) -> Self { |
| 554 | critical_section::with(|_| { | 554 | critical_section::with(|_| { |
| 555 | clk.set_as_af(clk.af_num(), CLK_AF); | 555 | set_as_af!(clk, CLK_AF); |
| 556 | cmd.set_as_af(cmd.af_num(), CMD_AF); | 556 | set_as_af!(cmd, CMD_AF); |
| 557 | d0.set_as_af(d0.af_num(), DATA_AF); | 557 | set_as_af!(d0, DATA_AF); |
| 558 | }); | 558 | }); |
| 559 | 559 | ||
| 560 | Self::new_inner( | 560 | Self::new_inner( |
| @@ -586,12 +586,12 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 586 | config: Config, | 586 | config: Config, |
| 587 | ) -> Self { | 587 | ) -> Self { |
| 588 | critical_section::with(|_| { | 588 | critical_section::with(|_| { |
| 589 | clk.set_as_af(clk.af_num(), CLK_AF); | 589 | set_as_af!(clk, CLK_AF); |
| 590 | cmd.set_as_af(cmd.af_num(), CMD_AF); | 590 | set_as_af!(cmd, CMD_AF); |
| 591 | d0.set_as_af(d0.af_num(), DATA_AF); | 591 | set_as_af!(d0, DATA_AF); |
| 592 | d1.set_as_af(d1.af_num(), DATA_AF); | 592 | set_as_af!(d1, DATA_AF); |
| 593 | d2.set_as_af(d2.af_num(), DATA_AF); | 593 | set_as_af!(d2, DATA_AF); |
| 594 | d3.set_as_af(d3.af_num(), DATA_AF); | 594 | set_as_af!(d3, DATA_AF); |
| 595 | }); | 595 | }); |
| 596 | 596 | ||
| 597 | Self::new_inner( | 597 | Self::new_inner( |
| @@ -630,16 +630,16 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 630 | config: Config, | 630 | config: Config, |
| 631 | ) -> Self { | 631 | ) -> Self { |
| 632 | critical_section::with(|_| { | 632 | critical_section::with(|_| { |
| 633 | clk.set_as_af(clk.af_num(), CLK_AF); | 633 | set_as_af!(clk, CLK_AF); |
| 634 | cmd.set_as_af(cmd.af_num(), CMD_AF); | 634 | set_as_af!(cmd, CMD_AF); |
| 635 | d0.set_as_af(d0.af_num(), DATA_AF); | 635 | set_as_af!(d0, DATA_AF); |
| 636 | d1.set_as_af(d1.af_num(), DATA_AF); | 636 | set_as_af!(d1, DATA_AF); |
| 637 | d2.set_as_af(d2.af_num(), DATA_AF); | 637 | set_as_af!(d2, DATA_AF); |
| 638 | d3.set_as_af(d3.af_num(), DATA_AF); | 638 | set_as_af!(d3, DATA_AF); |
| 639 | d4.set_as_af(d4.af_num(), DATA_AF); | 639 | set_as_af!(d4, DATA_AF); |
| 640 | d5.set_as_af(d5.af_num(), DATA_AF); | 640 | set_as_af!(d5, DATA_AF); |
| 641 | d6.set_as_af(d6.af_num(), DATA_AF); | 641 | set_as_af!(d6, DATA_AF); |
| 642 | d7.set_as_af(d7.af_num(), DATA_AF); | 642 | set_as_af!(d7, DATA_AF); |
| 643 | }); | 643 | }); |
| 644 | 644 | ||
| 645 | Self::new_inner( | 645 | Self::new_inner( |
diff --git a/embassy-stm32/src/spdifrx/mod.rs b/embassy-stm32/src/spdifrx/mod.rs index 466639e83..b0a32d5d1 100644 --- a/embassy-stm32/src/spdifrx/mod.rs +++ b/embassy-stm32/src/spdifrx/mod.rs | |||
| @@ -35,7 +35,7 @@ macro_rules! new_spdifrx_pin { | |||
| 35 | ($name:ident, $af_type:expr) => {{ | 35 | ($name:ident, $af_type:expr) => {{ |
| 36 | let pin = $name; | 36 | let pin = $name; |
| 37 | let input_sel = pin.input_sel(); | 37 | let input_sel = pin.input_sel(); |
| 38 | pin.set_as_af(pin.af_num(), $af_type); | 38 | set_as_af!(pin, $af_type); |
| 39 | (Some(pin.into()), input_sel) | 39 | (Some(pin.into()), input_sel) |
| 40 | }}; | 40 | }}; |
| 41 | } | 41 | } |
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs index 693eb3456..484aae1d0 100644 --- a/embassy-stm32/src/timer/complementary_pwm.rs +++ b/embassy-stm32/src/timer/complementary_pwm.rs | |||
| @@ -27,12 +27,10 @@ impl<'d, T: AdvancedInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!( | |||
| 27 | pub fn new(pin: Peri<'d, if_afio!(impl TimerComplementaryPin<T, C, A>)>, output_type: OutputType) -> Self { | 27 | pub fn new(pin: Peri<'d, if_afio!(impl TimerComplementaryPin<T, C, A>)>, output_type: OutputType) -> Self { |
| 28 | critical_section::with(|_| { | 28 | critical_section::with(|_| { |
| 29 | pin.set_low(); | 29 | pin.set_low(); |
| 30 | pin.set_as_af( | 30 | set_as_af!( |
| 31 | pin.af_num(), | 31 | pin, |
| 32 | crate::gpio::AfType::output(output_type, crate::gpio::Speed::VeryHigh), | 32 | crate::gpio::AfType::output(output_type, crate::gpio::Speed::VeryHigh) |
| 33 | ); | 33 | ); |
| 34 | #[cfg(afio)] | ||
| 35 | pin.afio_remap(); | ||
| 36 | }); | 34 | }); |
| 37 | ComplementaryPwmPin { | 35 | ComplementaryPwmPin { |
| 38 | pin: pin.into(), | 36 | pin: pin.into(), |
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs index 41391bd6d..7a25e6c21 100644 --- a/embassy-stm32/src/timer/input_capture.rs +++ b/embassy-stm32/src/timer/input_capture.rs | |||
| @@ -25,7 +25,7 @@ pub struct CapturePin<'d, T, C, #[cfg(afio)] A> { | |||
| 25 | impl<'d, T: GeneralInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(CapturePin<'d, T, C, A>) { | 25 | impl<'d, T: GeneralInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(CapturePin<'d, T, C, A>) { |
| 26 | /// Create a new capture pin instance. | 26 | /// Create a new capture pin instance. |
| 27 | pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pull: Pull) -> Self { | 27 | pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pull: Pull) -> Self { |
| 28 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 28 | set_as_af!(pin, AfType::input(pull)); |
| 29 | CapturePin { | 29 | CapturePin { |
| 30 | pin: pin.into(), | 30 | pin: pin.into(), |
| 31 | phantom: PhantomData, | 31 | phantom: PhantomData, |
diff --git a/embassy-stm32/src/timer/one_pulse.rs b/embassy-stm32/src/timer/one_pulse.rs index edab38022..a75b41bd7 100644 --- a/embassy-stm32/src/timer/one_pulse.rs +++ b/embassy-stm32/src/timer/one_pulse.rs | |||
| @@ -65,9 +65,7 @@ impl SealedTriggerSource for Ext {} | |||
| 65 | impl<'d, T: GeneralInstance4Channel, C: TriggerSource + TimerChannel> TriggerPin<'d, T, C> { | 65 | impl<'d, T: GeneralInstance4Channel, C: TriggerSource + TimerChannel> TriggerPin<'d, T, C> { |
| 66 | /// Create a new Channel trigger pin instance. | 66 | /// Create a new Channel trigger pin instance. |
| 67 | pub fn new<#[cfg(afio)] A>(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pull: Pull) -> Self { | 67 | pub fn new<#[cfg(afio)] A>(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pull: Pull) -> Self { |
| 68 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 68 | set_as_af!(pin, AfType::input(pull)); |
| 69 | #[cfg(afio)] | ||
| 70 | pin.afio_remap(); | ||
| 71 | TriggerPin { | 69 | TriggerPin { |
| 72 | pin: pin.into(), | 70 | pin: pin.into(), |
| 73 | phantom: PhantomData, | 71 | phantom: PhantomData, |
| @@ -78,9 +76,7 @@ impl<'d, T: GeneralInstance4Channel, C: TriggerSource + TimerChannel> TriggerPin | |||
| 78 | impl<'d, T: GeneralInstance4Channel> TriggerPin<'d, T, Ext> { | 76 | impl<'d, T: GeneralInstance4Channel> TriggerPin<'d, T, Ext> { |
| 79 | /// Create a new external trigger pin instance. | 77 | /// Create a new external trigger pin instance. |
| 80 | pub fn new_external<#[cfg(afio)] A>(pin: Peri<'d, if_afio!(impl ExternalTriggerPin<T, A>)>, pull: Pull) -> Self { | 78 | pub fn new_external<#[cfg(afio)] A>(pin: Peri<'d, if_afio!(impl ExternalTriggerPin<T, A>)>, pull: Pull) -> Self { |
| 81 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 79 | set_as_af!(pin, AfType::input(pull)); |
| 82 | #[cfg(afio)] | ||
| 83 | pin.afio_remap(); | ||
| 84 | TriggerPin { | 80 | TriggerPin { |
| 85 | pin: pin.into(), | 81 | pin: pin.into(), |
| 86 | phantom: PhantomData, | 82 | phantom: PhantomData, |
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs index 4c1df0316..159b5a177 100644 --- a/embassy-stm32/src/timer/pwm_input.rs +++ b/embassy-stm32/src/timer/pwm_input.rs | |||
| @@ -24,9 +24,7 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | |||
| 24 | pull: Pull, | 24 | pull: Pull, |
| 25 | freq: Hertz, | 25 | freq: Hertz, |
| 26 | ) -> Self { | 26 | ) -> Self { |
| 27 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 27 | set_as_af!(pin, AfType::input(pull)); |
| 28 | #[cfg(afio)] | ||
| 29 | pin.afio_remap(); | ||
| 30 | 28 | ||
| 31 | Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) | 29 | Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) |
| 32 | } | 30 | } |
| @@ -38,9 +36,7 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | |||
| 38 | pull: Pull, | 36 | pull: Pull, |
| 39 | freq: Hertz, | 37 | freq: Hertz, |
| 40 | ) -> Self { | 38 | ) -> Self { |
| 41 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 39 | set_as_af!(pin, AfType::input(pull)); |
| 42 | #[cfg(afio)] | ||
| 43 | pin.afio_remap(); | ||
| 44 | 40 | ||
| 45 | Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) | 41 | Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) |
| 46 | } | 42 | } |
diff --git a/embassy-stm32/src/timer/qei.rs b/embassy-stm32/src/timer/qei.rs index 528c4a904..82b5968b0 100644 --- a/embassy-stm32/src/timer/qei.rs +++ b/embassy-stm32/src/timer/qei.rs | |||
| @@ -31,9 +31,7 @@ impl<'d, T: GeneralInstance4Channel, C: QeiChannel, #[cfg(afio)] A> if_afio!(Qei | |||
| 31 | pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>) -> Self { | 31 | pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>) -> Self { |
| 32 | critical_section::with(|_| { | 32 | critical_section::with(|_| { |
| 33 | pin.set_low(); | 33 | pin.set_low(); |
| 34 | pin.set_as_af(pin.af_num(), AfType::input(Pull::None)); | 34 | set_as_af!(pin, AfType::input(Pull::None)); |
| 35 | #[cfg(afio)] | ||
| 36 | pin.afio_remap(); | ||
| 37 | }); | 35 | }); |
| 38 | QeiPin { | 36 | QeiPin { |
| 39 | pin: pin.into(), | 37 | pin: pin.into(), |
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs index c08a3939f..e6165e42b 100644 --- a/embassy-stm32/src/timer/simple_pwm.rs +++ b/embassy-stm32/src/timer/simple_pwm.rs | |||
| @@ -40,9 +40,7 @@ impl<'d, T: GeneralInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(P | |||
| 40 | pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, output_type: OutputType) -> Self { | 40 | pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, output_type: OutputType) -> Self { |
| 41 | critical_section::with(|_| { | 41 | critical_section::with(|_| { |
| 42 | pin.set_low(); | 42 | pin.set_low(); |
| 43 | pin.set_as_af(pin.af_num(), AfType::output(output_type, Speed::VeryHigh)); | 43 | set_as_af!(pin, AfType::output(output_type, Speed::VeryHigh)); |
| 44 | #[cfg(afio)] | ||
| 45 | pin.afio_remap(); | ||
| 46 | }); | 44 | }); |
| 47 | PwmPin { | 45 | PwmPin { |
| 48 | pin: pin.into(), | 46 | pin: pin.into(), |
| @@ -54,15 +52,13 @@ impl<'d, T: GeneralInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(P | |||
| 54 | pub fn new_with_config(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pin_config: PwmPinConfig) -> Self { | 52 | pub fn new_with_config(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pin_config: PwmPinConfig) -> Self { |
| 55 | critical_section::with(|_| { | 53 | critical_section::with(|_| { |
| 56 | pin.set_low(); | 54 | pin.set_low(); |
| 57 | pin.set_as_af( | 55 | #[cfg(gpio_v1)] |
| 58 | pin.af_num(), | 56 | set_as_af!(pin, AfType::output(pin_config.output_type, pin_config.speed)); |
| 59 | #[cfg(gpio_v1)] | 57 | #[cfg(gpio_v2)] |
| 60 | AfType::output(pin_config.output_type, pin_config.speed), | 58 | set_as_af!( |
| 61 | #[cfg(gpio_v2)] | 59 | pin, |
| 62 | AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull), | 60 | AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull) |
| 63 | ); | 61 | ); |
| 64 | #[cfg(afio)] | ||
| 65 | pin.afio_remap(); | ||
| 66 | }); | 62 | }); |
| 67 | PwmPin { | 63 | PwmPin { |
| 68 | pin: pin.into(), | 64 | pin: pin.into(), |
diff --git a/embassy-stm32/src/tsc/pin_groups.rs b/embassy-stm32/src/tsc/pin_groups.rs index 6f914a94e..84421f7ff 100644 --- a/embassy-stm32/src/tsc/pin_groups.rs +++ b/embassy-stm32/src/tsc/pin_groups.rs | |||
| @@ -427,7 +427,7 @@ macro_rules! impl_set_io { | |||
| 427 | pub fn $method<Role: pin_roles::Role>(&mut self, pin: Peri<'d, impl $trait<T>>) -> IOPinWithRole<$group, Role> { | 427 | pub fn $method<Role: pin_roles::Role>(&mut self, pin: Peri<'d, impl $trait<T>>) -> IOPinWithRole<$group, Role> { |
| 428 | critical_section::with(|_| { | 428 | critical_section::with(|_| { |
| 429 | pin.set_low(); | 429 | pin.set_low(); |
| 430 | pin.set_as_af(pin.af_num(), AfType::output(Role::output_type(), Speed::VeryHigh)); | 430 | set_as_af!(pin, AfType::output(Role::output_type(), Speed::VeryHigh)); |
| 431 | let tsc_io_pin = trait_to_io_pin!($trait); | 431 | let tsc_io_pin = trait_to_io_pin!($trait); |
| 432 | let new_pin = Pin { | 432 | let new_pin = Pin { |
| 433 | _pin: pin.into(), | 433 | _pin: pin.into(), |
diff --git a/embassy-stm32/src/usb/otg.rs b/embassy-stm32/src/usb/otg.rs index 1c3b99b93..5ce81b131 100644 --- a/embassy-stm32/src/usb/otg.rs +++ b/embassy-stm32/src/usb/otg.rs | |||
| @@ -34,7 +34,7 @@ macro_rules! config_ulpi_pins { | |||
| 34 | ($($pin:ident),*) => { | 34 | ($($pin:ident),*) => { |
| 35 | critical_section::with(|_| { | 35 | critical_section::with(|_| { |
| 36 | $( | 36 | $( |
| 37 | $pin.set_as_af($pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 37 | set_as_af!($pin, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 38 | )* | 38 | )* |
| 39 | }) | 39 | }) |
| 40 | }; | 40 | }; |
| @@ -68,8 +68,8 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 68 | ep_out_buffer: &'d mut [u8], | 68 | ep_out_buffer: &'d mut [u8], |
| 69 | config: Config, | 69 | config: Config, |
| 70 | ) -> Self { | 70 | ) -> Self { |
| 71 | dp.set_as_af(dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 71 | set_as_af!(dp, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 72 | dm.set_as_af(dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 72 | set_as_af!(dm, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 73 | 73 | ||
| 74 | let regs = T::regs(); | 74 | let regs = T::regs(); |
| 75 | 75 | ||
| @@ -107,8 +107,8 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 107 | // For STM32U5 High speed pins need to be left in analog mode | 107 | // For STM32U5 High speed pins need to be left in analog mode |
| 108 | #[cfg(not(any(all(stm32u5, peri_usb_otg_hs), all(stm32wba, peri_usb_otg_hs))))] | 108 | #[cfg(not(any(all(stm32u5, peri_usb_otg_hs), all(stm32wba, peri_usb_otg_hs))))] |
| 109 | { | 109 | { |
| 110 | _dp.set_as_af(_dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 110 | set_as_af!(_dp, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 111 | _dm.set_as_af(_dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 111 | set_as_af!(_dm, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | let instance = OtgInstance { | 114 | let instance = OtgInstance { |
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index 54596aeae..9e08d99b3 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs | |||
| @@ -298,7 +298,7 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 298 | ) -> Self { | 298 | ) -> Self { |
| 299 | { | 299 | { |
| 300 | use crate::gpio::{AfType, OutputType, Speed}; | 300 | use crate::gpio::{AfType, OutputType, Speed}; |
| 301 | sof.set_as_af(sof.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 301 | set_as_af!(sof, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 302 | } | 302 | } |
| 303 | 303 | ||
| 304 | Self::new(_usb, _irq, dp, dm) | 304 | Self::new(_usb, _irq, dp, dm) |
| @@ -329,8 +329,8 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 329 | #[cfg(not(stm32l1))] | 329 | #[cfg(not(stm32l1))] |
| 330 | { | 330 | { |
| 331 | use crate::gpio::{AfType, OutputType, Speed}; | 331 | use crate::gpio::{AfType, OutputType, Speed}; |
| 332 | dp.set_as_af(dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 332 | set_as_af!(dp, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 333 | dm.set_as_af(dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 333 | set_as_af!(dm, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 334 | } | 334 | } |
| 335 | #[cfg(stm32l1)] | 335 | #[cfg(stm32l1)] |
| 336 | let _ = (dp, dm); // suppress "unused" warnings. | 336 | let _ = (dp, dm); // suppress "unused" warnings. |
