stm32: Remove OptionalPin
The idea behind OptionalPin has a few problems: - you need to impl the signal traits for NoPin which is a bit weird https://github.com/embassy-rs/embassy/blob/master/embassy-stm32/src/dcmi.rs#L413-L416 - you can pass any combination of set/unset pins, which needs checking at runtime https://github.com/embassy-rs/embassy/blob/master/embassy-stm32/src/dcmi.rs#L130 The replacement is to do multiple `new` constructors for each combination of pins you want to take.
This commit is contained in:
@ -248,31 +248,6 @@ crate::pac::interrupts! {
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
macro_rules! impl_pwm_nopin {
|
||||
($inst:ident) => {
|
||||
impl_no_pin!($inst, Channel1Pin);
|
||||
impl_no_pin!($inst, Channel1ComplementaryPin);
|
||||
impl_no_pin!($inst, Channel2Pin);
|
||||
impl_no_pin!($inst, Channel2ComplementaryPin);
|
||||
impl_no_pin!($inst, Channel3Pin);
|
||||
impl_no_pin!($inst, Channel3ComplementaryPin);
|
||||
impl_no_pin!($inst, Channel4Pin);
|
||||
impl_no_pin!($inst, Channel4ComplementaryPin);
|
||||
impl_no_pin!($inst, ExternalTriggerPin);
|
||||
impl_no_pin!($inst, BreakInputPin);
|
||||
impl_no_pin!($inst, BreakInputComparator1Pin);
|
||||
impl_no_pin!($inst, BreakInputComparator2Pin);
|
||||
impl_no_pin!($inst, BreakInput2Pin);
|
||||
impl_no_pin!($inst, BreakInput2Comparator1Pin);
|
||||
impl_no_pin!($inst, BreakInput2Comparator2Pin);
|
||||
};
|
||||
}
|
||||
|
||||
crate::pac::peripherals!(
|
||||
(timer, $inst:ident) => { impl_pwm_nopin!($inst); };
|
||||
);
|
||||
|
||||
crate::pac::peripheral_pins!(
|
||||
($inst:ident, timer, $block:ident, $pin:ident, CH1, $af:expr) => {
|
||||
impl_pin!($inst, Channel1Pin, $pin, $af);
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::gpio::OptionalPin;
|
||||
use crate::gpio::Pin;
|
||||
|
||||
#[cfg(feature = "unstable-pac")]
|
||||
pub mod low_level {
|
||||
@ -6,118 +6,106 @@ pub mod low_level {
|
||||
}
|
||||
|
||||
pub(crate) mod sealed {
|
||||
use crate::gpio::sealed::OptionalPin;
|
||||
use crate::gpio::sealed::Pin;
|
||||
|
||||
pub trait Channel1Pin<Timer>: OptionalPin {
|
||||
pub trait Channel1Pin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
pub trait Channel1ComplementaryPin<Timer>: OptionalPin {
|
||||
pub trait Channel1ComplementaryPin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
|
||||
pub trait Channel2Pin<Timer>: OptionalPin {
|
||||
pub trait Channel2Pin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
pub trait Channel2ComplementaryPin<Timer>: OptionalPin {
|
||||
pub trait Channel2ComplementaryPin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
|
||||
pub trait Channel3Pin<Timer>: OptionalPin {
|
||||
pub trait Channel3Pin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
pub trait Channel3ComplementaryPin<Timer>: OptionalPin {
|
||||
pub trait Channel3ComplementaryPin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
|
||||
pub trait Channel4Pin<Timer>: OptionalPin {
|
||||
pub trait Channel4Pin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
pub trait Channel4ComplementaryPin<Timer>: OptionalPin {
|
||||
pub trait Channel4ComplementaryPin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
|
||||
pub trait ExternalTriggerPin<Timer>: OptionalPin {
|
||||
pub trait ExternalTriggerPin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
|
||||
pub trait BreakInputPin<Timer>: OptionalPin {
|
||||
pub trait BreakInputPin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
pub trait BreakInputComparator1Pin<Timer>: OptionalPin {
|
||||
pub trait BreakInputComparator1Pin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
pub trait BreakInputComparator2Pin<Timer>: OptionalPin {
|
||||
pub trait BreakInputComparator2Pin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
|
||||
pub trait BreakInput2Pin<Timer>: OptionalPin {
|
||||
pub trait BreakInput2Pin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
pub trait BreakInput2Comparator1Pin<Timer>: OptionalPin {
|
||||
pub trait BreakInput2Comparator1Pin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
pub trait BreakInput2Comparator2Pin<Timer>: OptionalPin {
|
||||
pub trait BreakInput2Comparator2Pin<Timer>: Pin {
|
||||
unsafe fn configure(&mut self);
|
||||
}
|
||||
}
|
||||
pub trait Channel1Pin<Timer>: sealed::Channel1Pin<Timer> + OptionalPin + 'static {}
|
||||
pub trait Channel1Pin<Timer>: sealed::Channel1Pin<Timer> + Pin + 'static {}
|
||||
pub trait Channel1ComplementaryPin<Timer>:
|
||||
sealed::Channel1ComplementaryPin<Timer> + OptionalPin + 'static
|
||||
sealed::Channel1ComplementaryPin<Timer> + Pin + 'static
|
||||
{
|
||||
}
|
||||
|
||||
pub trait Channel2Pin<Timer>: sealed::Channel2Pin<Timer> + 'static {}
|
||||
pub trait Channel2ComplementaryPin<Timer>:
|
||||
sealed::Channel2ComplementaryPin<Timer> + OptionalPin + 'static
|
||||
sealed::Channel2ComplementaryPin<Timer> + Pin + 'static
|
||||
{
|
||||
}
|
||||
|
||||
pub trait Channel3Pin<Timer>: sealed::Channel3Pin<Timer> + 'static {}
|
||||
pub trait Channel3ComplementaryPin<Timer>:
|
||||
sealed::Channel3ComplementaryPin<Timer> + OptionalPin + 'static
|
||||
sealed::Channel3ComplementaryPin<Timer> + Pin + 'static
|
||||
{
|
||||
}
|
||||
|
||||
pub trait Channel4Pin<Timer>: sealed::Channel4Pin<Timer> + 'static {}
|
||||
pub trait Channel4ComplementaryPin<Timer>:
|
||||
sealed::Channel4ComplementaryPin<Timer> + OptionalPin + 'static
|
||||
sealed::Channel4ComplementaryPin<Timer> + Pin + 'static
|
||||
{
|
||||
}
|
||||
|
||||
pub trait ExternalTriggerPin<Timer>:
|
||||
sealed::ExternalTriggerPin<Timer> + OptionalPin + 'static
|
||||
{
|
||||
}
|
||||
pub trait ExternalTriggerPin<Timer>: sealed::ExternalTriggerPin<Timer> + Pin + 'static {}
|
||||
|
||||
pub trait BreakInputPin<Timer>: sealed::BreakInputPin<Timer> + OptionalPin + 'static {}
|
||||
pub trait BreakInputPin<Timer>: sealed::BreakInputPin<Timer> + Pin + 'static {}
|
||||
pub trait BreakInputComparator1Pin<Timer>:
|
||||
sealed::BreakInputComparator1Pin<Timer> + OptionalPin + 'static
|
||||
sealed::BreakInputComparator1Pin<Timer> + Pin + 'static
|
||||
{
|
||||
}
|
||||
pub trait BreakInputComparator2Pin<Timer>:
|
||||
sealed::BreakInputComparator2Pin<Timer> + OptionalPin + 'static
|
||||
sealed::BreakInputComparator2Pin<Timer> + Pin + 'static
|
||||
{
|
||||
}
|
||||
|
||||
pub trait BreakInput2Pin<Timer>: sealed::BreakInput2Pin<Timer> + OptionalPin + 'static {}
|
||||
pub trait BreakInput2Pin<Timer>: sealed::BreakInput2Pin<Timer> + Pin + 'static {}
|
||||
pub trait BreakInput2Comparator1Pin<Timer>:
|
||||
sealed::BreakInput2Comparator1Pin<Timer> + OptionalPin + 'static
|
||||
sealed::BreakInput2Comparator1Pin<Timer> + Pin + 'static
|
||||
{
|
||||
}
|
||||
pub trait BreakInput2Comparator2Pin<Timer>:
|
||||
sealed::BreakInput2Comparator2Pin<Timer> + OptionalPin + 'static
|
||||
sealed::BreakInput2Comparator2Pin<Timer> + Pin + 'static
|
||||
{
|
||||
}
|
||||
|
||||
macro_rules! impl_no_pin {
|
||||
($timer:ident, $signal:ident) => {
|
||||
impl crate::pwm::pins::sealed::$signal<crate::peripherals::$timer> for crate::gpio::NoPin {
|
||||
unsafe fn configure(&mut self) {}
|
||||
}
|
||||
impl crate::pwm::pins::$signal<crate::peripherals::$timer> for crate::gpio::NoPin {}
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
macro_rules! impl_pin {
|
||||
($timer:ident, $signal:ident, $pin:ident, $af:expr) => {
|
||||
|
@ -12,7 +12,46 @@ pub struct SimplePwm<'d, T> {
|
||||
}
|
||||
|
||||
impl<'d, T: CaptureCompareCapable16bitInstance> SimplePwm<'d, T> {
|
||||
pub fn new<F: Into<Hertz>>(
|
||||
pub fn new_1ch<F: Into<Hertz>>(
|
||||
tim: impl Unborrow<Target = T> + 'd,
|
||||
ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
|
||||
freq: F,
|
||||
) -> Self {
|
||||
unborrow!(ch1);
|
||||
Self::new_inner(tim, freq, move || unsafe {
|
||||
ch1.configure();
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_2ch<F: Into<Hertz>>(
|
||||
tim: impl Unborrow<Target = T> + 'd,
|
||||
ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
|
||||
ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd,
|
||||
freq: F,
|
||||
) -> Self {
|
||||
unborrow!(ch1, ch2);
|
||||
Self::new_inner(tim, freq, move || unsafe {
|
||||
ch1.configure();
|
||||
ch2.configure();
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_3ch<F: Into<Hertz>>(
|
||||
tim: impl Unborrow<Target = T> + 'd,
|
||||
ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
|
||||
ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd,
|
||||
ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd,
|
||||
freq: F,
|
||||
) -> Self {
|
||||
unborrow!(ch1, ch2, ch3);
|
||||
Self::new_inner(tim, freq, move || unsafe {
|
||||
ch1.configure();
|
||||
ch2.configure();
|
||||
ch3.configure();
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_4ch<F: Into<Hertz>>(
|
||||
tim: impl Unborrow<Target = T> + 'd,
|
||||
ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
|
||||
ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd,
|
||||
@ -20,17 +59,26 @@ impl<'d, T: CaptureCompareCapable16bitInstance> SimplePwm<'d, T> {
|
||||
ch4: impl Unborrow<Target = impl Channel4Pin<T>> + 'd,
|
||||
freq: F,
|
||||
) -> Self {
|
||||
unborrow!(tim, ch1, ch2, ch3, ch4);
|
||||
|
||||
T::enable();
|
||||
<T as crate::rcc::sealed::RccPeripheral>::reset();
|
||||
|
||||
unsafe {
|
||||
unborrow!(ch1, ch2, ch3, ch4);
|
||||
Self::new_inner(tim, freq, move || unsafe {
|
||||
ch1.configure();
|
||||
ch2.configure();
|
||||
ch3.configure();
|
||||
ch4.configure();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn new_inner<F: Into<Hertz>>(
|
||||
tim: impl Unborrow<Target = T> + 'd,
|
||||
freq: F,
|
||||
configure_pins: impl FnOnce(),
|
||||
) -> Self {
|
||||
unborrow!(tim);
|
||||
|
||||
T::enable();
|
||||
<T as crate::rcc::sealed::RccPeripheral>::reset();
|
||||
|
||||
configure_pins();
|
||||
|
||||
let mut this = Self {
|
||||
inner: tim,
|
||||
|
Reference in New Issue
Block a user