Skip to content

Commit e5294fb

Browse files
authored
Audit timers HAL #3: Remove unwraps (#532)
Depends on #531 Resolves #530 This removes the last of the panic paths in the timers HAL by removing unwraps and changing a few constructors to return a `Result` instead (which introduces a breaking change). A new freq field was added to the PWM struct since originally, we unwrapped in a PWM trait method which does not return a `Result`. So, we just verify the clock config is valid in the constructor and can use the cached freq in the trait methods.
1 parent fc2ddfd commit e5294fb

File tree

2 files changed

+106
-99
lines changed

2 files changed

+106
-99
lines changed

examples/rt685s-evk/src/bin/timer.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ async fn main(spawner: Spawner) {
3131
spawner.spawn(monitor_task()).unwrap();
3232

3333
let sfro = ClockConfig::crystal().sfro;
34-
let mut tmr1 = CountingTimer::new_blocking(p.CTIMER0_COUNT_CHANNEL0, sfro);
34+
let mut tmr1 = CountingTimer::new_blocking(p.CTIMER0_COUNT_CHANNEL0, sfro).expect("Invalid clock config");
3535

3636
let sfro = ClockConfig::crystal().sfro;
37-
let mut tmr2 = CountingTimer::new_async(p.CTIMER1_COUNT_CHANNEL0, sfro, Irqs);
37+
let mut tmr2 = CountingTimer::new_async(p.CTIMER1_COUNT_CHANNEL0, sfro, Irqs).expect("Invalid clock config");
3838

3939
tmr1.wait_us(3000000); // 3 seoconds wait
4040
info!("First Counting timer expired");
@@ -45,15 +45,17 @@ async fn main(spawner: Spawner) {
4545
{
4646
let sfro = ClockConfig::crystal().sfro;
4747
let mut cap_async_tmr =
48-
CaptureTimer::new_async(p.CTIMER4_CAPTURE_CHANNEL0.reborrow(), p.PIO0_5.reborrow(), sfro, Irqs);
48+
CaptureTimer::new_async(p.CTIMER4_CAPTURE_CHANNEL0.reborrow(), p.PIO0_5.reborrow(), sfro, Irqs)
49+
.expect("Invalid clock config");
4950
let event_time_us = cap_async_tmr.capture_cycle_time_us(CaptureChEdge::Rising).await;
5051
info!("Capture timer expired, time between two capture = {} us", event_time_us);
5152

5253
drop(cap_async_tmr);
5354

5455
let sfro = ClockConfig::crystal().sfro;
5556
let mut cap_async_tmr =
56-
CaptureTimer::new_async(p.CTIMER4_CAPTURE_CHANNEL0.reborrow(), p.PIO0_5.reborrow(), sfro, Irqs);
57+
CaptureTimer::new_async(p.CTIMER4_CAPTURE_CHANNEL0.reborrow(), p.PIO0_5.reborrow(), sfro, Irqs)
58+
.expect("Invalid clock config");
5759
let event_time_us = cap_async_tmr.capture_cycle_time_us(CaptureChEdge::Rising).await;
5860
info!("Capture timer expired, time between two capture = {} us", event_time_us);
5961
}

0 commit comments

Comments
 (0)