@@ -110,7 +110,7 @@ fn run() -> ! {
110
110
gpio_a, gpio_b, gpio_c, gpio_d, gpio_e, gpio_f, gpio_g, gpio_h, gpio_i, gpio_j, gpio_k,
111
111
) ;
112
112
113
- // configures the system timer to trigger a SysTick exception every second
113
+ // configures the system timer to trigger a SysTick exception every 10ms
114
114
init:: init_systick ( Hz ( 100 ) , & mut systick, & rcc) ;
115
115
systick. enable_interrupt ( ) ;
116
116
@@ -127,27 +127,33 @@ fn run() -> ! {
127
127
let mut layer_2 = lcd. layer_2 ( ) . unwrap ( ) ;
128
128
129
129
layer_2. clear ( ) ;
130
+
131
+ // Make `println` print to the LCD
130
132
lcd:: init_stdout ( layer_2) ;
131
133
132
134
println ! ( "Hello World" ) ;
133
135
134
-
136
+ // example allocation
135
137
let _xs = vec ! [ 1 , 2 , 3 ] ;
136
138
137
139
let mut i2c_3 = init:: init_i2c_3 ( Box :: leak ( Box :: new ( peripherals. I2C3 ) ) , & mut rcc) ;
138
140
i2c_3. test_1 ( ) ;
139
141
i2c_3. test_2 ( ) ;
140
142
143
+ // TODO: is this needed?
141
144
nvic. enable ( Interrupt :: EXTI0 ) ;
142
145
143
146
let mut sd = sd:: Sd :: new ( & mut sdmmc, & mut rcc, & pins. sdcard_present ) ;
144
147
148
+ // audio initialization
145
149
init:: init_sai_2 ( & mut sai_2, & mut rcc) ;
146
150
init:: init_wm8994 ( & mut i2c_3) . expect ( "WM8994 init failed" ) ;
151
+
147
152
// touch initialization should be done after audio initialization, because the touch
148
153
// controller might not be ready yet
149
154
touch:: check_family_id ( & mut i2c_3) . unwrap ( ) ;
150
155
156
+ // initialization of random number generator
151
157
let mut rng = Rng :: init ( & mut rng, & mut rcc) . expect ( "RNG init failed" ) ;
152
158
print ! ( "Random numbers: " ) ;
153
159
for _ in 0 ..4 {
@@ -186,40 +192,50 @@ fn run() -> ! {
186
192
StreamExt ,
187
193
} ;
188
194
195
+ // Future channels for passing interrupts events. The interrupt handler pushes
196
+ // to a channel and the interrupt handler awaits the next item of the channel. There
197
+ // is no data exchange, the item is always a zero sized `()`.
198
+ // TODO: Currently we use futures::channel::mpsc, which means that we allocate heap
199
+ // memory even though the item type is zero-sized. To avoid this we could build our
200
+ // own channel type that uses an atomic counter instead of storing any items.
189
201
let ( idle_waker_sink, mut idle_waker_stream) = mpsc:: unbounded ( ) ;
190
202
let ( tim6_sink, tim6_stream) = mpsc:: unbounded ( ) ;
191
203
let ( button_sink, button_stream) = mpsc:: unbounded ( ) ;
192
204
let ( touch_int_sink, touch_int_stream) = mpsc:: unbounded ( ) ;
193
205
206
+ // Interrupt handler for the TIM6_DAC interrupt, which is the interrupt triggered by
207
+ // the tim6 timer.
194
208
interrupt_table. register ( InterruptRequest :: TIM6_DAC , Priority :: P1 , move || {
195
209
tim6_sink. unbounded_send ( ( ) ) . expect ( "sending on tim6 channel failed" ) ;
196
210
let tim = & mut tim6;
197
211
// make sure the interrupt doesn't just restart again by clearing the flag
198
212
tim. sr . modify ( |_, w| w. uif ( ) . clear_bit ( ) ) ;
199
213
} ) . expect ( "registering tim6 interrupt failed" ) ;
200
214
201
- // choose pin I-11 for exti11 line
215
+ // choose pin I-11 for exti11 line, which is the GPIO pin for the hardware button
202
216
syscfg. exticr3 . modify ( |_, w| unsafe { w. exti11 ( ) . bits ( 0b1000 ) } ) ;
203
217
// trigger exti11 on rising
204
218
exti. rtsr . modify ( |_, w| w. tr11 ( ) . set_bit ( ) ) ;
205
219
// unmask exti11 line
206
220
exti. imr . modify ( |_, w| w. mr11 ( ) . set_bit ( ) ) ;
207
221
208
- // choose pin I-13 for exti13 line
222
+ // choose pin I-13 for exti13 line, which is the GPIO pin signalizing a touch event
209
223
syscfg. exticr4 . modify ( |_, w| unsafe { w. exti13 ( ) . bits ( 0b1000 ) } ) ;
210
224
// trigger exti13 on rising
211
225
exti. rtsr . modify ( |_, w| w. tr13 ( ) . set_bit ( ) ) ;
212
226
// unmask exti13 line
213
227
exti. imr . modify ( |_, w| w. mr13 ( ) . set_bit ( ) ) ;
214
228
215
- // choose pin H-15 for exti15 line
229
+ // choose pin H-15 for exti15 line, which is the GPIO pin signalizing new audio data
230
+ // TODO: the audio interrupt doesn't work yet
216
231
syscfg. exticr4 . modify ( |_, w| unsafe { w. exti15 ( ) . bits ( 0b0111 ) } ) ;
217
232
// trigger exti15 on rising
218
233
exti. rtsr . modify ( |_, w| w. tr15 ( ) . set_bit ( ) ) ;
219
234
// unmask exti15 line
220
235
exti. imr . modify ( |_, w| w. mr15 ( ) . set_bit ( ) ) ;
221
236
222
-
237
+ // Interrupt handler for the EXTI15_10 interrupt, which is triggered by different
238
+ // sources.
223
239
interrupt_table. register ( InterruptRequest :: EXTI15_10 , Priority :: P1 , move || {
224
240
exti. pr . modify ( |r, w| {
225
241
if r. pr11 ( ) . bit_is_set ( ) {
@@ -235,14 +251,6 @@ fn run() -> ! {
235
251
} ) ;
236
252
} ) . expect ( "registering exti15_10 interrupt failed" ) ;
237
253
238
-
239
-
240
- interrupt_table. register ( InterruptRequest :: EXTI9_5 , Priority :: P1 , move || {
241
- panic ! ( "unknown exti9_5 interrupt" ) ;
242
- } ) . expect ( "registering exti9_5 interrupt failed" ) ;
243
-
244
- // tasks
245
-
246
254
let idle_stream = task_runtime:: IdleStream :: new ( idle_waker_sink. clone ( ) ) ;
247
255
248
256
// ethernet
0 commit comments