ws2812_flexio/
pins.rs

1use imxrt_iomuxc::{self as iomuxc, flexio::Pin};
2
3use paste::paste;
4
5/// The pins to use for WS2812.
6pub trait Pins<const N: u8, const L: usize> {
7    /// The amount of pins this object contains.
8    const PIN_COUNT: u8;
9
10    /// Configures the pins.
11    ///
12    /// This is not intended to be called by the user;
13    /// it will be used inside of the driver.
14    fn configure(&mut self);
15
16    /// The FlexIO pin offsets
17    const FLEXIO_PIN_OFFSETS: &'static [u8];
18}
19
20macro_rules! count {
21    () => (0u8);
22    ( $x:tt $($xs:tt)* ) => (1u8 + count!($($xs)*));
23}
24
25macro_rules! impl_pins {
26    ($($n:literal)+) => {
27        paste! {
28            impl<const N: u8, $([<P $n>]: Pin<N>),+> Pins<N, {count!($($n)+) as usize}> for ($([<P $n>]),+,) {
29                fn configure(&mut self) {
30                    $(
31                        iomuxc::flexio::prepare(&mut self.$n);
32                    )+
33                }
34
35                const PIN_COUNT: u8 = count!($($n)+);
36
37                const FLEXIO_PIN_OFFSETS: &'static[u8] = &[$(
38                    [<P $n>]::OFFSET
39                ),+];
40            }
41        }
42    };
43}
44
45impl_pins!(0);
46impl_pins!(0 1);
47impl_pins!(0 1 2);
48impl_pins!(0 1 2 3);