1use stm32f7xx_hal::{
7 gpio::{
8 gpioa, gpiob, gpioc, gpiod, Alternate, Analog, Floating, Input, OpenDrain, Output, PushPull,
9 },
10 pac,
11 prelude::*,
12};
13#[cfg(feature = "mobile-base")]
14use stm32f7xx_hal::gpio::gpioe;
15
16pub struct BoardPins {
17 pub leds: Leds,
18 pub usart3: Usart3Pins,
19 pub spi1: Spi1Pins,
20 pub m1: Motor1Pins,
21 pub m2: Motor2Pins,
22 pub i2c1: I2c1Pins,
23 #[cfg(feature = "mobile-base")]
24 pub wheels: WheelPins,
25}
26
27pub struct Leds {
28 pub green: gpiob::PB0<Output<PushPull>>, pub blue: gpiob::PB7<Output<PushPull>>, pub red: gpiob::PB14<Output<PushPull>>, }
32
33pub struct Usart3Pins {
34 pub tx: gpiod::PD8<Alternate<7>>,
35 pub rx: gpiod::PD9<Alternate<7>>,
36}
37
38pub struct Spi1Pins {
39 pub sck: gpioa::PA5<Alternate<5>>,
40 pub miso: gpioa::PA6<Alternate<5>>,
41 pub mosi: gpioa::PA7<Alternate<5>>,
42 pub cs: gpioc::PC3<Output<PushPull>>,
43 pub drdy: gpioa::PA3<Input<Floating>>,
44}
45
46pub struct Motor1Pins {
47 pub in1: gpioc::PC6<Alternate<2>>, pub in2: gpioc::PC7<Alternate<2>>, pub cs: gpiod::PD0<Output<PushPull>>,
50 pub nsleep: gpiod::PD1<Output<PushPull>>,
51 pub disable: gpiod::PD2<Output<PushPull>>,
52 pub adc: gpiob::PB1<Analog>,
53}
54
55pub struct I2c1Pins {
56 pub scl: gpiob::PB8<Alternate<4, OpenDrain>>,
57 pub sda: gpiob::PB9<Alternate<4, OpenDrain>>,
58}
59
60pub struct Motor2Pins {
61 pub in1: gpioc::PC8<Alternate<2>>, pub in2: gpioc::PC9<Alternate<2>>, pub cs: gpiod::PD3<Output<PushPull>>,
64 pub nsleep: gpiod::PD4<Output<PushPull>>,
65 pub disable: gpiod::PD5<Output<PushPull>>,
66 pub adc: gpioc::PC2<Analog>,
67}
68
69#[cfg(feature = "mobile-base")]
70pub struct WheelPins {
71 pub fl_pwm: gpiod::PD12<Alternate<2>>, pub fl_in1: gpiod::PD6<Output<PushPull>>,
73 pub fl_in2: gpiod::PD7<Output<PushPull>>,
74 pub fr_pwm: gpiod::PD13<Alternate<2>>, pub fr_in1: gpiod::PD11<Output<PushPull>>,
76 pub fr_in2: gpioe::PE2<Output<PushPull>>,
77 pub bl_pwm: gpiod::PD14<Alternate<2>>, pub bl_in1: gpioa::PA1<Output<PushPull>>,
79 pub bl_in2: gpioa::PA2<Output<PushPull>>,
80 pub br_pwm: gpiod::PD15<Alternate<2>>, pub br_in1: gpioa::PA4<Output<PushPull>>,
82 pub br_in2: gpioa::PA8<Output<PushPull>>,
83}
84
85impl BoardPins {
86 pub fn new(
87 gpioa: pac::GPIOA,
88 gpiob: pac::GPIOB,
89 gpioc: pac::GPIOC,
90 gpiod: pac::GPIOD,
91 #[cfg(feature = "mobile-base")] gpioe: pac::GPIOE,
92 ) -> Self {
93 let gpioa = gpioa.split();
94 let gpiob = gpiob.split();
95 let gpioc = gpioc.split();
96 let gpiod = gpiod.split();
97 #[cfg(feature = "mobile-base")]
98 let gpioe = gpioe.split();
99
100 Self {
101 leds: Leds {
102 green: gpiob.pb0.into_push_pull_output(),
103 blue: gpiob.pb7.into_push_pull_output(),
104 red: gpiob.pb14.into_push_pull_output(),
105 },
106
107 usart3: Usart3Pins {
108 tx: gpiod.pd8.into_alternate::<7>(),
109 rx: gpiod.pd9.into_alternate::<7>(),
110 },
111
112 spi1: Spi1Pins {
113 sck: gpioa.pa5.into_alternate::<5>(),
114 miso: gpioa.pa6.into_alternate::<5>(),
115 mosi: gpioa.pa7.into_alternate::<5>(),
116 cs: gpioc.pc3.into_push_pull_output(),
117 drdy: gpioa.pa3.into_floating_input(),
118 },
119
120 m1: Motor1Pins {
121 in1: gpioc.pc6.into_alternate::<2>(),
122 in2: gpioc.pc7.into_alternate::<2>(),
123 cs: gpiod.pd0.into_push_pull_output(),
124 nsleep: gpiod.pd1.into_push_pull_output(),
125 disable: gpiod.pd2.into_push_pull_output(),
126 adc: gpiob.pb1.into_analog(),
127 },
128
129 m2: Motor2Pins {
130 in1: gpioc.pc8.into_alternate::<2>(),
131 in2: gpioc.pc9.into_alternate::<2>(),
132 cs: gpiod.pd3.into_push_pull_output(),
133 nsleep: gpiod.pd4.into_push_pull_output(),
134 disable: gpiod.pd5.into_push_pull_output(),
135 adc: gpioc.pc2.into_analog(),
136 },
137
138 i2c1: I2c1Pins {
139 scl: gpiob.pb8.into_alternate_open_drain::<4>(),
140 sda: gpiob.pb9.into_alternate_open_drain::<4>(),
141 },
142
143 #[cfg(feature = "mobile-base")]
144 wheels: WheelPins {
145 fl_pwm: gpiod.pd12.into_alternate::<2>(),
146 fl_in1: gpiod.pd6.into_push_pull_output(),
147 fl_in2: gpiod.pd7.into_push_pull_output(),
148 fr_pwm: gpiod.pd13.into_alternate::<2>(),
149 fr_in1: gpiod.pd11.into_push_pull_output(),
150 fr_in2: gpioe.pe2.into_push_pull_output(),
151 bl_pwm: gpiod.pd14.into_alternate::<2>(),
152 bl_in1: gpioa.pa1.into_push_pull_output(),
153 bl_in2: gpioa.pa2.into_push_pull_output(),
154 br_pwm: gpiod.pd15.into_alternate::<2>(),
155 br_in1: gpioa.pa4.into_push_pull_output(),
156 br_in2: gpioa.pa8.into_push_pull_output(),
157 },
158 }
159 }
160}