omnitiles/hw/
pins_devboard.rs

1// SPDX-License-Identifier: MIT
2// © 2025–2026 Christopher Liu
3
4//! Pin definitions for STM32F777 MCU Devboard for OmniTiles.
5
6use stm32f7xx_hal::{
7    gpio::{gpioa, gpiod, gpioe, Alternate, Output, PushPull},
8    pac,
9    prelude::*,
10};
11
12/// All board pins. Construct this once at startup using:
13///
14/// ```rust
15/// let pins = BoardPins::new(dp.GPIOA, dp.GPIOD, dp.GPIOE);
16/// ```
17pub struct BoardPins {
18    pub leds: LedPins,
19    pub usart1: Usart1Pins,
20    pub spi4: Spi4Pins,
21    pub can1: Can1Pins,
22}
23
24pub struct LedPins {
25    pub red: gpiod::PD8<Output<PushPull>>,
26    pub yellow: gpiod::PD9<Output<PushPull>>,
27    pub green: gpiod::PD10<Output<PushPull>>,
28}
29
30// USART1 TX/RX
31pub struct Usart1Pins {
32    pub tx: gpioa::PA9<Alternate<7>>,
33    pub rx: gpioa::PA10<Alternate<7>>,
34}
35
36/// SPI4 SCK/MISO/MOSI and CS
37pub struct Spi4Pins {
38    pub sck: gpioe::PE12<Alternate<5>>,
39    pub miso: gpioe::PE13<Alternate<5>>,
40    pub mosi: gpioe::PE14<Alternate<5>>,
41    pub cs1: gpioe::PE4<Output<PushPull>>,
42    pub cs2: gpioe::PE11<Output<PushPull>>,
43}
44
45/// CAN1 TX/RX
46pub struct Can1Pins {
47    pub tx: gpioa::PA12<Alternate<9>>,
48    pub rx: gpioa::PA11<Alternate<9>>,
49}
50
51impl BoardPins {
52    /// Create all named pins from raw GPIO peripherals.
53    pub fn new(gpioa: pac::GPIOA, gpiod: pac::GPIOD, gpioe: pac::GPIOE) -> Self {
54        let gpioa = gpioa.split();
55        let gpiod = gpiod.split();
56        let gpioe = gpioe.split();
57
58        Self {
59            leds: LedPins {
60                red: gpiod.pd8.into_push_pull_output(),
61                yellow: gpiod.pd9.into_push_pull_output(),
62                green: gpiod.pd10.into_push_pull_output(),
63            },
64
65            usart1: Usart1Pins {
66                tx: gpioa.pa9.into_alternate::<7>(),
67                rx: gpioa.pa10.into_alternate::<7>(),
68            },
69
70            spi4: Spi4Pins {
71                sck: gpioe.pe12.into_alternate::<5>(),
72                miso: gpioe.pe13.into_alternate::<5>(),
73                mosi: gpioe.pe14.into_alternate::<5>(),
74                cs1: gpioe.pe4.into_push_pull_output(),
75                cs2: gpioe.pe11.into_push_pull_output(),
76            },
77
78            can1: Can1Pins {
79                tx: gpioa.pa12.into_alternate::<9>(),
80                rx: gpioa.pa11.into_alternate::<9>().internal_pull_up(true),
81            },
82        }
83    }
84}