Skip to content

Commit c38a160

Browse files
committed
Add/improve some comments, remove some unneeded code
1 parent b3dbff5 commit c38a160

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/bin/async-await.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn run() -> ! {
110110
gpio_a, gpio_b, gpio_c, gpio_d, gpio_e, gpio_f, gpio_g, gpio_h, gpio_i, gpio_j, gpio_k,
111111
);
112112

113-
// configures the system timer to trigger a SysTick exception every second
113+
// configures the system timer to trigger a SysTick exception every 10ms
114114
init::init_systick(Hz(100), &mut systick, &rcc);
115115
systick.enable_interrupt();
116116

@@ -127,27 +127,33 @@ fn run() -> ! {
127127
let mut layer_2 = lcd.layer_2().unwrap();
128128

129129
layer_2.clear();
130+
131+
// Make `println` print to the LCD
130132
lcd::init_stdout(layer_2);
131133

132134
println!("Hello World");
133135

134-
136+
// example allocation
135137
let _xs = vec![1, 2, 3];
136138

137139
let mut i2c_3 = init::init_i2c_3(Box::leak(Box::new(peripherals.I2C3)), &mut rcc);
138140
i2c_3.test_1();
139141
i2c_3.test_2();
140142

143+
// TODO: is this needed?
141144
nvic.enable(Interrupt::EXTI0);
142145

143146
let mut sd = sd::Sd::new(&mut sdmmc, &mut rcc, &pins.sdcard_present);
144147

148+
// audio initialization
145149
init::init_sai_2(&mut sai_2, &mut rcc);
146150
init::init_wm8994(&mut i2c_3).expect("WM8994 init failed");
151+
147152
// touch initialization should be done after audio initialization, because the touch
148153
// controller might not be ready yet
149154
touch::check_family_id(&mut i2c_3).unwrap();
150155

156+
// initialization of random number generator
151157
let mut rng = Rng::init(&mut rng, &mut rcc).expect("RNG init failed");
152158
print!("Random numbers: ");
153159
for _ in 0..4 {
@@ -186,40 +192,50 @@ fn run() -> ! {
186192
StreamExt,
187193
};
188194

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.
189201
let (idle_waker_sink, mut idle_waker_stream) = mpsc::unbounded();
190202
let (tim6_sink, tim6_stream) = mpsc::unbounded();
191203
let (button_sink, button_stream) = mpsc::unbounded();
192204
let (touch_int_sink, touch_int_stream) = mpsc::unbounded();
193205

206+
// Interrupt handler for the TIM6_DAC interrupt, which is the interrupt triggered by
207+
// the tim6 timer.
194208
interrupt_table.register(InterruptRequest::TIM6_DAC, Priority::P1, move || {
195209
tim6_sink.unbounded_send(()).expect("sending on tim6 channel failed");
196210
let tim = &mut tim6;
197211
// make sure the interrupt doesn't just restart again by clearing the flag
198212
tim.sr.modify(|_, w| w.uif().clear_bit());
199213
}).expect("registering tim6 interrupt failed");
200214

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
202216
syscfg.exticr3.modify(|_, w| unsafe { w.exti11().bits(0b1000) });
203217
// trigger exti11 on rising
204218
exti.rtsr.modify(|_, w| w.tr11().set_bit());
205219
// unmask exti11 line
206220
exti.imr.modify(|_, w| w.mr11().set_bit());
207221

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
209223
syscfg.exticr4.modify(|_, w| unsafe { w.exti13().bits(0b1000) });
210224
// trigger exti13 on rising
211225
exti.rtsr.modify(|_, w| w.tr13().set_bit());
212226
// unmask exti13 line
213227
exti.imr.modify(|_, w| w.mr13().set_bit());
214228

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
216231
syscfg.exticr4.modify(|_, w| unsafe { w.exti15().bits(0b0111) });
217232
// trigger exti15 on rising
218233
exti.rtsr.modify(|_, w| w.tr15().set_bit());
219234
// unmask exti15 line
220235
exti.imr.modify(|_, w| w.mr15().set_bit());
221236

222-
237+
// Interrupt handler for the EXTI15_10 interrupt, which is triggered by different
238+
// sources.
223239
interrupt_table.register(InterruptRequest::EXTI15_10, Priority::P1, move || {
224240
exti.pr.modify(|r, w| {
225241
if r.pr11().bit_is_set() {
@@ -235,14 +251,6 @@ fn run() -> ! {
235251
});
236252
}).expect("registering exti15_10 interrupt failed");
237253

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-
246254
let idle_stream = task_runtime::IdleStream::new(idle_waker_sink.clone());
247255

248256
// ethernet

src/init/pins.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,6 @@ pub fn init<'a>(
294294
let audio_in = gpio_h
295295
.to_input(gpio_h_pins.pin_15.pin(), Resistor::NoPull,)
296296
.expect("Failed to reserve SAI2 audio in pin");
297-
/*let audio_in = gpio_d
298-
.to_input(gpio_d_pins.pin_6.pin(), Resistor::NoPull,)
299-
.expect("Failed to reserve SAI2 audio in pin");*/
300297
audio_in
301298
};
302299

src/task_runtime.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ impl Wake for NoOpWaker {
118118
}
119119
}
120120

121+
// TODO document, check behavior
121122
#[derive(Debug, Clone)]
122123
pub struct IdleStream {
123124
idle: bool,

0 commit comments

Comments
 (0)