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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
//! SPI pin multiplexing

pub mod module {
    pub trait Module {
        const IDX: usize;
    }
    pub struct _1;
    impl Module for _1 {
        const IDX: usize = 1;
    }
    pub struct _2;
    impl Module for _2 {
        const IDX: usize = 2;
    }
    pub struct _3;
    impl Module for _3 {
        const IDX: usize = 3;
    }
    pub struct _4;
    impl Module for _4 {
        const IDX: usize = 4;
    }
}

pub trait Wire {}
pub struct SCK;
impl Wire for SCK {}
pub struct SDO;
impl Wire for SDO {}
pub struct SDI;
impl Wire for SDI {}
pub struct PCS0;
impl Wire for PCS0 {}

pub trait Pin {
    type Wire: Wire;
    type Module: module::Module;

    /// Perform IOMUXC configurations for this pin
    fn configure(&mut self);
}

use crate::iomuxc::{
    daisy::{Daisy, IntoDaisy},
    gpio::{
        GPIO_AD_B0_00, GPIO_AD_B0_01, GPIO_AD_B0_02, GPIO_AD_B0_03, GPIO_B0_00, GPIO_B0_01,
        GPIO_B0_02, GPIO_B0_03, GPIO_EMC_30, GPIO_SD_B0_00, GPIO_SD_B0_01, GPIO_SD_B0_02,
        GPIO_SD_B0_03, GPIO_SD_B1_06, GPIO_SD_B1_07, GPIO_SD_B1_08, GPIO_SD_B1_09,
    },
    Alt3, Alt4, Alt7,
};

macro_rules! pin_config {
    ($w:expr) => {
        $w.dse().dse_7_r0_7().speed().speed_2_medium_100mhz()
    };
}

//
// Note: The pad mapping below is *not* complete
//

// SPI 1

impl Pin for GPIO_SD_B0_00<Alt4> {
    type Wire = SCK;
    type Module = module::_1;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_SD_B0_00<Alt4> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi1_sck_select_input
            .write(|w| w.daisy().gpio_sd_b0_00_alt4());
        Daisy::new(self)
    }
}

impl Pin for GPIO_SD_B0_02<Alt4> {
    type Wire = SDO;
    type Module = module::_1;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_SD_B0_02<Alt4> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi1_sdo_select_input
            .write(|w| w.daisy().gpio_sd_b0_02_alt4());
        Daisy::new(self)
    }
}

impl Pin for GPIO_SD_B0_03<Alt4> {
    type Wire = SDI;
    type Module = module::_1;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_SD_B0_03<Alt4> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi1_sdi_select_input
            .write(|w| w.daisy().gpio_sd_b0_03_alt4());
        Daisy::new(self)
    }
}

impl Pin for GPIO_SD_B0_01<Alt4> {
    type Wire = PCS0;
    type Module = module::_1;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_SD_B0_01<Alt4> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi1_pcs0_select_input
            .write(|w| w.daisy().gpio_sd_b0_01_alt4());
        Daisy::new(self)
    }
}

impl Pin for GPIO_EMC_30<Alt3> {
    type Wire = PCS0;
    type Module = module::_1;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_EMC_30<Alt3> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi1_pcs0_select_input
            .write(|w| w.daisy().gpio_emc_30_alt3());
        Daisy::new(self)
    }
}

// SPI 2

impl Pin for GPIO_SD_B1_07<Alt4> {
    type Wire = SCK;
    type Module = module::_2;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_SD_B1_07<Alt4> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi2_sck_select_input
            .write(|w| w.daisy().gpio_sd_b1_07_alt4());
        Daisy::new(self)
    }
}

impl Pin for GPIO_SD_B1_08<Alt4> {
    type Wire = SDO;
    type Module = module::_2;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_SD_B1_08<Alt4> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi2_sdo_select_input
            .write(|w| w.daisy().gpio_sd_b1_08_alt4());
        Daisy::new(self)
    }
}

impl Pin for GPIO_SD_B1_09<Alt4> {
    type Wire = SDI;
    type Module = module::_2;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_SD_B1_09<Alt4> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi2_sdi_select_input
            .write(|w| w.daisy().gpio_sd_b1_09_alt4());
        Daisy::new(self)
    }
}

impl Pin for GPIO_SD_B1_06<Alt4> {
    type Wire = PCS0;
    type Module = module::_2;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_SD_B1_06<Alt4> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi2_pcs0_select_input
            .write(|w| w.daisy().gpio_sd_b1_06_alt4());
        Daisy::new(self)
    }
}

// SPI 3

impl Pin for GPIO_AD_B0_00<Alt7> {
    type Wire = SCK;
    type Module = module::_3;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_AD_B0_00<Alt7> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi3_sck_select_input
            .write(|w| w.daisy().gpio_ad_b0_00_alt7());
        Daisy::new(self)
    }
}

impl Pin for GPIO_AD_B0_01<Alt7> {
    type Wire = SDO;
    type Module = module::_3;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_AD_B0_01<Alt7> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi3_sdo_select_input
            .write(|w| w.daisy().gpio_ad_b0_01_alt7());
        Daisy::new(self)
    }
}

impl Pin for GPIO_AD_B0_02<Alt7> {
    type Wire = SDI;
    type Module = module::_3;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_AD_B0_02<Alt7> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi3_sdi_select_input
            .write(|w| w.daisy().gpio_ad_b0_02_alt7());
        Daisy::new(self)
    }
}

impl Pin for GPIO_AD_B0_03<Alt7> {
    type Wire = PCS0;
    type Module = module::_3;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_AD_B0_03<Alt7> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi3_pcs0_select_input
            .write(|w| w.daisy().gpio_ad_b0_03_alt7());
        Daisy::new(self)
    }
}

// SPI 4

impl Pin for GPIO_B0_03<Alt3> {
    type Wire = SCK;
    type Module = module::_4;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_B0_03<Alt3> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi4_sck_select_input
            .write(|w| w.daisy().gpio_b0_03_alt3());
        Daisy::new(self)
    }
}

impl Pin for GPIO_B0_02<Alt3> {
    type Wire = SDO;
    type Module = module::_4;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_B0_02<Alt3> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi4_sdo_select_input
            .write(|w| w.daisy().gpio_b0_02_alt3());
        Daisy::new(self)
    }
}

impl Pin for GPIO_B0_01<Alt3> {
    type Wire = SDI;
    type Module = module::_4;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_B0_01<Alt3> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi4_sdi_select_input
            .write(|w| w.daisy().gpio_b0_01_alt3());
        Daisy::new(self)
    }
}

impl Pin for GPIO_B0_00<Alt3> {
    type Wire = PCS0;
    type Module = module::_4;

    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_B0_00<Alt3> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpspi4_pcs0_select_input
            .write(|w| w.daisy().gpio_b0_00_alt3());
        Daisy::new(self)
    }
}