aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-09-05 23:44:25 +0200
committerDario Nieuwenhuis <[email protected]>2025-09-05 23:44:25 +0200
commit35f4ae378cbc9a1263e46baaeac536cae2337896 (patch)
tree7f142a458cf10b0ffa444b9963d0e2b30349ef0b /embassy-stm32
parent7419b398bf7cc5c1ff164c504f4a4027cd6bcd3b (diff)
stm32/afio: make the A generic param only appear in chips with AFIO.
Diffstat (limited to 'embassy-stm32')
-rw-r--r--embassy-stm32/src/can/bxcan/mod.rs6
-rw-r--r--embassy-stm32/src/eth/v1/mod.rs50
-rw-r--r--embassy-stm32/src/eth/v2/mod.rs50
-rw-r--r--embassy-stm32/src/gpio.rs1
-rw-r--r--embassy-stm32/src/i2c/mod.rs12
-rw-r--r--embassy-stm32/src/i2s.rs46
-rw-r--r--embassy-stm32/src/macros.rs54
-rw-r--r--embassy-stm32/src/spi/mod.rs48
-rw-r--r--embassy-stm32/src/timer/complementary_pwm.rs26
-rw-r--r--embassy-stm32/src/timer/input_capture.rs18
-rw-r--r--embassy-stm32/src/timer/one_pulse.rs4
-rw-r--r--embassy-stm32/src/timer/pwm_input.rs14
-rw-r--r--embassy-stm32/src/timer/qei.rs14
-rw-r--r--embassy-stm32/src/timer/simple_pwm.rs22
-rw-r--r--embassy-stm32/src/usart/buffered.rs48
-rw-r--r--embassy-stm32/src/usart/mod.rs104
16 files changed, 291 insertions, 226 deletions
diff --git a/embassy-stm32/src/can/bxcan/mod.rs b/embassy-stm32/src/can/bxcan/mod.rs
index 9ebfeb42f..663b34501 100644
--- a/embassy-stm32/src/can/bxcan/mod.rs
+++ b/embassy-stm32/src/can/bxcan/mod.rs
@@ -181,10 +181,10 @@ pub enum TryWriteError {
181impl<'d> Can<'d> { 181impl<'d> Can<'d> {
182 /// Creates a new Bxcan instance, keeping the peripheral in sleep mode. 182 /// Creates a new Bxcan instance, keeping the peripheral in sleep mode.
183 /// You must call [Can::enable_non_blocking] to use the peripheral. 183 /// You must call [Can::enable_non_blocking] to use the peripheral.
184 pub fn new<T: Instance, A>( 184 pub fn new<T: Instance, #[cfg(afio)] A>(
185 _peri: Peri<'d, T>, 185 _peri: Peri<'d, T>,
186 rx: Peri<'d, impl RxPin<T, A>>, 186 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
187 tx: Peri<'d, impl TxPin<T, A>>, 187 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
188 _irqs: impl interrupt::typelevel::Binding<T::TXInterrupt, TxInterruptHandler<T>> 188 _irqs: impl interrupt::typelevel::Binding<T::TXInterrupt, TxInterruptHandler<T>>
189 + interrupt::typelevel::Binding<T::RX0Interrupt, Rx0InterruptHandler<T>> 189 + interrupt::typelevel::Binding<T::RX0Interrupt, Rx0InterruptHandler<T>>
190 + interrupt::typelevel::Binding<T::RX1Interrupt, Rx1InterruptHandler<T>> 190 + interrupt::typelevel::Binding<T::RX1Interrupt, Rx1InterruptHandler<T>>
diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs
index 45be65c5f..2ae451902 100644
--- a/embassy-stm32/src/eth/v1/mod.rs
+++ b/embassy-stm32/src/eth/v1/mod.rs
@@ -99,19 +99,19 @@ macro_rules! config_pins {
99 99
100impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { 100impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
101 /// safety: the returned instance is not leak-safe 101 /// safety: the returned instance is not leak-safe
102 pub fn new<const TX: usize, const RX: usize, A>( 102 pub fn new<const TX: usize, const RX: usize, #[cfg(afio)] A>(
103 queue: &'d mut PacketQueue<TX, RX>, 103 queue: &'d mut PacketQueue<TX, RX>,
104 peri: Peri<'d, T>, 104 peri: Peri<'d, T>,
105 irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, 105 irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd,
106 ref_clk: Peri<'d, impl RefClkPin<T, A>>, 106 ref_clk: Peri<'d, if_afio!(impl RefClkPin<T, A>)>,
107 mdio: Peri<'d, impl MDIOPin<T, A>>, 107 mdio: Peri<'d, if_afio!(impl MDIOPin<T, A>)>,
108 mdc: Peri<'d, impl MDCPin<T, A>>, 108 mdc: Peri<'d, if_afio!(impl MDCPin<T, A>)>,
109 crs: Peri<'d, impl CRSPin<T, A>>, 109 crs: Peri<'d, if_afio!(impl CRSPin<T, A>)>,
110 rx_d0: Peri<'d, impl RXD0Pin<T, A>>, 110 rx_d0: Peri<'d, if_afio!(impl RXD0Pin<T, A>)>,
111 rx_d1: Peri<'d, impl RXD1Pin<T, A>>, 111 rx_d1: Peri<'d, if_afio!(impl RXD1Pin<T, A>)>,
112 tx_d0: Peri<'d, impl TXD0Pin<T, A>>, 112 tx_d0: Peri<'d, if_afio!(impl TXD0Pin<T, A>)>,
113 tx_d1: Peri<'d, impl TXD1Pin<T, A>>, 113 tx_d1: Peri<'d, if_afio!(impl TXD1Pin<T, A>)>,
114 tx_en: Peri<'d, impl TXEnPin<T, A>>, 114 tx_en: Peri<'d, if_afio!(impl TXEnPin<T, A>)>,
115 phy: P, 115 phy: P,
116 mac_addr: [u8; 6], 116 mac_addr: [u8; 6],
117 ) -> Self { 117 ) -> Self {
@@ -291,24 +291,24 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
291 } 291 }
292 292
293 /// Create a new MII ethernet driver using 14 pins. 293 /// Create a new MII ethernet driver using 14 pins.
294 pub fn new_mii<const TX: usize, const RX: usize, A>( 294 pub fn new_mii<const TX: usize, const RX: usize, #[cfg(afio)] A>(
295 queue: &'d mut PacketQueue<TX, RX>, 295 queue: &'d mut PacketQueue<TX, RX>,
296 peri: Peri<'d, T>, 296 peri: Peri<'d, T>,
297 irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, 297 irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd,
298 rx_clk: Peri<'d, impl RXClkPin<T, A>>, 298 rx_clk: Peri<'d, if_afio!(impl RXClkPin<T, A>)>,
299 tx_clk: Peri<'d, impl TXClkPin<T, A>>, 299 tx_clk: Peri<'d, if_afio!(impl TXClkPin<T, A>)>,
300 mdio: Peri<'d, impl MDIOPin<T, A>>, 300 mdio: Peri<'d, if_afio!(impl MDIOPin<T, A>)>,
301 mdc: Peri<'d, impl MDCPin<T, A>>, 301 mdc: Peri<'d, if_afio!(impl MDCPin<T, A>)>,
302 rxdv: Peri<'d, impl RXDVPin<T, A>>, 302 rxdv: Peri<'d, if_afio!(impl RXDVPin<T, A>)>,
303 rx_d0: Peri<'d, impl RXD0Pin<T, A>>, 303 rx_d0: Peri<'d, if_afio!(impl RXD0Pin<T, A>)>,
304 rx_d1: Peri<'d, impl RXD1Pin<T, A>>, 304 rx_d1: Peri<'d, if_afio!(impl RXD1Pin<T, A>)>,
305 rx_d2: Peri<'d, impl RXD2Pin<T, A>>, 305 rx_d2: Peri<'d, if_afio!(impl RXD2Pin<T, A>)>,
306 rx_d3: Peri<'d, impl RXD3Pin<T, A>>, 306 rx_d3: Peri<'d, if_afio!(impl RXD3Pin<T, A>)>,
307 tx_d0: Peri<'d, impl TXD0Pin<T, A>>, 307 tx_d0: Peri<'d, if_afio!(impl TXD0Pin<T, A>)>,
308 tx_d1: Peri<'d, impl TXD1Pin<T, A>>, 308 tx_d1: Peri<'d, if_afio!(impl TXD1Pin<T, A>)>,
309 tx_d2: Peri<'d, impl TXD2Pin<T, A>>, 309 tx_d2: Peri<'d, if_afio!(impl TXD2Pin<T, A>)>,
310 tx_d3: Peri<'d, impl TXD3Pin<T, A>>, 310 tx_d3: Peri<'d, if_afio!(impl TXD3Pin<T, A>)>,
311 tx_en: Peri<'d, impl TXEnPin<T, A>>, 311 tx_en: Peri<'d, if_afio!(impl TXEnPin<T, A>)>,
312 phy: P, 312 phy: P,
313 mac_addr: [u8; 6], 313 mac_addr: [u8; 6],
314 ) -> Self { 314 ) -> Self {
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs
index 96ad42c7f..034c5dd88 100644
--- a/embassy-stm32/src/eth/v2/mod.rs
+++ b/embassy-stm32/src/eth/v2/mod.rs
@@ -65,19 +65,19 @@ macro_rules! config_pins {
65 65
66impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { 66impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
67 /// Create a new RMII ethernet driver using 9 pins. 67 /// Create a new RMII ethernet driver using 9 pins.
68 pub fn new<const TX: usize, const RX: usize, A>( 68 pub fn new<const TX: usize, const RX: usize>(
69 queue: &'d mut PacketQueue<TX, RX>, 69 queue: &'d mut PacketQueue<TX, RX>,
70 peri: Peri<'d, T>, 70 peri: Peri<'d, T>,
71 irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, 71 irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd,
72 ref_clk: Peri<'d, impl RefClkPin<T, A>>, 72 ref_clk: Peri<'d, impl RefClkPin<T>>,
73 mdio: Peri<'d, impl MDIOPin<T, A>>, 73 mdio: Peri<'d, impl MDIOPin<T>>,
74 mdc: Peri<'d, impl MDCPin<T, A>>, 74 mdc: Peri<'d, impl MDCPin<T>>,
75 crs: Peri<'d, impl CRSPin<T, A>>, 75 crs: Peri<'d, impl CRSPin<T>>,
76 rx_d0: Peri<'d, impl RXD0Pin<T, A>>, 76 rx_d0: Peri<'d, impl RXD0Pin<T>>,
77 rx_d1: Peri<'d, impl RXD1Pin<T, A>>, 77 rx_d1: Peri<'d, impl RXD1Pin<T>>,
78 tx_d0: Peri<'d, impl TXD0Pin<T, A>>, 78 tx_d0: Peri<'d, impl TXD0Pin<T>>,
79 tx_d1: Peri<'d, impl TXD1Pin<T, A>>, 79 tx_d1: Peri<'d, impl TXD1Pin<T>>,
80 tx_en: Peri<'d, impl TXEnPin<T, A>>, 80 tx_en: Peri<'d, impl TXEnPin<T>>,
81 phy: P, 81 phy: P,
82 mac_addr: [u8; 6], 82 mac_addr: [u8; 6],
83 ) -> Self { 83 ) -> Self {
@@ -110,24 +110,24 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
110 } 110 }
111 111
112 /// Create a new MII ethernet driver using 14 pins. 112 /// Create a new MII ethernet driver using 14 pins.
113 pub fn new_mii<const TX: usize, const RX: usize, A>( 113 pub fn new_mii<const TX: usize, const RX: usize>(
114 queue: &'d mut PacketQueue<TX, RX>, 114 queue: &'d mut PacketQueue<TX, RX>,
115 peri: Peri<'d, T>, 115 peri: Peri<'d, T>,
116 irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, 116 irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd,
117 rx_clk: Peri<'d, impl RXClkPin<T, A>>, 117 rx_clk: Peri<'d, impl RXClkPin<T>>,
118 tx_clk: Peri<'d, impl TXClkPin<T, A>>, 118 tx_clk: Peri<'d, impl TXClkPin<T>>,
119 mdio: Peri<'d, impl MDIOPin<T, A>>, 119 mdio: Peri<'d, impl MDIOPin<T>>,
120 mdc: Peri<'d, impl MDCPin<T, A>>, 120 mdc: Peri<'d, impl MDCPin<T>>,
121 rxdv: Peri<'d, impl RXDVPin<T, A>>, 121 rxdv: Peri<'d, impl RXDVPin<T>>,
122 rx_d0: Peri<'d, impl RXD0Pin<T, A>>, 122 rx_d0: Peri<'d, impl RXD0Pin<T>>,
123 rx_d1: Peri<'d, impl RXD1Pin<T, A>>, 123 rx_d1: Peri<'d, impl RXD1Pin<T>>,
124 rx_d2: Peri<'d, impl RXD2Pin<T, A>>, 124 rx_d2: Peri<'d, impl RXD2Pin<T>>,
125 rx_d3: Peri<'d, impl RXD3Pin<T, A>>, 125 rx_d3: Peri<'d, impl RXD3Pin<T>>,
126 tx_d0: Peri<'d, impl TXD0Pin<T, A>>, 126 tx_d0: Peri<'d, impl TXD0Pin<T>>,
127 tx_d1: Peri<'d, impl TXD1Pin<T, A>>, 127 tx_d1: Peri<'d, impl TXD1Pin<T>>,
128 tx_d2: Peri<'d, impl TXD2Pin<T, A>>, 128 tx_d2: Peri<'d, impl TXD2Pin<T>>,
129 tx_d3: Peri<'d, impl TXD3Pin<T, A>>, 129 tx_d3: Peri<'d, impl TXD3Pin<T>>,
130 tx_en: Peri<'d, impl TXEnPin<T, A>>, 130 tx_en: Peri<'d, impl TXEnPin<T>>,
131 phy: P, 131 phy: P,
132 mac_addr: [u8; 6], 132 mac_addr: [u8; 6],
133 ) -> Self { 133 ) -> Self {
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index ef631bbdc..83fd08e23 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -718,6 +718,7 @@ pub struct AfioRemap<const V: u8>;
718/// Holds the AFIO remap value for a peripheral's pin 718/// Holds the AFIO remap value for a peripheral's pin
719pub struct AfioRemapBool<const V: bool>; 719pub struct AfioRemapBool<const V: bool>;
720 720
721#[cfg(afio)]
721/// Placeholder for a peripheral's pin which cannot be remapped via AFIO. 722/// Placeholder for a peripheral's pin which cannot be remapped via AFIO.
722pub struct AfioRemapNotApplicable; 723pub struct AfioRemapNotApplicable;
723 724
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs
index be0ae2f5f..249bac41c 100644
--- a/embassy-stm32/src/i2c/mod.rs
+++ b/embassy-stm32/src/i2c/mod.rs
@@ -149,10 +149,10 @@ pub struct I2c<'d, M: Mode, IM: MasterMode> {
149 149
150impl<'d> I2c<'d, Async, Master> { 150impl<'d> I2c<'d, Async, Master> {
151 /// Create a new I2C driver. 151 /// Create a new I2C driver.
152 pub fn new<T: Instance, A>( 152 pub fn new<T: Instance, #[cfg(afio)] A>(
153 peri: Peri<'d, T>, 153 peri: Peri<'d, T>,
154 scl: Peri<'d, impl SclPin<T, A>>, 154 scl: Peri<'d, if_afio!(impl SclPin<T, A>)>,
155 sda: Peri<'d, impl SdaPin<T, A>>, 155 sda: Peri<'d, if_afio!(impl SdaPin<T, A>)>,
156 _irq: impl interrupt::typelevel::Binding<T::EventInterrupt, EventInterruptHandler<T>> 156 _irq: impl interrupt::typelevel::Binding<T::EventInterrupt, EventInterruptHandler<T>>
157 + interrupt::typelevel::Binding<T::ErrorInterrupt, ErrorInterruptHandler<T>> 157 + interrupt::typelevel::Binding<T::ErrorInterrupt, ErrorInterruptHandler<T>>
158 + 'd, 158 + 'd,
@@ -173,10 +173,10 @@ impl<'d> I2c<'d, Async, Master> {
173 173
174impl<'d> I2c<'d, Blocking, Master> { 174impl<'d> I2c<'d, Blocking, Master> {
175 /// Create a new blocking I2C driver. 175 /// Create a new blocking I2C driver.
176 pub fn new_blocking<T: Instance, A>( 176 pub fn new_blocking<T: Instance, #[cfg(afio)] A>(
177 peri: Peri<'d, T>, 177 peri: Peri<'d, T>,
178 scl: Peri<'d, impl SclPin<T, A>>, 178 scl: Peri<'d, if_afio!(impl SclPin<T, A>)>,
179 sda: Peri<'d, impl SdaPin<T, A>>, 179 sda: Peri<'d, if_afio!(impl SdaPin<T, A>)>,
180 config: Config, 180 config: Config,
181 ) -> Self { 181 ) -> Self {
182 Self::new_inner( 182 Self::new_inner(
diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs
index 4c634aa17..1b885ec54 100644
--- a/embassy-stm32/src/i2s.rs
+++ b/embassy-stm32/src/i2s.rs
@@ -237,12 +237,12 @@ pub struct I2S<'d, W: Word> {
237 237
238impl<'d, W: Word> I2S<'d, W> { 238impl<'d, W: Word> I2S<'d, W> {
239 /// Create a transmitter driver. 239 /// Create a transmitter driver.
240 pub fn new_txonly<T: Instance, A>( 240 pub fn new_txonly<T: Instance, #[cfg(afio)] A>(
241 peri: Peri<'d, T>, 241 peri: Peri<'d, T>,
242 sd: Peri<'d, impl MosiPin<T, A>>, 242 sd: Peri<'d, if_afio!(impl MosiPin<T, A>)>,
243 ws: Peri<'d, impl WsPin<T, A>>, 243 ws: Peri<'d, if_afio!(impl WsPin<T, A>)>,
244 ck: Peri<'d, impl CkPin<T, A>>, 244 ck: Peri<'d, if_afio!(impl CkPin<T, A>)>,
245 mck: Peri<'d, impl MckPin<T, A>>, 245 mck: Peri<'d, if_afio!(impl MckPin<T, A>)>,
246 txdma: Peri<'d, impl TxDma<T>>, 246 txdma: Peri<'d, impl TxDma<T>>,
247 txdma_buf: &'d mut [W], 247 txdma_buf: &'d mut [W],
248 config: Config, 248 config: Config,
@@ -262,11 +262,11 @@ impl<'d, W: Word> I2S<'d, W> {
262 } 262 }
263 263
264 /// Create a transmitter driver without a master clock pin. 264 /// Create a transmitter driver without a master clock pin.
265 pub fn new_txonly_nomck<T: Instance, A>( 265 pub fn new_txonly_nomck<T: Instance, #[cfg(afio)] A>(
266 peri: Peri<'d, T>, 266 peri: Peri<'d, T>,
267 sd: Peri<'d, impl MosiPin<T, A>>, 267 sd: Peri<'d, if_afio!(impl MosiPin<T, A>)>,
268 ws: Peri<'d, impl WsPin<T, A>>, 268 ws: Peri<'d, if_afio!(impl WsPin<T, A>)>,
269 ck: Peri<'d, impl CkPin<T, A>>, 269 ck: Peri<'d, if_afio!(impl CkPin<T, A>)>,
270 txdma: Peri<'d, impl TxDma<T>>, 270 txdma: Peri<'d, impl TxDma<T>>,
271 txdma_buf: &'d mut [W], 271 txdma_buf: &'d mut [W],
272 config: Config, 272 config: Config,
@@ -286,12 +286,12 @@ impl<'d, W: Word> I2S<'d, W> {
286 } 286 }
287 287
288 /// Create a receiver driver. 288 /// Create a receiver driver.
289 pub fn new_rxonly<T: Instance, A>( 289 pub fn new_rxonly<T: Instance, #[cfg(afio)] A>(
290 peri: Peri<'d, T>, 290 peri: Peri<'d, T>,
291 sd: Peri<'d, impl MisoPin<T, A>>, 291 sd: Peri<'d, if_afio!(impl MisoPin<T, A>)>,
292 ws: Peri<'d, impl WsPin<T, A>>, 292 ws: Peri<'d, if_afio!(impl WsPin<T, A>)>,
293 ck: Peri<'d, impl CkPin<T, A>>, 293 ck: Peri<'d, if_afio!(impl CkPin<T, A>)>,
294 mck: Peri<'d, impl MckPin<T, A>>, 294 mck: Peri<'d, if_afio!(impl MckPin<T, A>)>,
295 rxdma: Peri<'d, impl RxDma<T>>, 295 rxdma: Peri<'d, impl RxDma<T>>,
296 rxdma_buf: &'d mut [W], 296 rxdma_buf: &'d mut [W],
297 config: Config, 297 config: Config,
@@ -313,13 +313,13 @@ impl<'d, W: Word> I2S<'d, W> {
313 #[cfg(any(spi_v4, spi_v5))] 313 #[cfg(any(spi_v4, spi_v5))]
314 314
315 /// Create a full duplex driver. 315 /// Create a full duplex driver.
316 pub fn new_full_duplex<T: Instance, A>( 316 pub fn new_full_duplex<T: Instance, #[cfg(afio)] A>(
317 peri: Peri<'d, T>, 317 peri: Peri<'d, T>,
318 txsd: Peri<'d, impl MosiPin<T, A>>, 318 txsd: Peri<'d, if_afio!(impl MosiPin<T, A>)>,
319 rxsd: Peri<'d, impl MisoPin<T, A>>, 319 rxsd: Peri<'d, if_afio!(impl MisoPin<T, A>)>,
320 ws: Peri<'d, impl WsPin<T, A>>, 320 ws: Peri<'d, if_afio!(impl WsPin<T, A>)>,
321 ck: Peri<'d, impl CkPin<T, A>>, 321 ck: Peri<'d, if_afio!(impl CkPin<T, A>)>,
322 mck: Peri<'d, impl MckPin<T, A>>, 322 mck: Peri<'d, if_afio!(impl MckPin<T, A>)>,
323 txdma: Peri<'d, impl TxDma<T>>, 323 txdma: Peri<'d, impl TxDma<T>>,
324 txdma_buf: &'d mut [W], 324 txdma_buf: &'d mut [W],
325 rxdma: Peri<'d, impl RxDma<T>>, 325 rxdma: Peri<'d, impl RxDma<T>>,
@@ -459,12 +459,12 @@ impl<'d, W: Word> I2S<'d, W> {
459 } 459 }
460 } 460 }
461 461
462 fn new_inner<T: Instance, A>( 462 fn new_inner<T: Instance, #[cfg(afio)] A>(
463 peri: Peri<'d, T>, 463 peri: Peri<'d, T>,
464 txsd: Option<Peri<'d, AnyPin>>, 464 txsd: Option<Peri<'d, AnyPin>>,
465 rxsd: Option<Peri<'d, AnyPin>>, 465 rxsd: Option<Peri<'d, AnyPin>>,
466 ws: Peri<'d, impl WsPin<T, A>>, 466 ws: Peri<'d, if_afio!(impl WsPin<T, A>)>,
467 ck: Peri<'d, impl CkPin<T, A>>, 467 ck: Peri<'d, if_afio!(impl CkPin<T, A>)>,
468 mck: Option<Peri<'d, AnyPin>>, 468 mck: Option<Peri<'d, AnyPin>>,
469 txdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, 469 txdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>,
470 rxdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, 470 rxdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>,
diff --git a/embassy-stm32/src/macros.rs b/embassy-stm32/src/macros.rs
index 8a3abe1ee..def8dcf49 100644
--- a/embassy-stm32/src/macros.rs
+++ b/embassy-stm32/src/macros.rs
@@ -43,7 +43,7 @@ macro_rules! peri_trait_impl {
43macro_rules! pin_trait { 43macro_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)? $(, $afio)?>: crate::gpio::Pin { 46 pub trait $signal<T: $instance $(, M: $mode)? $(, #[cfg(afio)] $afio)?>: crate::gpio::Pin {
47 #[doc = concat!("Get the AF number needed to use this pin as ", stringify!($signal))] 47 #[doc = concat!("Get the AF number needed to use this pin as ", stringify!($signal))]
48 fn af_num(&self) -> u8; 48 fn af_num(&self) -> u8;
49 49
@@ -56,16 +56,23 @@ macro_rules! pin_trait {
56 56
57macro_rules! pin_trait_impl { 57macro_rules! pin_trait_impl {
58 (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $pin:ident, $af:expr $(, $afio:path)?) => { 58 (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $pin:ident, $af:expr $(, $afio:path)?) => {
59 #[cfg(afio)]
59 impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)? $(, $afio)?> for crate::peripherals::$pin { 60 impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)? $(, $afio)?> for crate::peripherals::$pin {
60 fn af_num(&self) -> u8 { 61 fn af_num(&self) -> u8 {
61 $af 62 $af
62 } 63 }
63 64
64 #[cfg(afio)]
65 fn afio_remap(&self) { 65 fn afio_remap(&self) {
66 // nothing 66 // nothing
67 } 67 }
68 } 68 }
69
70 #[cfg(not(afio))]
71 impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for crate::peripherals::$pin {
72 fn af_num(&self) -> u8 {
73 $af
74 }
75 }
69 }; 76 };
70} 77}
71 78
@@ -190,3 +197,46 @@ macro_rules! new_pin {
190 Some(pin.into()) 197 Some(pin.into())
191 }}; 198 }};
192} 199}
200
201#[cfg(afio)]
202macro_rules! if_afio {
203 ($($t:tt)*) => {
204 $($t)*
205 }
206}
207#[cfg(not(afio))]
208macro_rules! if_afio {
209 (($a:ty, A)) => {
210 ($a,)
211 };
212 (($a:ty, $b:ty, A)) => {
213 ($a,$b)
214 };
215 (($a:ty, $b:ty, $c:ty, A)) => {
216 ($a,$b, $c)
217 };
218 ($type:ident<$lt:lifetime, $a:ty, $b:ty, A>) => {
219 $type<$lt, $a, $b>
220 };
221 ($type:ident<$lt:lifetime, $a:ty, $b:ty, $c:ty, A>) => {
222 $type<$lt, $a, $b, $c>
223 };
224 ($type:ident<$a:ty, A>) => {
225 $type<$a>
226 };
227 ($type:ident<$a:ty, $b:ty, A>) => {
228 $type<$a, $b>
229 };
230 ($type:ident<$a:ty, $b:ty, $c:ty, A>) => {
231 $type<$a, $b, $c>
232 };
233 (impl $trait:ident<$a:ty, A>) => {
234 impl $trait<$a>
235 };
236 (impl $trait:ident<$a:ty, $b:ty, A>) => {
237 impl $trait<$a, $b>
238 };
239 (impl $trait:ident<$a:ty, $b:ty, $c:ty, A>) => {
240 impl $trait<$a, $b, $c>
241 };
242}
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs
index 105c617d8..c5373a54d 100644
--- a/embassy-stm32/src/spi/mod.rs
+++ b/embassy-stm32/src/spi/mod.rs
@@ -471,11 +471,11 @@ impl<'d, M: PeriMode> Spi<'d, M> {
471 471
472impl<'d> Spi<'d, Blocking> { 472impl<'d> Spi<'d, Blocking> {
473 /// Create a new blocking SPI driver. 473 /// Create a new blocking SPI driver.
474 pub fn new_blocking<T: Instance, A>( 474 pub fn new_blocking<T: Instance, #[cfg(afio)] A>(
475 peri: Peri<'d, T>, 475 peri: Peri<'d, T>,
476 sck: Peri<'d, impl SckPin<T, A>>, 476 sck: Peri<'d, if_afio!(impl SckPin<T, A>)>,
477 mosi: Peri<'d, impl MosiPin<T, A>>, 477 mosi: Peri<'d, if_afio!(impl MosiPin<T, A>)>,
478 miso: Peri<'d, impl MisoPin<T, A>>, 478 miso: Peri<'d, if_afio!(impl MisoPin<T, A>)>,
479 config: Config, 479 config: Config,
480 ) -> Self { 480 ) -> Self {
481 Self::new_inner( 481 Self::new_inner(
@@ -490,10 +490,10 @@ impl<'d> Spi<'d, Blocking> {
490 } 490 }
491 491
492 /// Create a new blocking SPI driver, in RX-only mode (only MISO pin, no MOSI). 492 /// Create a new blocking SPI driver, in RX-only mode (only MISO pin, no MOSI).
493 pub fn new_blocking_rxonly<T: Instance, A>( 493 pub fn new_blocking_rxonly<T: Instance, #[cfg(afio)] A>(
494 peri: Peri<'d, T>, 494 peri: Peri<'d, T>,
495 sck: Peri<'d, impl SckPin<T, A>>, 495 sck: Peri<'d, if_afio!(impl SckPin<T, A>)>,
496 miso: Peri<'d, impl MisoPin<T, A>>, 496 miso: Peri<'d, if_afio!(impl MisoPin<T, A>)>,
497 config: Config, 497 config: Config,
498 ) -> Self { 498 ) -> Self {
499 Self::new_inner( 499 Self::new_inner(
@@ -508,10 +508,10 @@ impl<'d> Spi<'d, Blocking> {
508 } 508 }
509 509
510 /// Create a new blocking SPI driver, in TX-only mode (only MOSI pin, no MISO). 510 /// Create a new blocking SPI driver, in TX-only mode (only MOSI pin, no MISO).
511 pub fn new_blocking_txonly<T: Instance, A>( 511 pub fn new_blocking_txonly<T: Instance, #[cfg(afio)] A>(
512 peri: Peri<'d, T>, 512 peri: Peri<'d, T>,
513 sck: Peri<'d, impl SckPin<T, A>>, 513 sck: Peri<'d, if_afio!(impl SckPin<T, A>)>,
514 mosi: Peri<'d, impl MosiPin<T, A>>, 514 mosi: Peri<'d, if_afio!(impl MosiPin<T, A>)>,
515 config: Config, 515 config: Config,
516 ) -> Self { 516 ) -> Self {
517 Self::new_inner( 517 Self::new_inner(
@@ -528,9 +528,9 @@ impl<'d> Spi<'d, Blocking> {
528 /// Create a new SPI driver, in TX-only mode, without SCK pin. 528 /// Create a new SPI driver, in TX-only mode, without SCK pin.
529 /// 529 ///
530 /// This can be useful for bit-banging non-SPI protocols. 530 /// This can be useful for bit-banging non-SPI protocols.
531 pub fn new_blocking_txonly_nosck<T: Instance, A>( 531 pub fn new_blocking_txonly_nosck<T: Instance, #[cfg(afio)] A>(
532 peri: Peri<'d, T>, 532 peri: Peri<'d, T>,
533 mosi: Peri<'d, impl MosiPin<T, A>>, 533 mosi: Peri<'d, if_afio!(impl MosiPin<T, A>)>,
534 config: Config, 534 config: Config,
535 ) -> Self { 535 ) -> Self {
536 Self::new_inner( 536 Self::new_inner(
@@ -547,11 +547,11 @@ impl<'d> Spi<'d, Blocking> {
547 547
548impl<'d> Spi<'d, Async> { 548impl<'d> Spi<'d, Async> {
549 /// Create a new SPI driver. 549 /// Create a new SPI driver.
550 pub fn new<T: Instance, A>( 550 pub fn new<T: Instance, #[cfg(afio)] A>(
551 peri: Peri<'d, T>, 551 peri: Peri<'d, T>,
552 sck: Peri<'d, impl SckPin<T, A>>, 552 sck: Peri<'d, if_afio!(impl SckPin<T, A>)>,
553 mosi: Peri<'d, impl MosiPin<T, A>>, 553 mosi: Peri<'d, if_afio!(impl MosiPin<T, A>)>,
554 miso: Peri<'d, impl MisoPin<T, A>>, 554 miso: Peri<'d, if_afio!(impl MisoPin<T, A>)>,
555 tx_dma: Peri<'d, impl TxDma<T>>, 555 tx_dma: Peri<'d, impl TxDma<T>>,
556 rx_dma: Peri<'d, impl RxDma<T>>, 556 rx_dma: Peri<'d, impl RxDma<T>>,
557 config: Config, 557 config: Config,
@@ -568,10 +568,10 @@ impl<'d> Spi<'d, Async> {
568 } 568 }
569 569
570 /// Create a new SPI driver, in RX-only mode (only MISO pin, no MOSI). 570 /// Create a new SPI driver, in RX-only mode (only MISO pin, no MOSI).
571 pub fn new_rxonly<T: Instance, A>( 571 pub fn new_rxonly<T: Instance, #[cfg(afio)] A>(
572 peri: Peri<'d, T>, 572 peri: Peri<'d, T>,
573 sck: Peri<'d, impl SckPin<T, A>>, 573 sck: Peri<'d, if_afio!(impl SckPin<T, A>)>,
574 miso: Peri<'d, impl MisoPin<T, A>>, 574 miso: Peri<'d, if_afio!(impl MisoPin<T, A>)>,
575 #[cfg(any(spi_v1, spi_v2, spi_v3))] tx_dma: Peri<'d, impl TxDma<T>>, 575 #[cfg(any(spi_v1, spi_v2, spi_v3))] tx_dma: Peri<'d, impl TxDma<T>>,
576 rx_dma: Peri<'d, impl RxDma<T>>, 576 rx_dma: Peri<'d, impl RxDma<T>>,
577 config: Config, 577 config: Config,
@@ -591,10 +591,10 @@ impl<'d> Spi<'d, Async> {
591 } 591 }
592 592
593 /// Create a new SPI driver, in TX-only mode (only MOSI pin, no MISO). 593 /// Create a new SPI driver, in TX-only mode (only MOSI pin, no MISO).
594 pub fn new_txonly<T: Instance, A>( 594 pub fn new_txonly<T: Instance, #[cfg(afio)] A>(
595 peri: Peri<'d, T>, 595 peri: Peri<'d, T>,
596 sck: Peri<'d, impl SckPin<T, A>>, 596 sck: Peri<'d, if_afio!(impl SckPin<T, A>)>,
597 mosi: Peri<'d, impl MosiPin<T, A>>, 597 mosi: Peri<'d, if_afio!(impl MosiPin<T, A>)>,
598 tx_dma: Peri<'d, impl TxDma<T>>, 598 tx_dma: Peri<'d, impl TxDma<T>>,
599 config: Config, 599 config: Config,
600 ) -> Self { 600 ) -> Self {
@@ -612,9 +612,9 @@ impl<'d> Spi<'d, Async> {
612 /// Create a new SPI driver, in TX-only mode, without SCK pin. 612 /// Create a new SPI driver, in TX-only mode, without SCK pin.
613 /// 613 ///
614 /// This can be useful for bit-banging non-SPI protocols. 614 /// This can be useful for bit-banging non-SPI protocols.
615 pub fn new_txonly_nosck<T: Instance, A>( 615 pub fn new_txonly_nosck<T: Instance, #[cfg(afio)] A>(
616 peri: Peri<'d, T>, 616 peri: Peri<'d, T>,
617 mosi: Peri<'d, impl MosiPin<T, A>>, 617 mosi: Peri<'d, if_afio!(impl MosiPin<T, A>)>,
618 tx_dma: Peri<'d, impl TxDma<T>>, 618 tx_dma: Peri<'d, impl TxDma<T>>,
619 config: Config, 619 config: Config,
620 ) -> Self { 620 ) -> Self {
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs
index d3b84ed16..693eb3456 100644
--- a/embassy-stm32/src/timer/complementary_pwm.rs
+++ b/embassy-stm32/src/timer/complementary_pwm.rs
@@ -16,15 +16,15 @@ use crate::Peri;
16/// Complementary PWM pin wrapper. 16/// Complementary PWM pin wrapper.
17/// 17///
18/// This wraps a pin to make it usable with PWM. 18/// This wraps a pin to make it usable with PWM.
19pub struct ComplementaryPwmPin<'d, T, C, A> { 19pub struct ComplementaryPwmPin<'d, T, C, #[cfg(afio)] A> {
20 #[allow(unused)] 20 #[allow(unused)]
21 pin: Peri<'d, AnyPin>, 21 pin: Peri<'d, AnyPin>,
22 phantom: PhantomData<(T, C, A)>, 22 phantom: PhantomData<if_afio!((T, C, A))>,
23} 23}
24 24
25impl<'d, T: AdvancedInstance4Channel, C: TimerChannel, A> ComplementaryPwmPin<'d, T, C, A> { 25impl<'d, T: AdvancedInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(ComplementaryPwmPin<'d, T, C, A>) {
26 /// Create a new complementary PWM pin instance. 26 /// Create a new complementary PWM pin instance.
27 pub fn new(pin: Peri<'d, 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 pin.set_as_af(
@@ -58,16 +58,16 @@ pub enum IdlePolarity {
58impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> { 58impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> {
59 /// Create a new complementary PWM driver. 59 /// Create a new complementary PWM driver.
60 #[allow(clippy::too_many_arguments, unused)] 60 #[allow(clippy::too_many_arguments, unused)]
61 pub fn new<A>( 61 pub fn new<#[cfg(afio)] A>(
62 tim: Peri<'d, T>, 62 tim: Peri<'d, T>,
63 ch1: Option<PwmPin<'d, T, Ch1, A>>, 63 ch1: Option<if_afio!(PwmPin<'d, T, Ch1, A>)>,
64 ch1n: Option<ComplementaryPwmPin<'d, T, Ch1, A>>, 64 ch1n: Option<if_afio!(ComplementaryPwmPin<'d, T, Ch1, A>)>,
65 ch2: Option<PwmPin<'d, T, Ch2, A>>, 65 ch2: Option<if_afio!(PwmPin<'d, T, Ch2, A>)>,
66 ch2n: Option<ComplementaryPwmPin<'d, T, Ch2, A>>, 66 ch2n: Option<if_afio!(ComplementaryPwmPin<'d, T, Ch2, A>)>,
67 ch3: Option<PwmPin<'d, T, Ch3, A>>, 67 ch3: Option<if_afio!(PwmPin<'d, T, Ch3, A>)>,
68 ch3n: Option<ComplementaryPwmPin<'d, T, Ch3, A>>, 68 ch3n: Option<if_afio!(ComplementaryPwmPin<'d, T, Ch3, A>)>,
69 ch4: Option<PwmPin<'d, T, Ch4, A>>, 69 ch4: Option<if_afio!(PwmPin<'d, T, Ch4, A>)>,
70 ch4n: Option<ComplementaryPwmPin<'d, T, Ch4, A>>, 70 ch4n: Option<if_afio!(ComplementaryPwmPin<'d, T, Ch4, A>)>,
71 freq: Hertz, 71 freq: Hertz,
72 counting_mode: CountingMode, 72 counting_mode: CountingMode,
73 ) -> Self { 73 ) -> Self {
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs
index 262f9d067..41391bd6d 100644
--- a/embassy-stm32/src/timer/input_capture.rs
+++ b/embassy-stm32/src/timer/input_capture.rs
@@ -17,14 +17,14 @@ use crate::Peri;
17/// Capture pin wrapper. 17/// Capture pin wrapper.
18/// 18///
19/// This wraps a pin to make it usable with capture. 19/// This wraps a pin to make it usable with capture.
20pub struct CapturePin<'d, T, C, A> { 20pub struct CapturePin<'d, T, C, #[cfg(afio)] A> {
21 #[allow(unused)] 21 #[allow(unused)]
22 pin: Peri<'d, AnyPin>, 22 pin: Peri<'d, AnyPin>,
23 phantom: PhantomData<(T, C, A)>, 23 phantom: PhantomData<if_afio!((T, C, A))>,
24} 24}
25impl<'d, T: GeneralInstance4Channel, C: TimerChannel, A> CapturePin<'d, T, C, A> { 25impl<'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, 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 pin.set_as_af(pin.af_num(), AfType::input(pull));
29 CapturePin { 29 CapturePin {
30 pin: pin.into(), 30 pin: pin.into(),
@@ -41,12 +41,12 @@ pub struct InputCapture<'d, T: GeneralInstance4Channel> {
41impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> { 41impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> {
42 /// Create a new input capture driver. 42 /// Create a new input capture driver.
43 #[allow(unused)] 43 #[allow(unused)]
44 pub fn new<A>( 44 pub fn new<#[cfg(afio)] A>(
45 tim: Peri<'d, T>, 45 tim: Peri<'d, T>,
46 ch1: Option<CapturePin<'d, T, Ch1, A>>, 46 ch1: Option<if_afio!(CapturePin<'d, T, Ch1, A>)>,
47 ch2: Option<CapturePin<'d, T, Ch2, A>>, 47 ch2: Option<if_afio!(CapturePin<'d, T, Ch2, A>)>,
48 ch3: Option<CapturePin<'d, T, Ch3, A>>, 48 ch3: Option<if_afio!(CapturePin<'d, T, Ch3, A>)>,
49 ch4: Option<CapturePin<'d, T, Ch4, A>>, 49 ch4: Option<if_afio!(CapturePin<'d, T, Ch4, A>)>,
50 _irq: impl Binding<T::CaptureCompareInterrupt, CaptureCompareInterruptHandler<T>> + 'd, 50 _irq: impl Binding<T::CaptureCompareInterrupt, CaptureCompareInterruptHandler<T>> + 'd,
51 freq: Hertz, 51 freq: Hertz,
52 counting_mode: CountingMode, 52 counting_mode: CountingMode,
diff --git a/embassy-stm32/src/timer/one_pulse.rs b/embassy-stm32/src/timer/one_pulse.rs
index b15cea679..edab38022 100644
--- a/embassy-stm32/src/timer/one_pulse.rs
+++ b/embassy-stm32/src/timer/one_pulse.rs
@@ -64,7 +64,7 @@ impl SealedTriggerSource for Ext {}
64 64
65impl<'d, T: GeneralInstance4Channel, C: TriggerSource + TimerChannel> TriggerPin<'d, T, C> { 65impl<'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<A>(pin: Peri<'d, 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 pin.set_as_af(pin.af_num(), AfType::input(pull));
69 #[cfg(afio)] 69 #[cfg(afio)]
70 pin.afio_remap(); 70 pin.afio_remap();
@@ -77,7 +77,7 @@ impl<'d, T: GeneralInstance4Channel, C: TriggerSource + TimerChannel> TriggerPin
77 77
78impl<'d, T: GeneralInstance4Channel> TriggerPin<'d, T, Ext> { 78impl<'d, T: GeneralInstance4Channel> TriggerPin<'d, T, Ext> {
79 /// Create a new external trigger pin instance. 79 /// Create a new external trigger pin instance.
80 pub fn new_external<A>(pin: Peri<'d, impl ExternalTriggerPin<T, A>>, pull: Pull) -> Self { 80 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)); 81 pin.set_as_af(pin.af_num(), AfType::input(pull));
82 #[cfg(afio)] 82 #[cfg(afio)]
83 pin.afio_remap(); 83 pin.afio_remap();
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs
index 62d7a8550..4c1df0316 100644
--- a/embassy-stm32/src/timer/pwm_input.rs
+++ b/embassy-stm32/src/timer/pwm_input.rs
@@ -18,7 +18,12 @@ pub struct PwmInput<'d, T: GeneralInstance4Channel> {
18 18
19impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { 19impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
20 /// Create a new PWM input driver. 20 /// Create a new PWM input driver.
21 pub fn new_ch1<A>(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch1, A>>, pull: Pull, freq: Hertz) -> Self { 21 pub fn new_ch1<#[cfg(afio)] A>(
22 tim: Peri<'d, T>,
23 pin: Peri<'d, if_afio!(impl TimerPin<T, Ch1, A>)>,
24 pull: Pull,
25 freq: Hertz,
26 ) -> Self {
22 pin.set_as_af(pin.af_num(), AfType::input(pull)); 27 pin.set_as_af(pin.af_num(), AfType::input(pull));
23 #[cfg(afio)] 28 #[cfg(afio)]
24 pin.afio_remap(); 29 pin.afio_remap();
@@ -27,7 +32,12 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
27 } 32 }
28 33
29 /// Create a new PWM input driver. 34 /// Create a new PWM input driver.
30 pub fn new_ch2<A>(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch2, A>>, pull: Pull, freq: Hertz) -> Self { 35 pub fn new_ch2<#[cfg(afio)] A>(
36 tim: Peri<'d, T>,
37 pin: Peri<'d, if_afio!(impl TimerPin<T, Ch2, A>)>,
38 pull: Pull,
39 freq: Hertz,
40 ) -> Self {
31 pin.set_as_af(pin.af_num(), AfType::input(pull)); 41 pin.set_as_af(pin.af_num(), AfType::input(pull));
32 #[cfg(afio)] 42 #[cfg(afio)]
33 pin.afio_remap(); 43 pin.afio_remap();
diff --git a/embassy-stm32/src/timer/qei.rs b/embassy-stm32/src/timer/qei.rs
index 39d051294..528c4a904 100644
--- a/embassy-stm32/src/timer/qei.rs
+++ b/embassy-stm32/src/timer/qei.rs
@@ -20,15 +20,15 @@ pub enum Direction {
20} 20}
21 21
22/// Wrapper for using a pin with QEI. 22/// Wrapper for using a pin with QEI.
23pub struct QeiPin<'d, T, Channel, A> { 23pub struct QeiPin<'d, T, Channel, #[cfg(afio)] A> {
24 #[allow(unused)] 24 #[allow(unused)]
25 pin: Peri<'d, AnyPin>, 25 pin: Peri<'d, AnyPin>,
26 phantom: PhantomData<(T, Channel, A)>, 26 phantom: PhantomData<if_afio!((T, Channel, A))>,
27} 27}
28 28
29impl<'d, T: GeneralInstance4Channel, C: QeiChannel, A> QeiPin<'d, T, C, A> { 29impl<'d, T: GeneralInstance4Channel, C: QeiChannel, #[cfg(afio)] A> if_afio!(QeiPin<'d, T, C, A>) {
30 /// Create a new QEI pin instance. 30 /// Create a new QEI pin instance.
31 pub fn new(pin: Peri<'d, 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 pin.set_as_af(pin.af_num(), AfType::input(Pull::None));
@@ -62,7 +62,11 @@ pub struct Qei<'d, T: GeneralInstance4Channel> {
62impl<'d, T: GeneralInstance4Channel> Qei<'d, T> { 62impl<'d, T: GeneralInstance4Channel> Qei<'d, T> {
63 /// Create a new quadrature decoder driver. 63 /// Create a new quadrature decoder driver.
64 #[allow(unused)] 64 #[allow(unused)]
65 pub fn new<A>(tim: Peri<'d, T>, ch1: QeiPin<'d, T, Ch1, A>, ch2: QeiPin<'d, T, Ch2, A>) -> Self { 65 pub fn new<#[cfg(afio)] A>(
66 tim: Peri<'d, T>,
67 ch1: if_afio!(QeiPin<'d, T, Ch1, A>),
68 ch2: if_afio!(QeiPin<'d, T, Ch2, A>),
69 ) -> Self {
66 Self::new_inner(tim) 70 Self::new_inner(tim)
67 } 71 }
68 72
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs
index 53f7cdd22..c08a3939f 100644
--- a/embassy-stm32/src/timer/simple_pwm.rs
+++ b/embassy-stm32/src/timer/simple_pwm.rs
@@ -14,10 +14,10 @@ use crate::Peri;
14/// PWM pin wrapper. 14/// PWM pin wrapper.
15/// 15///
16/// This wraps a pin to make it usable with PWM. 16/// This wraps a pin to make it usable with PWM.
17pub struct PwmPin<'d, T, C, A> { 17pub struct PwmPin<'d, T, C, #[cfg(afio)] A> {
18 #[allow(unused)] 18 #[allow(unused)]
19 pub(crate) pin: Peri<'d, AnyPin>, 19 pub(crate) pin: Peri<'d, AnyPin>,
20 phantom: PhantomData<(T, C, A)>, 20 phantom: PhantomData<if_afio!((T, C, A))>,
21} 21}
22 22
23/// PWM pin config 23/// PWM pin config
@@ -35,9 +35,9 @@ pub struct PwmPinConfig {
35 pub pull: Pull, 35 pub pull: Pull,
36} 36}
37 37
38impl<'d, T: GeneralInstance4Channel, C: TimerChannel, A> PwmPin<'d, T, C, A> { 38impl<'d, T: GeneralInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(PwmPin<'d, T, C, A>) {
39 /// Create a new PWM pin instance. 39 /// Create a new PWM pin instance.
40 pub fn new(pin: Peri<'d, 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 pin.set_as_af(pin.af_num(), AfType::output(output_type, Speed::VeryHigh));
@@ -50,8 +50,8 @@ impl<'d, T: GeneralInstance4Channel, C: TimerChannel, A> PwmPin<'d, T, C, A> {
50 } 50 }
51 } 51 }
52 52
53 /// Create a new PWM pin instance with config. 53 /// Create a new PWM pin instance with a specific configuration.
54 pub fn new_with_config(pin: Peri<'d, impl TimerPin<T, C, A>>, pin_config: PwmPinConfig) -> Self { 54 pub fn new_with_config(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pin_config: PwmPinConfig) -> Self {
55 critical_section::with(|_| { 55 critical_section::with(|_| {
56 pin.set_low(); 56 pin.set_low();
57 pin.set_as_af( 57 pin.set_as_af(
@@ -184,12 +184,12 @@ pub struct SimplePwm<'d, T: GeneralInstance4Channel> {
184impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { 184impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
185 /// Create a new simple PWM driver. 185 /// Create a new simple PWM driver.
186 #[allow(unused)] 186 #[allow(unused)]
187 pub fn new<A>( 187 pub fn new<#[cfg(afio)] A>(
188 tim: Peri<'d, T>, 188 tim: Peri<'d, T>,
189 ch1: Option<PwmPin<'d, T, Ch1, A>>, 189 ch1: Option<if_afio!(PwmPin<'d, T, Ch1, A>)>,
190 ch2: Option<PwmPin<'d, T, Ch2, A>>, 190 ch2: Option<if_afio!(PwmPin<'d, T, Ch2, A>)>,
191 ch3: Option<PwmPin<'d, T, Ch3, A>>, 191 ch3: Option<if_afio!(PwmPin<'d, T, Ch3, A>)>,
192 ch4: Option<PwmPin<'d, T, Ch4, A>>, 192 ch4: Option<if_afio!(PwmPin<'d, T, Ch4, A>)>,
193 freq: Hertz, 193 freq: Hertz,
194 counting_mode: CountingMode, 194 counting_mode: CountingMode,
195 ) -> Self { 195 ) -> Self {
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs
index 72aeb8357..890c8a80e 100644
--- a/embassy-stm32/src/usart/buffered.rs
+++ b/embassy-stm32/src/usart/buffered.rs
@@ -208,10 +208,10 @@ impl<'d> SetConfig for BufferedUartTx<'d> {
208 208
209impl<'d> BufferedUart<'d> { 209impl<'d> BufferedUart<'d> {
210 /// Create a new bidirectional buffered UART driver 210 /// Create a new bidirectional buffered UART driver
211 pub fn new<T: Instance, A>( 211 pub fn new<T: Instance, #[cfg(afio)] A>(
212 peri: Peri<'d, T>, 212 peri: Peri<'d, T>,
213 rx: Peri<'d, impl RxPin<T, A>>, 213 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
214 tx: Peri<'d, impl TxPin<T, A>>, 214 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
215 tx_buffer: &'d mut [u8], 215 tx_buffer: &'d mut [u8],
216 rx_buffer: &'d mut [u8], 216 rx_buffer: &'d mut [u8],
217 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 217 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
@@ -231,12 +231,12 @@ impl<'d> BufferedUart<'d> {
231 } 231 }
232 232
233 /// Create a new bidirectional buffered UART driver with request-to-send and clear-to-send pins 233 /// Create a new bidirectional buffered UART driver with request-to-send and clear-to-send pins
234 pub fn new_with_rtscts<T: Instance, A>( 234 pub fn new_with_rtscts<T: Instance, #[cfg(afio)] A>(
235 peri: Peri<'d, T>, 235 peri: Peri<'d, T>,
236 rx: Peri<'d, impl RxPin<T, A>>, 236 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
237 tx: Peri<'d, impl TxPin<T, A>>, 237 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
238 rts: Peri<'d, impl RtsPin<T, A>>, 238 rts: Peri<'d, if_afio!(impl RtsPin<T, A>)>,
239 cts: Peri<'d, impl CtsPin<T, A>>, 239 cts: Peri<'d, if_afio!(impl CtsPin<T, A>)>,
240 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 240 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
241 tx_buffer: &'d mut [u8], 241 tx_buffer: &'d mut [u8],
242 rx_buffer: &'d mut [u8], 242 rx_buffer: &'d mut [u8],
@@ -256,11 +256,11 @@ impl<'d> BufferedUart<'d> {
256 } 256 }
257 257
258 /// Create a new bidirectional buffered UART driver with only the RTS pin as the DE pin 258 /// Create a new bidirectional buffered UART driver with only the RTS pin as the DE pin
259 pub fn new_with_rts_as_de<T: Instance, A>( 259 pub fn new_with_rts_as_de<T: Instance, #[cfg(afio)] A>(
260 peri: Peri<'d, T>, 260 peri: Peri<'d, T>,
261 rx: Peri<'d, impl RxPin<T, A>>, 261 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
262 tx: Peri<'d, impl TxPin<T, A>>, 262 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
263 rts: Peri<'d, impl RtsPin<T, A>>, 263 rts: Peri<'d, if_afio!(impl RtsPin<T, A>)>,
264 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 264 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
265 tx_buffer: &'d mut [u8], 265 tx_buffer: &'d mut [u8],
266 rx_buffer: &'d mut [u8], 266 rx_buffer: &'d mut [u8],
@@ -280,11 +280,11 @@ impl<'d> BufferedUart<'d> {
280 } 280 }
281 281
282 /// Create a new bidirectional buffered UART driver with only the request-to-send pin 282 /// Create a new bidirectional buffered UART driver with only the request-to-send pin
283 pub fn new_with_rts<T: Instance, A>( 283 pub fn new_with_rts<T: Instance, #[cfg(afio)] A>(
284 peri: Peri<'d, T>, 284 peri: Peri<'d, T>,
285 rx: Peri<'d, impl RxPin<T, A>>, 285 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
286 tx: Peri<'d, impl TxPin<T, A>>, 286 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
287 rts: Peri<'d, impl RtsPin<T, A>>, 287 rts: Peri<'d, if_afio!(impl RtsPin<T, A>)>,
288 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 288 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
289 tx_buffer: &'d mut [u8], 289 tx_buffer: &'d mut [u8],
290 rx_buffer: &'d mut [u8], 290 rx_buffer: &'d mut [u8],
@@ -305,11 +305,11 @@ impl<'d> BufferedUart<'d> {
305 305
306 /// Create a new bidirectional buffered UART driver with a driver-enable pin 306 /// Create a new bidirectional buffered UART driver with a driver-enable pin
307 #[cfg(not(any(usart_v1, usart_v2)))] 307 #[cfg(not(any(usart_v1, usart_v2)))]
308 pub fn new_with_de<T: Instance, A>( 308 pub fn new_with_de<T: Instance, #[cfg(afio)] A>(
309 peri: Peri<'d, T>, 309 peri: Peri<'d, T>,
310 rx: Peri<'d, impl RxPin<T, A>>, 310 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
311 tx: Peri<'d, impl TxPin<T, A>>, 311 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
312 de: Peri<'d, impl DePin<T, A>>, 312 de: Peri<'d, if_afio!(impl DePin<T, A>)>,
313 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 313 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
314 tx_buffer: &'d mut [u8], 314 tx_buffer: &'d mut [u8],
315 rx_buffer: &'d mut [u8], 315 rx_buffer: &'d mut [u8],
@@ -340,9 +340,9 @@ impl<'d> BufferedUart<'d> {
340 /// Apart from this, the communication protocol is similar to normal USART mode. Any conflict 340 /// Apart from this, the communication protocol is similar to normal USART mode. Any conflict
341 /// on the line must be managed by software (for instance by using a centralized arbiter). 341 /// on the line must be managed by software (for instance by using a centralized arbiter).
342 #[doc(alias("HDSEL"))] 342 #[doc(alias("HDSEL"))]
343 pub fn new_half_duplex<T: Instance, A>( 343 pub fn new_half_duplex<T: Instance, #[cfg(afio)] A>(
344 peri: Peri<'d, T>, 344 peri: Peri<'d, T>,
345 tx: Peri<'d, impl TxPin<T, A>>, 345 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
346 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 346 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
347 tx_buffer: &'d mut [u8], 347 tx_buffer: &'d mut [u8],
348 rx_buffer: &'d mut [u8], 348 rx_buffer: &'d mut [u8],
@@ -379,9 +379,9 @@ impl<'d> BufferedUart<'d> {
379 /// on the line must be managed by software (for instance by using a centralized arbiter). 379 /// on the line must be managed by software (for instance by using a centralized arbiter).
380 #[cfg(not(any(usart_v1, usart_v2)))] 380 #[cfg(not(any(usart_v1, usart_v2)))]
381 #[doc(alias("HDSEL"))] 381 #[doc(alias("HDSEL"))]
382 pub fn new_half_duplex_on_rx<T: Instance, A>( 382 pub fn new_half_duplex_on_rx<T: Instance, #[cfg(afio)] A>(
383 peri: Peri<'d, T>, 383 peri: Peri<'d, T>,
384 rx: Peri<'d, impl RxPin<T, A>>, 384 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
385 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 385 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
386 tx_buffer: &'d mut [u8], 386 tx_buffer: &'d mut [u8],
387 rx_buffer: &'d mut [u8], 387 rx_buffer: &'d mut [u8],
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs
index 21d174bf0..ff211e0c9 100644
--- a/embassy-stm32/src/usart/mod.rs
+++ b/embassy-stm32/src/usart/mod.rs
@@ -429,9 +429,9 @@ impl<'d, M: Mode> SetConfig for UartRx<'d, M> {
429 429
430impl<'d> UartTx<'d, Async> { 430impl<'d> UartTx<'d, Async> {
431 /// Useful if you only want Uart Tx. It saves 1 pin and consumes a little less power. 431 /// Useful if you only want Uart Tx. It saves 1 pin and consumes a little less power.
432 pub fn new<T: Instance, A>( 432 pub fn new<T: Instance, #[cfg(afio)] A>(
433 peri: Peri<'d, T>, 433 peri: Peri<'d, T>,
434 tx: Peri<'d, impl TxPin<T, A>>, 434 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
435 tx_dma: Peri<'d, impl TxDma<T>>, 435 tx_dma: Peri<'d, impl TxDma<T>>,
436 config: Config, 436 config: Config,
437 ) -> Result<Self, ConfigError> { 437 ) -> Result<Self, ConfigError> {
@@ -439,10 +439,10 @@ impl<'d> UartTx<'d, Async> {
439 } 439 }
440 440
441 /// Create a new tx-only UART with a clear-to-send pin 441 /// Create a new tx-only UART with a clear-to-send pin
442 pub fn new_with_cts<T: Instance, A>( 442 pub fn new_with_cts<T: Instance, #[cfg(afio)] A>(
443 peri: Peri<'d, T>, 443 peri: Peri<'d, T>,
444 tx: Peri<'d, impl TxPin<T, A>>, 444 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
445 cts: Peri<'d, impl CtsPin<T, A>>, 445 cts: Peri<'d, if_afio!(impl CtsPin<T, A>)>,
446 tx_dma: Peri<'d, impl TxDma<T>>, 446 tx_dma: Peri<'d, impl TxDma<T>>,
447 config: Config, 447 config: Config,
448 ) -> Result<Self, ConfigError> { 448 ) -> Result<Self, ConfigError> {
@@ -482,19 +482,19 @@ impl<'d> UartTx<'d, Blocking> {
482 /// Create a new blocking tx-only UART with no hardware flow control. 482 /// Create a new blocking tx-only UART with no hardware flow control.
483 /// 483 ///
484 /// Useful if you only want Uart Tx. It saves 1 pin and consumes a little less power. 484 /// Useful if you only want Uart Tx. It saves 1 pin and consumes a little less power.
485 pub fn new_blocking<T: Instance, A>( 485 pub fn new_blocking<T: Instance, #[cfg(afio)] A>(
486 peri: Peri<'d, T>, 486 peri: Peri<'d, T>,
487 tx: Peri<'d, impl TxPin<T, A>>, 487 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
488 config: Config, 488 config: Config,
489 ) -> Result<Self, ConfigError> { 489 ) -> Result<Self, ConfigError> {
490 Self::new_inner(peri, new_pin!(tx, config.tx_af()), None, None, config) 490 Self::new_inner(peri, new_pin!(tx, config.tx_af()), None, None, config)
491 } 491 }
492 492
493 /// Create a new blocking tx-only UART with a clear-to-send pin 493 /// Create a new blocking tx-only UART with a clear-to-send pin
494 pub fn new_blocking_with_cts<T: Instance, A>( 494 pub fn new_blocking_with_cts<T: Instance, #[cfg(afio)] A>(
495 peri: Peri<'d, T>, 495 peri: Peri<'d, T>,
496 tx: Peri<'d, impl TxPin<T, A>>, 496 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
497 cts: Peri<'d, impl CtsPin<T, A>>, 497 cts: Peri<'d, if_afio!(impl CtsPin<T, A>)>,
498 config: Config, 498 config: Config,
499 ) -> Result<Self, ConfigError> { 499 ) -> Result<Self, ConfigError> {
500 Self::new_inner( 500 Self::new_inner(
@@ -662,10 +662,10 @@ impl<'d> UartRx<'d, Async> {
662 /// Create a new rx-only UART with no hardware flow control. 662 /// Create a new rx-only UART with no hardware flow control.
663 /// 663 ///
664 /// Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power. 664 /// Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power.
665 pub fn new<T: Instance, A>( 665 pub fn new<T: Instance, #[cfg(afio)] A>(
666 peri: Peri<'d, T>, 666 peri: Peri<'d, T>,
667 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 667 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
668 rx: Peri<'d, impl RxPin<T, A>>, 668 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
669 rx_dma: Peri<'d, impl RxDma<T>>, 669 rx_dma: Peri<'d, impl RxDma<T>>,
670 config: Config, 670 config: Config,
671 ) -> Result<Self, ConfigError> { 671 ) -> Result<Self, ConfigError> {
@@ -673,11 +673,11 @@ impl<'d> UartRx<'d, Async> {
673 } 673 }
674 674
675 /// Create a new rx-only UART with a request-to-send pin 675 /// Create a new rx-only UART with a request-to-send pin
676 pub fn new_with_rts<T: Instance, A>( 676 pub fn new_with_rts<T: Instance, #[cfg(afio)] A>(
677 peri: Peri<'d, T>, 677 peri: Peri<'d, T>,
678 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 678 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
679 rx: Peri<'d, impl RxPin<T, A>>, 679 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
680 rts: Peri<'d, impl RtsPin<T, A>>, 680 rts: Peri<'d, if_afio!(impl RtsPin<T, A>)>,
681 rx_dma: Peri<'d, impl RxDma<T>>, 681 rx_dma: Peri<'d, impl RxDma<T>>,
682 config: Config, 682 config: Config,
683 ) -> Result<Self, ConfigError> { 683 ) -> Result<Self, ConfigError> {
@@ -913,19 +913,19 @@ impl<'d> UartRx<'d, Blocking> {
913 /// Create a new rx-only UART with no hardware flow control. 913 /// Create a new rx-only UART with no hardware flow control.
914 /// 914 ///
915 /// Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power. 915 /// Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power.
916 pub fn new_blocking<T: Instance, A>( 916 pub fn new_blocking<T: Instance, #[cfg(afio)] A>(
917 peri: Peri<'d, T>, 917 peri: Peri<'d, T>,
918 rx: Peri<'d, impl RxPin<T, A>>, 918 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
919 config: Config, 919 config: Config,
920 ) -> Result<Self, ConfigError> { 920 ) -> Result<Self, ConfigError> {
921 Self::new_inner(peri, new_pin!(rx, config.rx_af()), None, None, config) 921 Self::new_inner(peri, new_pin!(rx, config.rx_af()), None, None, config)
922 } 922 }
923 923
924 /// Create a new rx-only UART with a request-to-send pin 924 /// Create a new rx-only UART with a request-to-send pin
925 pub fn new_blocking_with_rts<T: Instance, A>( 925 pub fn new_blocking_with_rts<T: Instance, #[cfg(afio)] A>(
926 peri: Peri<'d, T>, 926 peri: Peri<'d, T>,
927 rx: Peri<'d, impl RxPin<T, A>>, 927 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
928 rts: Peri<'d, impl RtsPin<T, A>>, 928 rts: Peri<'d, if_afio!(impl RtsPin<T, A>)>,
929 config: Config, 929 config: Config,
930 ) -> Result<Self, ConfigError> { 930 ) -> Result<Self, ConfigError> {
931 Self::new_inner( 931 Self::new_inner(
@@ -1109,10 +1109,10 @@ fn drop_tx_rx(info: &Info, state: &State) {
1109 1109
1110impl<'d> Uart<'d, Async> { 1110impl<'d> Uart<'d, Async> {
1111 /// Create a new bidirectional UART 1111 /// Create a new bidirectional UART
1112 pub fn new<T: Instance, A>( 1112 pub fn new<T: Instance, #[cfg(afio)] A>(
1113 peri: Peri<'d, T>, 1113 peri: Peri<'d, T>,
1114 rx: Peri<'d, impl RxPin<T, A>>, 1114 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
1115 tx: Peri<'d, impl TxPin<T, A>>, 1115 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
1116 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 1116 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
1117 tx_dma: Peri<'d, impl TxDma<T>>, 1117 tx_dma: Peri<'d, impl TxDma<T>>,
1118 rx_dma: Peri<'d, impl RxDma<T>>, 1118 rx_dma: Peri<'d, impl RxDma<T>>,
@@ -1132,13 +1132,13 @@ impl<'d> Uart<'d, Async> {
1132 } 1132 }
1133 1133
1134 /// Create a new bidirectional UART with request-to-send and clear-to-send pins 1134 /// Create a new bidirectional UART with request-to-send and clear-to-send pins
1135 pub fn new_with_rtscts<T: Instance, A>( 1135 pub fn new_with_rtscts<T: Instance, #[cfg(afio)] A>(
1136 peri: Peri<'d, T>, 1136 peri: Peri<'d, T>,
1137 rx: Peri<'d, impl RxPin<T, A>>, 1137 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
1138 tx: Peri<'d, impl TxPin<T, A>>, 1138 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
1139 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 1139 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
1140 rts: Peri<'d, impl RtsPin<T, A>>, 1140 rts: Peri<'d, if_afio!(impl RtsPin<T, A>)>,
1141 cts: Peri<'d, impl CtsPin<T, A>>, 1141 cts: Peri<'d, if_afio!(impl CtsPin<T, A>)>,
1142 tx_dma: Peri<'d, impl TxDma<T>>, 1142 tx_dma: Peri<'d, impl TxDma<T>>,
1143 rx_dma: Peri<'d, impl RxDma<T>>, 1143 rx_dma: Peri<'d, impl RxDma<T>>,
1144 config: Config, 1144 config: Config,
@@ -1158,12 +1158,12 @@ impl<'d> Uart<'d, Async> {
1158 1158
1159 #[cfg(not(any(usart_v1, usart_v2)))] 1159 #[cfg(not(any(usart_v1, usart_v2)))]
1160 /// Create a new bidirectional UART with a driver-enable pin 1160 /// Create a new bidirectional UART with a driver-enable pin
1161 pub fn new_with_de<T: Instance, A>( 1161 pub fn new_with_de<T: Instance, #[cfg(afio)] A>(
1162 peri: Peri<'d, T>, 1162 peri: Peri<'d, T>,
1163 rx: Peri<'d, impl RxPin<T, A>>, 1163 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
1164 tx: Peri<'d, impl TxPin<T, A>>, 1164 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
1165 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 1165 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
1166 de: Peri<'d, impl DePin<T, A>>, 1166 de: Peri<'d, if_afio!(impl DePin<T, A>)>,
1167 tx_dma: Peri<'d, impl TxDma<T>>, 1167 tx_dma: Peri<'d, impl TxDma<T>>,
1168 rx_dma: Peri<'d, impl RxDma<T>>, 1168 rx_dma: Peri<'d, impl RxDma<T>>,
1169 config: Config, 1169 config: Config,
@@ -1193,9 +1193,9 @@ impl<'d> Uart<'d, Async> {
1193 /// Apart from this, the communication protocol is similar to normal USART mode. Any conflict 1193 /// Apart from this, the communication protocol is similar to normal USART mode. Any conflict
1194 /// on the line must be managed by software (for instance by using a centralized arbiter). 1194 /// on the line must be managed by software (for instance by using a centralized arbiter).
1195 #[doc(alias("HDSEL"))] 1195 #[doc(alias("HDSEL"))]
1196 pub fn new_half_duplex<T: Instance, A>( 1196 pub fn new_half_duplex<T: Instance, #[cfg(afio)] A>(
1197 peri: Peri<'d, T>, 1197 peri: Peri<'d, T>,
1198 tx: Peri<'d, impl TxPin<T, A>>, 1198 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
1199 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 1199 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
1200 tx_dma: Peri<'d, impl TxDma<T>>, 1200 tx_dma: Peri<'d, impl TxDma<T>>,
1201 rx_dma: Peri<'d, impl RxDma<T>>, 1201 rx_dma: Peri<'d, impl RxDma<T>>,
@@ -1232,9 +1232,9 @@ impl<'d> Uart<'d, Async> {
1232 /// on the line must be managed by software (for instance by using a centralized arbiter). 1232 /// on the line must be managed by software (for instance by using a centralized arbiter).
1233 #[cfg(not(any(usart_v1, usart_v2)))] 1233 #[cfg(not(any(usart_v1, usart_v2)))]
1234 #[doc(alias("HDSEL"))] 1234 #[doc(alias("HDSEL"))]
1235 pub fn new_half_duplex_on_rx<T: Instance, A>( 1235 pub fn new_half_duplex_on_rx<T: Instance, #[cfg(afio)] A>(
1236 peri: Peri<'d, T>, 1236 peri: Peri<'d, T>,
1237 rx: Peri<'d, impl RxPin<T, A>>, 1237 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
1238 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 1238 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
1239 tx_dma: Peri<'d, impl TxDma<T>>, 1239 tx_dma: Peri<'d, impl TxDma<T>>,
1240 rx_dma: Peri<'d, impl RxDma<T>>, 1240 rx_dma: Peri<'d, impl RxDma<T>>,
@@ -1280,10 +1280,10 @@ impl<'d> Uart<'d, Async> {
1280 1280
1281impl<'d> Uart<'d, Blocking> { 1281impl<'d> Uart<'d, Blocking> {
1282 /// Create a new blocking bidirectional UART. 1282 /// Create a new blocking bidirectional UART.
1283 pub fn new_blocking<T: Instance, A>( 1283 pub fn new_blocking<T: Instance, #[cfg(afio)] A>(
1284 peri: Peri<'d, T>, 1284 peri: Peri<'d, T>,
1285 rx: Peri<'d, impl RxPin<T, A>>, 1285 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
1286 tx: Peri<'d, impl TxPin<T, A>>, 1286 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
1287 config: Config, 1287 config: Config,
1288 ) -> Result<Self, ConfigError> { 1288 ) -> Result<Self, ConfigError> {
1289 Self::new_inner( 1289 Self::new_inner(
@@ -1300,12 +1300,12 @@ impl<'d> Uart<'d, Blocking> {
1300 } 1300 }
1301 1301
1302 /// Create a new bidirectional UART with request-to-send and clear-to-send pins 1302 /// Create a new bidirectional UART with request-to-send and clear-to-send pins
1303 pub fn new_blocking_with_rtscts<T: Instance, A>( 1303 pub fn new_blocking_with_rtscts<T: Instance, #[cfg(afio)] A>(
1304 peri: Peri<'d, T>, 1304 peri: Peri<'d, T>,
1305 rx: Peri<'d, impl RxPin<T, A>>, 1305 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
1306 tx: Peri<'d, impl TxPin<T, A>>, 1306 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
1307 rts: Peri<'d, impl RtsPin<T, A>>, 1307 rts: Peri<'d, if_afio!(impl RtsPin<T, A>)>,
1308 cts: Peri<'d, impl CtsPin<T, A>>, 1308 cts: Peri<'d, if_afio!(impl CtsPin<T, A>)>,
1309 config: Config, 1309 config: Config,
1310 ) -> Result<Self, ConfigError> { 1310 ) -> Result<Self, ConfigError> {
1311 Self::new_inner( 1311 Self::new_inner(
@@ -1323,11 +1323,11 @@ impl<'d> Uart<'d, Blocking> {
1323 1323
1324 #[cfg(not(any(usart_v1, usart_v2)))] 1324 #[cfg(not(any(usart_v1, usart_v2)))]
1325 /// Create a new bidirectional UART with a driver-enable pin 1325 /// Create a new bidirectional UART with a driver-enable pin
1326 pub fn new_blocking_with_de<T: Instance, A>( 1326 pub fn new_blocking_with_de<T: Instance, #[cfg(afio)] A>(
1327 peri: Peri<'d, T>, 1327 peri: Peri<'d, T>,
1328 rx: Peri<'d, impl RxPin<T, A>>, 1328 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
1329 tx: Peri<'d, impl TxPin<T, A>>, 1329 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
1330 de: Peri<'d, impl DePin<T, A>>, 1330 de: Peri<'d, if_afio!(impl DePin<T, A>)>,
1331 config: Config, 1331 config: Config,
1332 ) -> Result<Self, ConfigError> { 1332 ) -> Result<Self, ConfigError> {
1333 Self::new_inner( 1333 Self::new_inner(
@@ -1354,9 +1354,9 @@ impl<'d> Uart<'d, Blocking> {
1354 /// Apart from this, the communication protocol is similar to normal USART mode. Any conflict 1354 /// Apart from this, the communication protocol is similar to normal USART mode. Any conflict
1355 /// on the line must be managed by software (for instance by using a centralized arbiter). 1355 /// on the line must be managed by software (for instance by using a centralized arbiter).
1356 #[doc(alias("HDSEL"))] 1356 #[doc(alias("HDSEL"))]
1357 pub fn new_blocking_half_duplex<T: Instance, A>( 1357 pub fn new_blocking_half_duplex<T: Instance, #[cfg(afio)] A>(
1358 peri: Peri<'d, T>, 1358 peri: Peri<'d, T>,
1359 tx: Peri<'d, impl TxPin<T, A>>, 1359 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
1360 mut config: Config, 1360 mut config: Config,
1361 readback: HalfDuplexReadback, 1361 readback: HalfDuplexReadback,
1362 ) -> Result<Self, ConfigError> { 1362 ) -> Result<Self, ConfigError> {
@@ -1390,9 +1390,9 @@ impl<'d> Uart<'d, Blocking> {
1390 /// on the line must be managed by software (for instance by using a centralized arbiter). 1390 /// on the line must be managed by software (for instance by using a centralized arbiter).
1391 #[cfg(not(any(usart_v1, usart_v2)))] 1391 #[cfg(not(any(usart_v1, usart_v2)))]
1392 #[doc(alias("HDSEL"))] 1392 #[doc(alias("HDSEL"))]
1393 pub fn new_blocking_half_duplex_on_rx<T: Instance, A>( 1393 pub fn new_blocking_half_duplex_on_rx<T: Instance, #[cfg(afio)] A>(
1394 peri: Peri<'d, T>, 1394 peri: Peri<'d, T>,
1395 rx: Peri<'d, impl RxPin<T, A>>, 1395 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
1396 mut config: Config, 1396 mut config: Config,
1397 readback: HalfDuplexReadback, 1397 readback: HalfDuplexReadback,
1398 ) -> Result<Self, ConfigError> { 1398 ) -> Result<Self, ConfigError> {