stm32: move ADC, DAC pin impls to build.rs
This commit is contained in:
parent
30ce71127a
commit
052f370de9
@ -448,6 +448,28 @@ fn main() {
|
|||||||
pin_trait_impl!(#tr, #peri, #pin_name, #af);
|
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);
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,68 +69,14 @@ crate::pac::peripherals!(
|
|||||||
};
|
};
|
||||||
);
|
);
|
||||||
|
|
||||||
macro_rules! impl_pin {
|
macro_rules! impl_adc_pin {
|
||||||
($inst:ident, $pin:ident, $ch:expr) => {
|
($inst:ident, $pin:ident, $ch:expr) => {
|
||||||
impl AdcPin<peripherals::$inst> for peripherals::$pin {}
|
impl crate::adc::AdcPin<peripherals::$inst> for crate::peripherals::$pin {}
|
||||||
|
|
||||||
impl sealed::AdcPin<peripherals::$inst> for peripherals::$pin {
|
impl crate::adc::sealed::AdcPin<peripherals::$inst> for crate::peripherals::$pin {
|
||||||
fn channel(&self) -> u8 {
|
fn channel(&self) -> u8 {
|
||||||
$ch
|
$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);
|
|
||||||
};
|
|
||||||
);
|
|
||||||
|
@ -10,13 +10,11 @@ pub(crate) mod sealed {
|
|||||||
pub trait Instance {
|
pub trait Instance {
|
||||||
fn regs() -> &'static crate::pac::dac::Dac;
|
fn regs() -> &'static crate::pac::dac::Dac;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait DacPin<T: Instance, const C: u8>: crate::gpio::Pin {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Instance: sealed::Instance + 'static {}
|
pub trait Instance: sealed::Instance + 'static {}
|
||||||
|
|
||||||
pub trait DacPin<T: Instance, const C: u8>: sealed::DacPin<T, C> + 'static {}
|
pub trait DacPin<T: Instance, const C: u8>: crate::gpio::Pin + 'static {}
|
||||||
|
|
||||||
crate::pac::peripherals!(
|
crate::pac::peripherals!(
|
||||||
(dac, $inst:ident) => {
|
(dac, $inst:ident) => {
|
||||||
@ -30,19 +28,8 @@ crate::pac::peripherals!(
|
|||||||
};
|
};
|
||||||
);
|
);
|
||||||
|
|
||||||
crate::pac::peripheral_pins!(
|
macro_rules! impl_dac_pin {
|
||||||
($inst:ident, dac, DAC, $pin:ident, OUT1) => {
|
($inst:ident, $pin:ident, $ch:expr) => {
|
||||||
impl DacPin<peripherals::$inst, 1> for peripherals::$pin {}
|
impl crate::dac::DacPin<peripherals::$inst, $ch> for crate::peripherals::$pin {}
|
||||||
|
|
||||||
impl sealed::DacPin<peripherals::$inst, 1> for peripherals::$pin {
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
($inst:ident, dac, DAC, $pin:ident, OUT2) => {
|
|
||||||
impl DacPin<peripherals::$inst, 2> for peripherals::$pin {}
|
|
||||||
|
|
||||||
impl sealed::DacPin<peripherals::$inst, 2> for peripherals::$pin {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
);
|
|
||||||
|
Loading…
Reference in New Issue
Block a user