imxrt_iomuxc/
usdhc.rs

1//! USDHC pad configuration
2
3/// Type tag for the command pin
4pub enum Cmd {}
5/// Type tag for the clock pin
6pub enum Clk {}
7/// Type tag for the write protect pin
8pub enum Wp {}
9/// Type tag for the card detection pin
10pub enum CdB {}
11/// Type tag for the data0 pin
12pub enum Data0 {}
13/// Type tag for the data1 pin
14pub enum Data1 {}
15/// Type tag for the data2 pin
16pub enum Data2 {}
17/// Type tag for the data3 pin
18pub enum Data3 {}
19
20/// A uSDHC pin signal
21mod private {
22    pub trait Signal {}
23    impl Signal for super::Cmd {}
24    impl Signal for super::Clk {}
25    impl Signal for super::Wp {}
26    impl Signal for super::CdB {}
27    impl Signal for super::Data0 {}
28    impl Signal for super::Data1 {}
29    impl Signal for super::Data2 {}
30    impl Signal for super::Data3 {}
31}
32use private::Signal;
33
34use crate::Config;
35
36/// A uSDHC pin
37pub trait Pin: super::Iomuxc {
38    /// The alternate value for the uSDHC pin
39    const ALT: u32;
40    /// The daisy register which will select the pad
41    const DAISY: Option<super::Daisy>;
42    /// Pin configuration
43    ///
44    /// Applied during pin preparation, overwriting any
45    /// other user-provided configuration.
46    const CONFIG: Config;
47    /// Pin direction
48    type Signal: Signal;
49    /// uSDHC module; `U1` for `uSDHC1`
50    type Module: super::consts::Unsigned;
51}
52
53/// Prepare a uSDHC pin
54///
55/// If you do not call `prepare()` on your uSDHC pin, it might not work as a uSDHC
56/// pin.
57///
58/// # Safety
59///
60/// `prepare()` inherits all the unsafety that comes from the `IOMUX` supertrait.
61/// In particular, we cannot be sure that the implementation's pointers are correct.
62/// It may also write a daisy configuration that's incorrect.
63pub fn prepare<P: Pin>(pin: &mut P) {
64    super::alternate(pin, P::ALT);
65    super::set_sion(pin);
66    super::configure(pin, P::CONFIG);
67    if let Some(daisy) = P::DAISY {
68        unsafe { daisy.write() }
69    }
70}
71
72#[allow(unused)] // Used in chip-specific modules...
73macro_rules! usdhc {
74    (module: $module:ty, alt: $alt:expr, pad: $pad:ty, signal: $signal:ty, keeper: $keeper:expr, daisy: $daisy:expr) => {
75        impl Pin for $pad {
76            const ALT: u32 = $alt;
77            const DAISY: Option<Daisy> = $daisy;
78            const CONFIG: crate::Config = crate::Config::zero()
79                .set_speed(crate::Speed::Fast)
80                .set_drive_strength(crate::DriveStrength::R0_7)
81                .set_pull_keeper($keeper);
82            type Signal = $signal;
83            type Module = $module;
84        }
85    };
86}