From 052f370de9863df171e48d88a24e89b420b23ff7 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 23 Feb 2022 20:21:28 +0100 Subject: [PATCH] stm32: move ADC, DAC pin impls to build.rs --- embassy-stm32/build.rs | 22 +++++++++++++ embassy-stm32/src/adc/mod.rs | 60 ++---------------------------------- embassy-stm32/src/dac/mod.rs | 23 +++----------- 3 files changed, 30 insertions(+), 75 deletions(-) diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 41f5ce59..2b642db8 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -448,6 +448,28 @@ fn main() { pin_trait_impl!(#tr, #peri, #pin_name, #af); }) } + + // ADC is special + if regs.kind == "adc" { + let peri = format_ident!("{}", p.name); + let pin_name = format_ident!("{}", pin.pin); + let ch: u8 = pin.signal.strip_prefix("IN").unwrap().parse().unwrap(); + + g.extend(quote! { + impl_adc_pin!( #peri, #pin_name, #ch); + }) + } + + // DAC is special + if regs.kind == "dac" { + let peri = format_ident!("{}", p.name); + let pin_name = format_ident!("{}", pin.pin); + let ch: u8 = pin.signal.strip_prefix("OUT").unwrap().parse().unwrap(); + + g.extend(quote! { + impl_dac_pin!( #peri, #pin_name, #ch); + }) + } } } } diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs index d0fc188d..86f33ca1 100644 --- a/embassy-stm32/src/adc/mod.rs +++ b/embassy-stm32/src/adc/mod.rs @@ -69,68 +69,14 @@ crate::pac::peripherals!( }; ); -macro_rules! impl_pin { +macro_rules! impl_adc_pin { ($inst:ident, $pin:ident, $ch:expr) => { - impl AdcPin for peripherals::$pin {} + impl crate::adc::AdcPin for crate::peripherals::$pin {} - impl sealed::AdcPin for peripherals::$pin { + impl crate::adc::sealed::AdcPin for crate::peripherals::$pin { fn channel(&self) -> u8 { $ch } } }; } - -crate::pac::peripheral_pins!( - ($inst:ident, adc, ADC, $pin:ident, IN0) => { - impl_pin!($inst, $pin, 0); - }; - ($inst:ident, adc, ADC, $pin:ident, IN1) => { - impl_pin!($inst, $pin, 1); - }; - ($inst:ident, adc, ADC, $pin:ident, IN2) => { - impl_pin!($inst, $pin, 2); - }; - ($inst:ident, adc, ADC, $pin:ident, IN3) => { - impl_pin!($inst, $pin, 3); - }; - ($inst:ident, adc, ADC, $pin:ident, IN4) => { - impl_pin!($inst, $pin, 4); - }; - ($inst:ident, adc, ADC, $pin:ident, IN5) => { - impl_pin!($inst, $pin, 5); - }; - ($inst:ident, adc, ADC, $pin:ident, IN6) => { - impl_pin!($inst, $pin, 6); - }; - ($inst:ident, adc, ADC, $pin:ident, IN7) => { - impl_pin!($inst, $pin, 7); - }; - ($inst:ident, adc, ADC, $pin:ident, IN8) => { - impl_pin!($inst, $pin, 8); - }; - ($inst:ident, adc, ADC, $pin:ident, IN9) => { - impl_pin!($inst, $pin, 9); - }; - ($inst:ident, adc, ADC, $pin:ident, IN10) => { - impl_pin!($inst, $pin, 10); - }; - ($inst:ident, adc, ADC, $pin:ident, IN11) => { - impl_pin!($inst, $pin, 11); - }; - ($inst:ident, adc, ADC, $pin:ident, IN12) => { - impl_pin!($inst, $pin, 12); - }; - ($inst:ident, adc, ADC, $pin:ident, IN13) => { - impl_pin!($inst, $pin, 13); - }; - ($inst:ident, adc, ADC, $pin:ident, IN14) => { - impl_pin!($inst, $pin, 14); - }; - ($inst:ident, adc, ADC, $pin:ident, IN15) => { - impl_pin!($inst, $pin, 15); - }; - ($inst:ident, adc, ADC, $pin:ident, IN16) => { - impl_pin!($inst, $pin, 16); - }; -); diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 1acb0a9a..7432c34a 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs @@ -10,13 +10,11 @@ pub(crate) mod sealed { pub trait Instance { fn regs() -> &'static crate::pac::dac::Dac; } - - pub trait DacPin: crate::gpio::Pin {} } pub trait Instance: sealed::Instance + 'static {} -pub trait DacPin: sealed::DacPin + 'static {} +pub trait DacPin: crate::gpio::Pin + 'static {} crate::pac::peripherals!( (dac, $inst:ident) => { @@ -30,19 +28,8 @@ crate::pac::peripherals!( }; ); -crate::pac::peripheral_pins!( - ($inst:ident, dac, DAC, $pin:ident, OUT1) => { - impl DacPin for peripherals::$pin {} - - impl sealed::DacPin for peripherals::$pin { - } - +macro_rules! impl_dac_pin { + ($inst:ident, $pin:ident, $ch:expr) => { + impl crate::dac::DacPin for crate::peripherals::$pin {} }; - - ($inst:ident, dac, DAC, $pin:ident, OUT2) => { - impl DacPin for peripherals::$pin {} - - impl sealed::DacPin for peripherals::$pin { - } - }; -); +}