imxrt_iomuxc/
lpspi.rs

1//! SPI pad configurations
2
3/// A SPI signal
4pub trait Signal: private::Sealed {}
5
6/// A tag that indicates a SPI clock pad
7pub enum Sck {}
8/// A tag that indicates a SPI data out pad
9pub enum Sdo {}
10/// A tag that indicates a SPI data in pad
11pub enum Sdi {}
12/// A tag that indicates the Pcs0 chip select pad
13pub enum Pcs0 {}
14/// A tag that indicates the Pcs1 chip select pad
15pub enum Pcs1 {}
16/// A tag that indicates the Pcs2 chip select pad
17pub enum Pcs2 {}
18/// A tag that indicates the Pcs3 chip select pad
19pub enum Pcs3 {}
20
21impl Signal for Sck {}
22impl Signal for Sdo {}
23impl Signal for Sdi {}
24impl Signal for Pcs0 {}
25impl Signal for Pcs1 {}
26impl Signal for Pcs2 {}
27impl Signal for Pcs3 {}
28
29mod private {
30    pub trait Sealed {}
31    impl Sealed for super::Sck {}
32    impl Sealed for super::Sdo {}
33    impl Sealed for super::Sdi {}
34    impl Sealed for super::Pcs0 {}
35    impl Sealed for super::Pcs1 {}
36    impl Sealed for super::Pcs2 {}
37    impl Sealed for super::Pcs3 {}
38}
39
40/// A SPI pin
41pub trait Pin: super::Iomuxc {
42    /// Alternate value for this pin
43    const ALT: u32;
44    /// Daisy register
45    const DAISY: Option<super::Daisy>;
46    /// SPI signal
47    type Signal: Signal;
48    /// SPI module; `U3` for `SPI3`
49    type Module: super::consts::Unsigned;
50}
51
52/// Prepare a SPI pin
53///
54/// If you do not call `prepare()` on your SPI pin, it might work as
55/// a SPI pin.
56///
57/// # Safety
58///
59/// `prepare()` inherits all the unsafety that comes from the `IOMUX` supertrait.
60pub fn prepare<P: Pin>(pin: &mut P) {
61    super::alternate(pin, P::ALT);
62    super::set_sion(pin);
63    if let Some(daisy) = P::DAISY {
64        unsafe { daisy.write() };
65    }
66}
67
68#[allow(unused)] // Used in chip-specific modules...
69macro_rules! spi {
70    (module: $module:ty, alt: $alt:expr, pad: $pad:ty, signal: $signal:ty, daisy: $daisy:expr) => {
71        impl Pin for $pad {
72            const ALT: u32 = $alt;
73            const DAISY: Option<Daisy> = $daisy;
74            type Signal = $signal;
75            type Module = $module;
76        }
77    };
78}