|
|
@@ -1,19 +1,254 @@
|
|
1
|
1
|
//! GPIO pin configuration.
|
|
2
|
2
|
#![warn(missing_docs)]
|
|
|
3
|
+#![allow(unused)] // TODO: Enable this warning again.
|
|
|
4
|
+
|
|
|
5
|
+use stm32f4xx_hal::gpio::gpioa::{PA0, PA1, PA10, PA11, PA12, PA15, PA2, PA3, PA4, PA5, PA6, PA7};
|
|
|
6
|
+use stm32f4xx_hal::gpio::gpiob::{PB10, PB13, PB14, PB15, PB3, PB4, PB5, PB6, PB7, PB9};
|
|
|
7
|
+use stm32f4xx_hal::gpio::gpioc::{PC0, PC1, PC15, PC2, PC3, PC6};
|
|
|
8
|
+use stm32f4xx_hal::gpio::gpiod::{PD0, PD1, PD10, PD11, PD12, PD13, PD14, PD15, PD7, PD8, PD9};
|
|
|
9
|
+use stm32f4xx_hal::gpio::gpioe::{PE3, PE4, PE5, PE6};
|
|
|
10
|
+use stm32f4xx_hal::gpio::gpiof::{
|
|
|
11
|
+ PF0, PF1, PF10, PF13, PF14, PF15, PF2, PF3, PF4, PF5, PF6, PF7, PF8, PF9,
|
|
|
12
|
+};
|
|
|
13
|
+use stm32f4xx_hal::gpio::gpiog::{PG10, PG11, PG13, PG14, PG15, PG2, PG3, PG4, PG5, PG6};
|
|
|
14
|
+use stm32f4xx_hal::gpio::{
|
|
|
15
|
+ Alternate, Floating, Input, OpenDrain, Output, PushPull, AF10, AF12, AF4, AF5, AF6, AF7,
|
|
|
16
|
+};
|
|
|
17
|
+use stm32f4xx_hal::prelude::*;
|
|
|
18
|
+use stm32f4xx_hal::stm32::{DMA1, GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, I2S2EXT, SPI2};
|
|
|
19
|
+
|
|
|
20
|
+use super::halext::i2s::I2SClocks;
|
|
|
21
|
+
|
|
|
22
|
+/// Front panel LEDs.
|
|
|
23
|
+pub struct LedPins {
|
|
|
24
|
+ vol0: PF2<Output<OpenDrain>>,
|
|
|
25
|
+ vol1: PF3<Output<OpenDrain>>,
|
|
|
26
|
+ vol2: PF4<Output<OpenDrain>>,
|
|
|
27
|
+ vol3: PF5<Output<OpenDrain>>,
|
|
|
28
|
+ vol4: PF6<Output<OpenDrain>>,
|
|
|
29
|
+ vol5: PF7<Output<OpenDrain>>,
|
|
|
30
|
+ vol6: PF8<Output<OpenDrain>>,
|
|
|
31
|
+ vol7: PF9<Output<OpenDrain>>,
|
|
|
32
|
+ vol8: PF10<Output<OpenDrain>>,
|
|
|
33
|
+ vol9: PC0<Output<OpenDrain>>,
|
|
|
34
|
+ vol10: PC1<Output<OpenDrain>>,
|
|
|
35
|
+ vol11: PA0<Output<OpenDrain>>,
|
|
|
36
|
+ vol12: PA1<Output<OpenDrain>>,
|
|
|
37
|
+ vol13: PA2<Output<OpenDrain>>,
|
|
|
38
|
+ vol14: PA3<Output<OpenDrain>>,
|
|
|
39
|
+ vol15: PA4<Output<OpenDrain>>,
|
|
|
40
|
+
|
|
|
41
|
+ front_rst: PG11<Output<PushPull>>,
|
|
|
42
|
+ front_sclk: PG13<Output<PushPull>>,
|
|
|
43
|
+ front_mosi: PG14<Output<PushPull>>,
|
|
|
44
|
+ front_rclk: PG15<Output<PushPull>>,
|
|
|
45
|
+}
|
|
|
46
|
+
|
|
|
47
|
+/// Connection to the bluetooth module.
|
|
|
48
|
+pub struct BluetoothModulePins {
|
|
|
49
|
+ mfb: PG2<Output<PushPull>>,
|
|
|
50
|
+ p6: PG4<Output<PushPull>>,
|
|
|
51
|
+ p7: PG5<Output<PushPull>>,
|
|
|
52
|
+ p8: PG6<Input<Floating>>,
|
|
|
53
|
+ p9: PD15<Input<Floating>>,
|
|
|
54
|
+ p16: PD14<Output<PushPull>>,
|
|
|
55
|
+ p17: PD13<Output<PushPull>>,
|
|
|
56
|
+ p18: PD12<Output<PushPull>>,
|
|
|
57
|
+ p21: PD11<Output<PushPull>>,
|
|
|
58
|
+ p29: PD10<Input<Floating>>,
|
|
|
59
|
+ p30: PD9<Input<Floating>>,
|
|
|
60
|
+ p31: PD8<Input<Floating>>,
|
|
|
61
|
+
|
|
|
62
|
+ sda: PF0<Alternate<AF4>>,
|
|
|
63
|
+ scl: PF1<Alternate<AF4>>,
|
|
|
64
|
+
|
|
|
65
|
+ spi_pcm: PG3<Output<PushPull>>,
|
|
|
66
|
+ i2s_ws: PA15<Alternate<AF6>>,
|
|
|
67
|
+ i2s_ck: PB3<Alternate<AF6>>,
|
|
|
68
|
+ i2s_sdi: PB4<Alternate<AF7>>,
|
|
|
69
|
+ i2s_sdo: PB5<Alternate<AF6>>,
|
|
|
70
|
+}
|
|
|
71
|
+
|
|
|
72
|
+/// Front panel input pins.
|
|
|
73
|
+pub struct InputPins {
|
|
|
74
|
+ ir: PG10<Input<Floating>>,
|
|
|
75
|
+ hp_detect: PD7<Input<Floating>>,
|
|
|
76
|
+ pwr: PE3<Input<Floating>>,
|
|
|
77
|
+ mic1: PE4<Input<Floating>>,
|
|
|
78
|
+ mic2: PE5<Input<Floating>>,
|
|
|
79
|
+ bt1: PE6<Input<Floating>>,
|
|
|
80
|
+ bt2: PC15<Input<Floating>>,
|
|
|
81
|
+ enc_a: PA5<Input<Floating>>,
|
|
|
82
|
+ enc_b: PA6<Input<Floating>>,
|
|
|
83
|
+ enc_sw: PA7<Input<Floating>>,
|
|
|
84
|
+}
|
|
|
85
|
+/// Connection to the amplifier ICs.
|
|
|
86
|
+pub struct AmplifierPins {
|
|
|
87
|
+ spk_fault: PD0<Input<Floating>>,
|
|
|
88
|
+ spk_shutdown: PD1<Output<PushPull>>,
|
|
|
89
|
+
|
|
|
90
|
+ sda: PB7<Alternate<AF4>>,
|
|
|
91
|
+ scl: PB6<Alternate<AF4>>,
|
|
|
92
|
+
|
|
|
93
|
+ i2s_mck: PC6<Alternate<AF5>>,
|
|
|
94
|
+ i2s_ws: PB9<Alternate<AF5>>,
|
|
|
95
|
+ i2s_ck: PB10<Alternate<AF5>>,
|
|
|
96
|
+ i2s_sdi: PC2<Alternate<AF6>>,
|
|
|
97
|
+ i2s_sdo: PC3<Alternate<AF5>>,
|
|
|
98
|
+}
|
|
|
99
|
+
|
|
|
100
|
+/// USB pins.
|
|
|
101
|
+pub struct UsbPins {
|
|
|
102
|
+ usb1_detect: PA10<Input<Floating>>,
|
|
|
103
|
+ usb1_dm: PA11<Alternate<AF10>>,
|
|
|
104
|
+ usb1_dp: PA12<Alternate<AF10>>,
|
|
|
105
|
+ usb2_detect: PB13<Input<Floating>>,
|
|
|
106
|
+ usb2_dm: PB14<Alternate<AF12>>,
|
|
|
107
|
+ usb2_dp: PB15<Alternate<AF12>>,
|
|
|
108
|
+}
|
|
3
|
109
|
|
|
4
|
110
|
/// Type which contains all GPIO pins.
|
|
5
|
111
|
///
|
|
6
|
112
|
/// The pins are configured as the correct type. Whenever possible, the corresponding HAL driver is
|
|
7
|
113
|
/// instantiated. The initial output state is set during configuration.
|
|
8
|
114
|
pub struct Pins {
|
|
9
|
|
- // TODO
|
|
|
115
|
+ leds: LedPins,
|
|
|
116
|
+ bluetooth_module: BluetoothModulePins,
|
|
|
117
|
+ input: InputPins,
|
|
|
118
|
+ amplifier: AmplifierPins,
|
|
|
119
|
+ usb: UsbPins,
|
|
10
|
120
|
}
|
|
11
|
121
|
|
|
12
|
122
|
impl Pins {
|
|
13
|
123
|
/// Configures the GPIO pins and sets their initial value.
|
|
14
|
|
- pub fn configure() -> Pins {
|
|
15
|
|
- Pins{
|
|
16
|
|
- // TODO
|
|
|
124
|
+ pub fn configure(
|
|
|
125
|
+ gpioa: GPIOA,
|
|
|
126
|
+ gpiob: GPIOB,
|
|
|
127
|
+ gpioc: GPIOC,
|
|
|
128
|
+ gpiod: GPIOD,
|
|
|
129
|
+ gpioe: GPIOE,
|
|
|
130
|
+ gpiof: GPIOF,
|
|
|
131
|
+ gpiog: GPIOG,
|
|
|
132
|
+ dma1: DMA1,
|
|
|
133
|
+ spi2: SPI2,
|
|
|
134
|
+ i2s2ext: I2S2EXT,
|
|
|
135
|
+ i2sclocks: I2SClocks,
|
|
|
136
|
+ ) -> Pins {
|
|
|
137
|
+ let gpioa = gpioa.split();
|
|
|
138
|
+ let gpiob = gpiob.split();
|
|
|
139
|
+ let gpioc = gpioc.split();
|
|
|
140
|
+ let gpiod = gpiod.split();
|
|
|
141
|
+ let gpioe = gpioe.split();
|
|
|
142
|
+ let gpiof = gpiof.split();
|
|
|
143
|
+ let gpiog = gpiog.split();
|
|
|
144
|
+
|
|
|
145
|
+ let leds = LedPins {
|
|
|
146
|
+ vol0: gpiof.pf2.into_open_drain_output(),
|
|
|
147
|
+ vol1: gpiof.pf3.into_open_drain_output(),
|
|
|
148
|
+ vol2: gpiof.pf4.into_open_drain_output(),
|
|
|
149
|
+ vol3: gpiof.pf5.into_open_drain_output(),
|
|
|
150
|
+ vol4: gpiof.pf6.into_open_drain_output(),
|
|
|
151
|
+ vol5: gpiof.pf7.into_open_drain_output(),
|
|
|
152
|
+ vol6: gpiof.pf8.into_open_drain_output(),
|
|
|
153
|
+ vol7: gpiof.pf9.into_open_drain_output(),
|
|
|
154
|
+ vol8: gpiof.pf10.into_open_drain_output(),
|
|
|
155
|
+ vol9: gpioc.pc0.into_open_drain_output(),
|
|
|
156
|
+ vol10: gpioc.pc1.into_open_drain_output(),
|
|
|
157
|
+ vol11: gpioa.pa0.into_open_drain_output(),
|
|
|
158
|
+ vol12: gpioa.pa1.into_open_drain_output(),
|
|
|
159
|
+ vol13: gpioa.pa2.into_open_drain_output(),
|
|
|
160
|
+ vol14: gpioa.pa3.into_open_drain_output(),
|
|
|
161
|
+ vol15: gpioa.pa4.into_open_drain_output(),
|
|
|
162
|
+
|
|
|
163
|
+ front_rst: gpiog.pg11.into_push_pull_output(),
|
|
|
164
|
+ front_sclk: gpiog.pg13.into_push_pull_output(),
|
|
|
165
|
+ front_mosi: gpiog.pg14.into_push_pull_output(),
|
|
|
166
|
+ front_rclk: gpiog.pg15.into_push_pull_output(),
|
|
|
167
|
+ };
|
|
|
168
|
+ // TODO: Initial LED values.
|
|
|
169
|
+
|
|
|
170
|
+ let bluetooth_module = BluetoothModulePins {
|
|
|
171
|
+ mfb: gpiog.pg2.into_push_pull_output(),
|
|
|
172
|
+ p6: gpiog.pg4.into_push_pull_output(),
|
|
|
173
|
+ p7: gpiog.pg5.into_push_pull_output(),
|
|
|
174
|
+ p8: gpiog.pg6.into_floating_input(),
|
|
|
175
|
+ p9: gpiod.pd15.into_floating_input(),
|
|
|
176
|
+ p16: gpiod.pd14.into_push_pull_output(),
|
|
|
177
|
+ p17: gpiod.pd13.into_push_pull_output(),
|
|
|
178
|
+ p18: gpiod.pd12.into_push_pull_output(),
|
|
|
179
|
+ p21: gpiod.pd11.into_push_pull_output(),
|
|
|
180
|
+ p29: gpiod.pd10.into_floating_input(),
|
|
|
181
|
+ p30: gpiod.pd9.into_floating_input(),
|
|
|
182
|
+ p31: gpiod.pd8.into_floating_input(),
|
|
|
183
|
+
|
|
|
184
|
+ sda: gpiof.pf0.into_alternate_af4(),
|
|
|
185
|
+ scl: gpiof.pf1.into_alternate_af4(),
|
|
|
186
|
+
|
|
|
187
|
+ spi_pcm: gpiog.pg3.into_push_pull_output(),
|
|
|
188
|
+ i2s_ws: gpioa.pa15.into_alternate_af6(),
|
|
|
189
|
+ i2s_ck: gpiob.pb3.into_alternate_af6(),
|
|
|
190
|
+ i2s_sdi: gpiob.pb4.into_alternate_af7(),
|
|
|
191
|
+ i2s_sdo: gpiob.pb5.into_alternate_af6(),
|
|
|
192
|
+ };
|
|
|
193
|
+
|
|
|
194
|
+ let input = InputPins {
|
|
|
195
|
+ ir: gpiog.pg10.into_floating_input(),
|
|
|
196
|
+ hp_detect: gpiod.pd7.into_floating_input(),
|
|
|
197
|
+ pwr: gpioe.pe3.into_floating_input(),
|
|
|
198
|
+ mic1: gpioe.pe4.into_floating_input(),
|
|
|
199
|
+ mic2: gpioe.pe5.into_floating_input(),
|
|
|
200
|
+ bt1: gpioe.pe6.into_floating_input(),
|
|
|
201
|
+ bt2: gpioc.pc15.into_floating_input(),
|
|
|
202
|
+ enc_a: gpioa.pa5.into_floating_input(),
|
|
|
203
|
+ enc_b: gpioa.pa6.into_floating_input(),
|
|
|
204
|
+ enc_sw: gpioa.pa7.into_floating_input(),
|
|
|
205
|
+ };
|
|
|
206
|
+
|
|
|
207
|
+ let amplifier = AmplifierPins {
|
|
|
208
|
+ spk_fault: gpiod.pd0.into_floating_input(),
|
|
|
209
|
+ spk_shutdown: gpiod.pd1.into_push_pull_output(),
|
|
|
210
|
+
|
|
|
211
|
+ sda: gpiob.pb7.into_alternate_af4(),
|
|
|
212
|
+ scl: gpiob.pb6.into_alternate_af4(),
|
|
|
213
|
+
|
|
|
214
|
+ i2s_mck: gpioc.pc6.into_alternate_af5(),
|
|
|
215
|
+ i2s_ws: gpiob.pb9.into_alternate_af5(),
|
|
|
216
|
+ i2s_ck: gpiob.pb10.into_alternate_af5(),
|
|
|
217
|
+ i2s_sdi: gpioc.pc2.into_alternate_af6(),
|
|
|
218
|
+ i2s_sdo: gpioc.pc3.into_alternate_af5(),
|
|
|
219
|
+ };
|
|
|
220
|
+
|
|
|
221
|
+ let usb = UsbPins {
|
|
|
222
|
+ usb1_detect: gpioa.pa10.into_floating_input(),
|
|
|
223
|
+ usb1_dm: gpioa.pa11.into_alternate_af10(),
|
|
|
224
|
+ usb1_dp: gpioa.pa12.into_alternate_af10(),
|
|
|
225
|
+ usb2_detect: gpiob.pb13.into_floating_input(),
|
|
|
226
|
+ usb2_dm: gpiob.pb14.into_alternate_af12(),
|
|
|
227
|
+ usb2_dp: gpiob.pb15.into_alternate_af12(),
|
|
|
228
|
+ };
|
|
|
229
|
+
|
|
|
230
|
+ /*let dma = StreamsTuple::new(dma1);
|
|
|
231
|
+ let mut i2s = I2S::new(
|
|
|
232
|
+ spi2,
|
|
|
233
|
+ i2s2ext,
|
|
|
234
|
+ dma.3,
|
|
|
235
|
+ dma.4,
|
|
|
236
|
+ gpioc.pc6.into_alternate_af5(),
|
|
|
237
|
+ gpiob.pb12.into_alternate_af5(),
|
|
|
238
|
+ gpiob.pb13.into_alternate_af5(),
|
|
|
239
|
+ gpiob.pb14.into_alternate_af6(),
|
|
|
240
|
+ gpiob.pb15.into_alternate_af5(),
|
|
|
241
|
+ &_I2S_IN_BUFFER,
|
|
|
242
|
+ &_I2S_OUT_BUFFER,
|
|
|
243
|
+ i2sclocks,
|
|
|
244
|
+ );*/
|
|
|
245
|
+
|
|
|
246
|
+ Pins {
|
|
|
247
|
+ leds,
|
|
|
248
|
+ bluetooth_module,
|
|
|
249
|
+ input,
|
|
|
250
|
+ amplifier,
|
|
|
251
|
+ usb,
|
|
17
|
252
|
}
|
|
18
|
253
|
}
|
|
19
|
254
|
}
|