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
//! I2C 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 SCL;
impl Wire for SCL {}
pub struct SDA;
impl Wire for SDA {}

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_12, GPIO_AD_B0_13, GPIO_AD_B1_00, GPIO_AD_B1_01, GPIO_AD_B1_06, GPIO_AD_B1_07,
        GPIO_SD_B0_00, GPIO_SD_B0_01,
    },
    Alt0, Alt1, Alt2, Alt3,
};

macro_rules! pin_config {
    ($w:expr) => {
        $w.ode()
            .ode_1_open_drain_enabled()
            .sre()
            .sre_1_fast_slew_rate()
            .dse()
            .dse_4_r0_4()
            .speed()
            .speed_2_medium_100mhz()
            .pke()
            .pke_1_pull_keeper_enabled()
            .pue()
            .pue_1_pull()
            .pus()
            .pus_3_22k_ohm_pull_up()
    };
}

impl Pin for GPIO_AD_B1_07<Alt1> {
    type Wire = SCL;
    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_B1_07<Alt1> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpi2c3_scl_select_input
            .write(|w| w.daisy().gpio_ad_b1_07_alt1());
        Daisy::new(self)
    }
}

impl Pin for GPIO_AD_B1_06<Alt1> {
    type Wire = SDA;
    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_B1_06<Alt1> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpi2c3_sda_select_input
            .write(|w| w.daisy().gpio_ad_b1_06_alt1());
        Daisy::new(self)
    }
}

impl Pin for GPIO_AD_B1_01<Alt3> {
    type Wire = SDA;
    type Module = module::_1;
    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

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

impl Pin for GPIO_AD_B1_00<Alt3> {
    type Wire = SCL;
    type Module = module::_1;
    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

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

impl Pin for GPIO_AD_B0_12<Alt0> {
    type Wire = SCL;
    type Module = module::_4;
    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_AD_B0_12<Alt0> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpi2c4_scl_select_input
            .write(|w| w.daisy().gpio_ad_b0_12_alt0());
        Daisy::new(self)
    }
}

impl Pin for GPIO_AD_B0_13<Alt0> {
    type Wire = SDA;
    type Module = module::_4;
    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

impl IntoDaisy for GPIO_AD_B0_13<Alt0> {
    #[inline(always)]
    fn into_daisy(self) -> Daisy<Self> {
        self.iomuxc()
            .lpi2c4_sda_select_input
            .write(|w| w.daisy().gpio_ad_b0_13_alt0());
        Daisy::new(self)
    }
}

impl Pin for GPIO_SD_B0_01<Alt2> {
    type Wire = SDA;
    type Module = module::_3;
    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

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

impl Pin for GPIO_SD_B0_00<Alt2> {
    type Wire = SCL;
    type Module = module::_3;
    #[inline(always)]
    fn configure(&mut self) {
        self.sion_enable();
        self.pad().write(|w| pin_config!(w));
    }
}

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