diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-02-23 20:21:28 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-02-23 20:21:28 +0100 |
| commit | 052f370de9863df171e48d88a24e89b420b23ff7 (patch) | |
| tree | 805de805351b184ec5f8b30d75f1acadaf6c3fa3 | |
| parent | 30ce71127a3d8117ece329c2ea66f15dee92f98b (diff) | |
stm32: move ADC, DAC pin impls to build.rs
| -rw-r--r-- | embassy-stm32/build.rs | 22 | ||||
| -rw-r--r-- | embassy-stm32/src/adc/mod.rs | 60 | ||||
| -rw-r--r-- | 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 41f5ce591..2b642db84 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -448,6 +448,28 @@ fn main() { | |||
| 448 | pin_trait_impl!(#tr, #peri, #pin_name, #af); | 448 | pin_trait_impl!(#tr, #peri, #pin_name, #af); |
| 449 | }) | 449 | }) |
| 450 | } | 450 | } |
| 451 | |||
| 452 | // ADC is special | ||
| 453 | if regs.kind == "adc" { | ||
| 454 | let peri = format_ident!("{}", p.name); | ||
| 455 | let pin_name = format_ident!("{}", pin.pin); | ||
| 456 | let ch: u8 = pin.signal.strip_prefix("IN").unwrap().parse().unwrap(); | ||
| 457 | |||
| 458 | g.extend(quote! { | ||
| 459 | impl_adc_pin!( #peri, #pin_name, #ch); | ||
| 460 | }) | ||
| 461 | } | ||
| 462 | |||
| 463 | // DAC is special | ||
| 464 | if regs.kind == "dac" { | ||
| 465 | let peri = format_ident!("{}", p.name); | ||
| 466 | let pin_name = format_ident!("{}", pin.pin); | ||
| 467 | let ch: u8 = pin.signal.strip_prefix("OUT").unwrap().parse().unwrap(); | ||
| 468 | |||
| 469 | g.extend(quote! { | ||
| 470 | impl_dac_pin!( #peri, #pin_name, #ch); | ||
| 471 | }) | ||
| 472 | } | ||
| 451 | } | 473 | } |
| 452 | } | 474 | } |
| 453 | } | 475 | } |
diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs index d0fc188d5..86f33ca19 100644 --- a/embassy-stm32/src/adc/mod.rs +++ b/embassy-stm32/src/adc/mod.rs | |||
| @@ -69,68 +69,14 @@ crate::pac::peripherals!( | |||
| 69 | }; | 69 | }; |
| 70 | ); | 70 | ); |
| 71 | 71 | ||
| 72 | macro_rules! impl_pin { | 72 | macro_rules! impl_adc_pin { |
| 73 | ($inst:ident, $pin:ident, $ch:expr) => { | 73 | ($inst:ident, $pin:ident, $ch:expr) => { |
| 74 | impl AdcPin<peripherals::$inst> for peripherals::$pin {} | 74 | impl crate::adc::AdcPin<peripherals::$inst> for crate::peripherals::$pin {} |
| 75 | 75 | ||
| 76 | impl sealed::AdcPin<peripherals::$inst> for peripherals::$pin { | 76 | impl crate::adc::sealed::AdcPin<peripherals::$inst> for crate::peripherals::$pin { |
| 77 | fn channel(&self) -> u8 { | 77 | fn channel(&self) -> u8 { |
| 78 | $ch | 78 | $ch |
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| 81 | }; | 81 | }; |
| 82 | } | 82 | } |
| 83 | |||
| 84 | crate::pac::peripheral_pins!( | ||
| 85 | ($inst:ident, adc, ADC, $pin:ident, IN0) => { | ||
| 86 | impl_pin!($inst, $pin, 0); | ||
| 87 | }; | ||
| 88 | ($inst:ident, adc, ADC, $pin:ident, IN1) => { | ||
| 89 | impl_pin!($inst, $pin, 1); | ||
| 90 | }; | ||
| 91 | ($inst:ident, adc, ADC, $pin:ident, IN2) => { | ||
| 92 | impl_pin!($inst, $pin, 2); | ||
| 93 | }; | ||
| 94 | ($inst:ident, adc, ADC, $pin:ident, IN3) => { | ||
| 95 | impl_pin!($inst, $pin, 3); | ||
| 96 | }; | ||
| 97 | ($inst:ident, adc, ADC, $pin:ident, IN4) => { | ||
| 98 | impl_pin!($inst, $pin, 4); | ||
| 99 | }; | ||
| 100 | ($inst:ident, adc, ADC, $pin:ident, IN5) => { | ||
| 101 | impl_pin!($inst, $pin, 5); | ||
| 102 | }; | ||
| 103 | ($inst:ident, adc, ADC, $pin:ident, IN6) => { | ||
| 104 | impl_pin!($inst, $pin, 6); | ||
| 105 | }; | ||
| 106 | ($inst:ident, adc, ADC, $pin:ident, IN7) => { | ||
| 107 | impl_pin!($inst, $pin, 7); | ||
| 108 | }; | ||
| 109 | ($inst:ident, adc, ADC, $pin:ident, IN8) => { | ||
| 110 | impl_pin!($inst, $pin, 8); | ||
| 111 | }; | ||
| 112 | ($inst:ident, adc, ADC, $pin:ident, IN9) => { | ||
| 113 | impl_pin!($inst, $pin, 9); | ||
| 114 | }; | ||
| 115 | ($inst:ident, adc, ADC, $pin:ident, IN10) => { | ||
| 116 | impl_pin!($inst, $pin, 10); | ||
| 117 | }; | ||
| 118 | ($inst:ident, adc, ADC, $pin:ident, IN11) => { | ||
| 119 | impl_pin!($inst, $pin, 11); | ||
| 120 | }; | ||
| 121 | ($inst:ident, adc, ADC, $pin:ident, IN12) => { | ||
| 122 | impl_pin!($inst, $pin, 12); | ||
| 123 | }; | ||
| 124 | ($inst:ident, adc, ADC, $pin:ident, IN13) => { | ||
| 125 | impl_pin!($inst, $pin, 13); | ||
| 126 | }; | ||
| 127 | ($inst:ident, adc, ADC, $pin:ident, IN14) => { | ||
| 128 | impl_pin!($inst, $pin, 14); | ||
| 129 | }; | ||
| 130 | ($inst:ident, adc, ADC, $pin:ident, IN15) => { | ||
| 131 | impl_pin!($inst, $pin, 15); | ||
| 132 | }; | ||
| 133 | ($inst:ident, adc, ADC, $pin:ident, IN16) => { | ||
| 134 | impl_pin!($inst, $pin, 16); | ||
| 135 | }; | ||
| 136 | ); | ||
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 1acb0a9ae..7432c34a0 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs | |||
| @@ -10,13 +10,11 @@ pub(crate) mod sealed { | |||
| 10 | pub trait Instance { | 10 | pub trait Instance { |
| 11 | fn regs() -> &'static crate::pac::dac::Dac; | 11 | fn regs() -> &'static crate::pac::dac::Dac; |
| 12 | } | 12 | } |
| 13 | |||
| 14 | pub trait DacPin<T: Instance, const C: u8>: crate::gpio::Pin {} | ||
| 15 | } | 13 | } |
| 16 | 14 | ||
| 17 | pub trait Instance: sealed::Instance + 'static {} | 15 | pub trait Instance: sealed::Instance + 'static {} |
| 18 | 16 | ||
| 19 | pub trait DacPin<T: Instance, const C: u8>: sealed::DacPin<T, C> + 'static {} | 17 | pub trait DacPin<T: Instance, const C: u8>: crate::gpio::Pin + 'static {} |
| 20 | 18 | ||
| 21 | crate::pac::peripherals!( | 19 | crate::pac::peripherals!( |
| 22 | (dac, $inst:ident) => { | 20 | (dac, $inst:ident) => { |
| @@ -30,19 +28,8 @@ crate::pac::peripherals!( | |||
| 30 | }; | 28 | }; |
| 31 | ); | 29 | ); |
| 32 | 30 | ||
| 33 | crate::pac::peripheral_pins!( | 31 | macro_rules! impl_dac_pin { |
| 34 | ($inst:ident, dac, DAC, $pin:ident, OUT1) => { | 32 | ($inst:ident, $pin:ident, $ch:expr) => { |
| 35 | impl DacPin<peripherals::$inst, 1> for peripherals::$pin {} | 33 | impl crate::dac::DacPin<peripherals::$inst, $ch> for crate::peripherals::$pin {} |
| 36 | |||
| 37 | impl sealed::DacPin<peripherals::$inst, 1> for peripherals::$pin { | ||
| 38 | } | ||
| 39 | |||
| 40 | }; | ||
| 41 | |||
| 42 | ($inst:ident, dac, DAC, $pin:ident, OUT2) => { | ||
| 43 | impl DacPin<peripherals::$inst, 2> for peripherals::$pin {} | ||
| 44 | |||
| 45 | impl sealed::DacPin<peripherals::$inst, 2> for peripherals::$pin { | ||
| 46 | } | ||
| 47 | }; | 34 | }; |
| 48 | ); | 35 | } |
