imxrt_iomuxc/
flexpwm.rs

1//! PWM pad configuration
2
3/// A PWM output identified; one of `A` or `B`
4pub trait Output: private::Sealed {}
5/// PWM output A
6pub enum A {}
7/// PWM output B
8pub enum B {}
9
10impl Output for A {}
11impl Output for B {}
12
13mod private {
14    pub trait Sealed {}
15    impl Sealed for super::A {}
16    impl Sealed for super::B {}
17}
18
19/// A PWM pin
20pub trait Pin: super::Iomuxc {
21    /// The alternate mode for the PWM pin
22    const ALT: u32;
23    /// The output identifier
24    type Output: Output;
25    /// The daisy register which will select the pad
26    const DAISY: Option<super::Daisy>;
27    /// The PWM module; `U2` is `PWM2`
28    type Module: super::consts::Unsigned;
29    /// The PWM submodule; `U3` for `PWM2_SM3`
30    type Submodule: super::consts::Unsigned;
31}
32
33/// Prepare a PWM pin
34///
35/// # Safety
36///
37/// `prepare()` inherits all the unsafety of the `IOMUX` supertrait.
38pub fn prepare<P: Pin>(pin: &mut P) {
39    super::alternate(pin, P::ALT);
40    if let Some(daisy) = P::DAISY {
41        unsafe { daisy.write() };
42    }
43}
44
45#[allow(unused)] // Used in chip-specific modules...
46macro_rules! pwm {
47    (module: $module:ty, submodule: $submodule:ty, alt: $alt:expr, pad: $pad:ty, output: $output:ty, daisy: $daisy:expr) => {
48        impl Pin for $pad {
49            const ALT: u32 = $alt;
50            type Output = $output;
51            const DAISY: Option<Daisy> = $daisy;
52            type Module = $module;
53            type Submodule = $submodule;
54        }
55    };
56}