You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
drivers: migrate to new_pin! / set_as_af! macros (fixes CAN remap bug)
Adds the `new_pin!` and `set_as_af!` macros to macros.rs (mirroring
embassy-stm32 verbatim) and rewrites every driver `new*()` call site
to use them. This collapses the previous pattern
tx.set_as_af_output(AFType::OutputPushPull, Speed::High);
#[cfg(afio)]
tx.afio_remap();
// ...later...
Some(tx.into())
into a single
new_pin!(tx, AfType::output(OutputType::PushPull, Speed::High))
The 96 scattered `#[cfg(afio)] pin.afio_remap();` calls go away
because the macros own the cfg dispatch. Drivers are direction-
agnostic — input pins go through `new_pin!(pin, AfType::input(pull))`,
output pins through `AfType::output(...)`.
This also fixes a correctness bug: the CAN driver's `new_inner`
configured pins via raw `pin.set_mode_cnf(...)` calls, which the
earlier driver migration regex didn't match, so the
`#[cfg(afio)] pin.afio_remap()` injection silently skipped CAN. On V3
chips a user typing `Remap<2>` for CAN1 pins would compile but the
PCFR1.CAN1_RM bits would never get written — runtime CAN1 stayed on
the default group. Routing CAN through the same `set_as_af!` macro
restores the typesafe contract.
Driver-by-driver:
- USART: 14 sites
- SPI: 8 sites
- I2C: 1 site (with cfg(gpio_x0) open-drain fallback)
- CAN: 2 sites in `new_inner` (was the bug)
- timer simple_pwm + complementary_pwm: 1 macro each
USART's `new_half_duplex` / `new_blocking_half_duplex` now select
push-pull vs open-drain via a `#[cfg(not(gpio_x0))] let af = ...`
pair before the `new_pin!` call, matching the family-conditional
behaviour the original code had.
All 11 example families (ch32v003 ch32v006 ch32v103 ch32v203
ch32v208 ch32v305 ch32v307 ch32l103 ch32x035 ch641 ch643) build
clean with `cargo check`.
0 commit comments