1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
macro_rules! alt0 {
    ($Pad:ident, $mux_mod:ident) => {
        /// Converts the pad into its Alt0 setting
        pub fn alt0(self) -> $Pad<$crate::iomuxc::Alt0> {
            self.iomuxc().$mux_mod.modify(|_, w| {
                w.mux_mode()
                    .variant($crate::pac::iomuxc::$mux_mod::MUX_MODE_A::ALT0)
            });
            $Pad {
                _alt: core::marker::PhantomData,
                iomuxc: self.iomuxc,
            }
        }
    };
}

macro_rules! alt1 {
    ($Pad:ident, $mux_mod:ident) => {
        /// Converts the pad into its Alt1 setting
        pub fn alt1(self) -> $Pad<$crate::iomuxc::Alt1> {
            self.iomuxc().$mux_mod.modify(|_, w| {
                w.mux_mode()
                    .variant($crate::pac::iomuxc::$mux_mod::MUX_MODE_A::ALT1)
            });
            $Pad {
                _alt: core::marker::PhantomData,
                iomuxc: self.iomuxc,
            }
        }
    };
}

macro_rules! alt2 {
    ($Pad:ident, $mux_mod:ident) => {
        /// Converts the pad into its Alt2 setting
        pub fn alt2(self) -> $Pad<$crate::iomuxc::Alt2> {
            self.iomuxc().$mux_mod.modify(|_, w| {
                w.mux_mode()
                    .variant($crate::pac::iomuxc::$mux_mod::MUX_MODE_A::ALT2)
            });
            $Pad {
                _alt: core::marker::PhantomData,
                iomuxc: self.iomuxc,
            }
        }
    };
}

macro_rules! alt3 {
    ($Pad:ident, $mux_mod:ident) => {
        /// Converts the pad into its Alt3 setting
        pub fn alt3(self) -> $Pad<$crate::iomuxc::Alt3> {
            self.iomuxc().$mux_mod.modify(|_, w| {
                w.mux_mode()
                    .variant($crate::pac::iomuxc::$mux_mod::MUX_MODE_A::ALT3)
            });
            $Pad {
                _alt: core::marker::PhantomData,
                iomuxc: self.iomuxc,
            }
        }
    };
}

macro_rules! alt4 {
    ($Pad:ident, $mux_mod:ident) => {
        /// Converts the pad into its Alt4 setting
        pub fn alt4(self) -> $Pad<$crate::iomuxc::Alt4> {
            self.iomuxc().$mux_mod.modify(|_, w| {
                w.mux_mode()
                    .variant($crate::pac::iomuxc::$mux_mod::MUX_MODE_A::ALT4)
            });
            $Pad {
                _alt: core::marker::PhantomData,
                iomuxc: self.iomuxc,
            }
        }
    };
}

macro_rules! alt5 {
    ($Pad:ident, $mux_mod:ident) => {
        /// Converts the pad into its Alt5 setting
        pub fn alt5(self) -> $Pad<$crate::iomuxc::Alt5> {
            self.iomuxc().$mux_mod.modify(|_, w| {
                w.mux_mode()
                    .variant($crate::pac::iomuxc::$mux_mod::MUX_MODE_A::ALT5)
            });
            $Pad {
                _alt: core::marker::PhantomData,
                iomuxc: self.iomuxc,
            }
        }
    };
}

macro_rules! alt6 {
    ($Pad:ident, $mux_mod:ident) => {
        /// Converts the pad into its Alt6 setting
        pub fn alt6(self) -> $Pad<$crate::iomuxc::Alt6> {
            self.iomuxc().$mux_mod.modify(|_, w| {
                w.mux_mode()
                    .variant($crate::pac::iomuxc::$mux_mod::MUX_MODE_A::ALT6)
            });
            $Pad {
                _alt: core::marker::PhantomData,
                iomuxc: self.iomuxc,
            }
        }
    };
}

macro_rules! alt7 {
    ($Pad:ident, $mux_mod:ident) => {
        /// Converts the pad into its Alt7 setting
        pub fn alt7(self) -> $Pad<$crate::iomuxc::Alt7> {
            self.iomuxc().$mux_mod.modify(|_, w| {
                w.mux_mode()
                    .variant($crate::pac::iomuxc::$mux_mod::MUX_MODE_A::ALT7)
            });
            $Pad {
                _alt: core::marker::PhantomData,
                iomuxc: self.iomuxc,
            }
        }
    };
}

macro_rules! alt8 {
    ($Pad:ident, $mux_mod:ident) => {
        /// Converts the pad into its Alt8 setting
        pub fn alt8(self) -> $Pad<$crate::iomuxc::Alt8> {
            self.iomuxc().$mux_mod.modify(|_, w| {
                w.mux_mode()
                    .variant($crate::pac::iomuxc::$mux_mod::MUX_MODE_A::ALT8)
            });
            $Pad {
                _alt: core::marker::PhantomData,
                iomuxc: self.iomuxc,
            }
        }
    };
}

macro_rules! alt9 {
    ($Pad:ident, $mux_mod:ident) => {
        /// Converts the pad into its Alt9 setting
        pub fn alt9(self) -> $Pad<$crate::iomuxc::Alt9> {
            self.iomuxc().$mux_mod.modify(|_, w| {
                w.mux_mode()
                    .variant($crate::pac::iomuxc::$mux_mod::MUX_MODE_A::ALT9)
            });
            $Pad {
                _alt: core::marker::PhantomData,
                iomuxc: self.iomuxc,
            }
        }
    };
}

macro_rules! pad {
    ($Pad:ident, $mux_mod:ident, $pad_mod:ident, $pad_ty:ident, [$($alt_macro:ident),+]) => {
        pub struct $Pad<Alt> {
            _alt: core::marker::PhantomData<Alt>,
            iomuxc: *const $crate::pac::iomuxc::RegisterBlock,
        }
        impl<Alt> $Pad<Alt> {
            $(
                $alt_macro!($Pad, $mux_mod);
            )+

            #[allow(dead_code)] // TODO Remove once all pads are exposed in IOMUXC, and these are properly used
            pub(crate) fn new(iomuxc: &$crate::pac::iomuxc::RegisterBlock) -> Self {
                Self {
                    _alt: core::marker::PhantomData,
                    iomuxc,
                }
            }

            pub(crate) fn iomuxc(&self) -> &$crate::pac::iomuxc::RegisterBlock {
                // Safety: register block is always valid
                unsafe { &*self.iomuxc }
            }

            #[allow(dead_code)] // Method may not be used on a pin
            pub(crate) fn pad(&self) -> &$crate::pac::iomuxc::$pad_ty {
                &self.iomuxc().$pad_mod
            }

            /// Enables software input on (SION) for the pin, which forces
            /// the input path for the pin.
            #[allow(dead_code)] // Method may not be used on a pin
            pub(crate) fn sion_enable(&self) {
                self.iomuxc().$mux_mod.modify(|_, w| w.sion().set_bit());
            }

            /// Disables software input on (SION) for the pin. This means that
            /// the pin's input path is determined by its functionality.
            #[allow(dead_code)] // Method may not be used on a pin
            pub(crate) fn sion_disable(&self) {
                self.iomuxc().$mux_mod.modify(|_, w| w.sion().clear_bit());
            }
        }
    };
}