From 90470b6ff3e3aada90a0c50f221092d2d8a4c717 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= <AlexanderMeissner@gmx.net>
Date: Sat, 2 Oct 2021 07:41:04 +0200
Subject: [PATCH] Adds reset for timer, otherwise it would not run. (#136)

---
 boards/pico/examples/pico_countdown_blinky.rs         | 2 +-
 boards/pico/examples/pico_usb_serial.rs               | 2 +-
 boards/pro_micro_rp2040/examples/pro_micro_rainbow.rs | 2 +-
 rp2040-hal/src/timer.rs                               | 6 ++++--
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/boards/pico/examples/pico_countdown_blinky.rs b/boards/pico/examples/pico_countdown_blinky.rs
index f6a3ea7..a4d162f 100644
--- a/boards/pico/examples/pico_countdown_blinky.rs
+++ b/boards/pico/examples/pico_countdown_blinky.rs
@@ -61,7 +61,7 @@ fn main() -> ! {
     .unwrap();
 
     // Configure the Timer peripheral in count-down mode
-    let timer = hal::timer::Timer::new(pac.TIMER);
+    let timer = hal::timer::Timer::new(pac.TIMER, &mut pac.RESETS);
     let mut count_down = timer.count_down();
 
     // The single-cycle I/O block controls our GPIO pins
diff --git a/boards/pico/examples/pico_usb_serial.rs b/boards/pico/examples/pico_usb_serial.rs
index 2732da2..fb431b1 100644
--- a/boards/pico/examples/pico_usb_serial.rs
+++ b/boards/pico/examples/pico_usb_serial.rs
@@ -89,7 +89,7 @@ fn main() -> ! {
         .device_class(2) // from: https://www.usb.org/defined-class-codes
         .build();
 
-    let timer = hal::timer::Timer::new(pac.TIMER);
+    let timer = hal::timer::Timer::new(pac.TIMER, &mut pac.RESETS);
     let mut said_hello = false;
     loop {
         // A welcome message at the beginning
diff --git a/boards/pro_micro_rp2040/examples/pro_micro_rainbow.rs b/boards/pro_micro_rp2040/examples/pro_micro_rainbow.rs
index dd9a094..ae825e5 100644
--- a/boards/pro_micro_rp2040/examples/pro_micro_rainbow.rs
+++ b/boards/pro_micro_rp2040/examples/pro_micro_rainbow.rs
@@ -71,7 +71,7 @@ fn main() -> ! {
 
     let _led: Pin<_, FunctionPio0> = pins.led.into_mode();
 
-    let timer = Timer::new(pac.TIMER);
+    let timer = Timer::new(pac.TIMER, &mut pac.RESETS);
     let mut delay = timer.count_down();
 
     // Configure the addressable LED
diff --git a/rp2040-hal/src/timer.rs b/rp2040-hal/src/timer.rs
index 89a2d11..5728627 100644
--- a/rp2040-hal/src/timer.rs
+++ b/rp2040-hal/src/timer.rs
@@ -3,7 +3,8 @@
 
 use embedded_time::duration::Microseconds;
 
-use crate::pac::TIMER;
+use crate::pac::{RESETS, TIMER};
+use crate::resets::SubsystemReset;
 
 /// Timer peripheral
 pub struct Timer {
@@ -12,7 +13,8 @@ pub struct Timer {
 
 impl Timer {
     /// Create a new [`Timer`]
-    pub fn new(timer: TIMER) -> Self {
+    pub fn new(timer: TIMER, resets: &mut RESETS) -> Self {
+        timer.reset_bring_up(resets);
         Self { timer }
     }