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
//! PyPortal pins

use super::{hal, target_device};

use crate::hal::gpio::{self, *};
use hal::define_pins;

define_pins!(
    /// Maps the pins to their arduino names and
    /// the numbers printed on the board.
    struct Pins,
    target_device: target_device,

    /// Analog pin 0.  Can act as a true analog output
    /// as it has a DAC (which is not currently supported
    /// by this hal) as well as input.
    pin speaker = a2,
    /// enable speaker amplifier
    pin speaker_enable = a27,

    /// Light sensor
    pin light = a7,

    // STEMMA connectors
    /// Pin D3
    pin d3 = a4,
    /// Pin D4
    pin d4 = a5,

    /// D13 LED
    pin d13 = b23,
    /// Neopixel status LED
    pin neopixel = b22,

    // TFT(Thin-film-transistor liquid-crystal display) control ports
    /// TFT Reset
    pin tft_reset = a0,
    /// TFT RD
    pin tft_rd = b4,
    /// TFT RS
    pin tft_rs = b5,
    /// TFT CS
    pin tft_cs = b6,
    /// TFT TE
    pin tft_te = b7,
    /// TFT WR
    pin tft_wr = b9,
    /// TFT Backlight
    pin tft_backlight = b31,

    /// LCD Data 0
    pin lcd_data0 = a16,
    /// LCD Data 1
    pin lcd_data1 = a17,
    /// LCD Data 2
    pin lcd_data2 = a18,
    /// LCD Data 3
    pin lcd_data3 = a19,
    /// LCD Data 4
    pin lcd_data4 = a20,
    /// LCD Data 5
    pin lcd_data5 = a21,
    /// LCD Data 6
    pin lcd_data6 = a22,
    /// LCD Data 7
    pin lcd_data7 = a23,

    /// Touchscreen pins
    /// Touch YD
    pin touch_yd = b0,
    /// Touch XL
    pin touch_xl = b1,
    /// Touch YU
    pin touch_yu = a6,
    /// Touch XR
    pin touch_xr = b8,

    // ESP control - ESP32 WiFi
    /// Pin ESP CS
    pin esp_cs = b14,
    /// Pin ESP GPIO0
    pin esp_gpio0 = b15,
    /// Pin ESP Busy
    pin esp_busy = b16,
    /// Pin ESP Reset
    pin esp_reset = b17,
    /// Pin ESP RTS
    pin esp_rts = a15,

    // UART - Universal Asynchronous Receiver/Transmitter (connected to ESP32)
    /// Pin TX
    pin esp_tx = b12,
    /// Pin RX
    pin esp_rx = b13,

    // SPI - Serial Peripheral Interface
    /// Pin MOSI
    pin mosi = a12,
    /// Pin SCK
    pin sck = a13,
    /// Pin MISO
    pin miso = a14,

    // I2C - ADT7410 Analog Devices temperature sensor
    /// Pin SDA
    pin sda = b2,
    /// Pin SCL
    pin scl = b3,

    /// Pin SD CS
    pin sd_cs = b30,
    /// Pin SD card detect
    pin sd_card_detect = a1,
);

impl Pins {
    /// Split the device pins into subsets
    pub fn split(self) -> Sets {
        let speaker = Speaker {
            speaker: self.speaker,
            enable: self.speaker_enable,
        };

        let stemma = Stemma {
            d3: self.d3,
            d4: self.d4,
        };

        let display = Display {
            tft_reset: self.tft_reset,
            tft_rd: self.tft_rd,
            tft_rs: self.tft_rs,
            tft_cs: self.tft_cs,
            tft_te: self.tft_te,

            tft_wr: self.tft_wr,
            tft_backlight: self.tft_backlight,
            lcd_data0: self.lcd_data0,
            lcd_data1: self.lcd_data1,
            lcd_data2: self.lcd_data2,

            lcd_data3: self.lcd_data3,
            lcd_data4: self.lcd_data4,
            lcd_data5: self.lcd_data5,
            lcd_data6: self.lcd_data6,
            lcd_data7: self.lcd_data7,
        };

        let touchscreen = Touchscreen {
            yd: self.touch_yd,
            xl: self.touch_xl,
            yu: self.touch_yu,
            xr: self.touch_xr,
        };

        let esp = Esp {
            cs: self.esp_cs,
            gpio0: self.esp_gpio0,
            busy: self.esp_busy,
            reset: self.esp_reset,
            rts: self.esp_rts,
        };

        let esp_uart = EspUart {
            tx: self.esp_tx,
            rx: self.esp_rx,
        };

        let spi = Spi {
            mosi: self.mosi,
            sck: self.sck,
            miso: self.miso,
        };

        let i2c = I2C {
            sda: self.sda,
            scl: self.scl,
        };

        let sd = SdCard {
            cs: self.sd_cs,
            card_detect: self.sd_card_detect,
        };

        Sets {
            port: self.port,
            display,
            esp,
            light: self.light,
            i2c,
            sd,
            speaker,
            spi,
            stemma,
            touchscreen,
            esp_uart,
            d13: self.d13,
            neopixel: self.neopixel,
        }
    }
}

pub struct Sets {
    pub port: Port,
    pub display: Display,
    pub d13: Pb23<Input<Floating>>,
    pub neopixel: Pb22<Input<Floating>>,
    pub esp: Esp,
    pub light: Pa7<Input<Floating>>,
    pub i2c: I2C,
    pub sd: SdCard,
    pub speaker: Speaker,
    pub spi: Spi,
    pub stemma: Stemma,
    pub touchscreen: Touchscreen,
    pub esp_uart: EspUart,
}

pub struct Display {
    pub tft_reset: Pa0<Input<Floating>>,
    pub tft_rd: Pb4<Input<Floating>>,
    pub tft_rs: Pb5<Input<Floating>>,
    pub tft_cs: Pb6<Input<Floating>>,
    pub tft_te: Pb7<Input<Floating>>,
    pub tft_wr: Pb9<Input<Floating>>,
    pub tft_backlight: Pb31<Input<Floating>>,
    pub lcd_data0: Pa16<Input<Floating>>,
    pub lcd_data1: Pa17<Input<Floating>>,
    pub lcd_data2: Pa18<Input<Floating>>,
    pub lcd_data3: Pa19<Input<Floating>>,
    pub lcd_data4: Pa20<Input<Floating>>,
    pub lcd_data5: Pa21<Input<Floating>>,
    pub lcd_data6: Pa22<Input<Floating>>,
    pub lcd_data7: Pa23<Input<Floating>>,
}

pub struct Esp {
    pub cs: Pb14<Input<Floating>>,
    pub gpio0: Pb15<Input<Floating>>,
    pub busy: Pb16<Input<Floating>>,
    pub reset: Pb17<Input<Floating>>,
    pub rts: Pa15<Input<Floating>>,
}

pub struct I2C {
    pub sda: Pb2<Input<Floating>>,
    pub scl: Pb3<Input<Floating>>,
}

pub struct SdCard {
    pub cs: Pb30<Input<Floating>>,
    pub card_detect: Pa1<Input<Floating>>,
}

pub struct Speaker {
    pub speaker: Pa2<Input<Floating>>,
    pub enable: Pa27<Input<Floating>>,
}

pub struct Spi {
    pub mosi: Pa12<Input<Floating>>,
    pub sck: Pa13<Input<Floating>>,
    pub miso: Pa14<Input<Floating>>,
}

pub struct Stemma {
    pub d3: Pa4<Input<Floating>>,
    pub d4: Pa5<Input<Floating>>,
}

pub struct Touchscreen {
    pub yd: Pb0<Input<Floating>>,
    pub xl: Pb1<Input<Floating>>,
    pub yu: Pa6<Input<Floating>>,
    pub xr: Pb8<Input<Floating>>,
}

pub struct EspUart {
    pub tx: Pb12<Input<Floating>>,
    pub rx: Pb13<Input<Floating>>,
}