Skip to content

Commit da0dfe5

Browse files
committed
Implement inherent functions for the watchdog
Embedded-hal 0.2 trait impls are now wrappers for inherent functions
1 parent 4480c1d commit da0dfe5

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

rp2040-hal/examples/watchdog.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ use hal::pac;
2222

2323
// Some traits we need
2424
use embedded_hal::digital::OutputPin;
25-
// Embedded HAL 1.0.0 doesn't have an Watchdog trait, so use the one from 0.2
26-
use embedded_hal_0_2::watchdog::{Watchdog, WatchdogEnable};
2725
use hal::fugit::ExtU32;
2826
use rp2040_hal::clocks::Clock;
2927

rp2040-hal/src/watchdog.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,17 @@ impl Watchdog {
150150
w
151151
});
152152
}
153-
}
154153

155-
impl watchdog::Watchdog for Watchdog {
156-
fn feed(&mut self) {
154+
/// Set the watchdog counter back to its load value, making sure
155+
/// that the watchdog reboot will not be triggered for the configured
156+
/// period.
157+
pub fn feed(&self) {
157158
self.load_counter(self.load_value)
158159
}
159-
}
160-
161-
impl watchdog::WatchdogEnable for Watchdog {
162-
type Time = MicrosDurationU32;
163160

164-
fn start<T: Into<Self::Time>>(&mut self, period: T) {
161+
/// Start the watchdog. This enables a timer which will reboot the
162+
/// rp2040 if [`feed()`] doesnot get called for the configured period.
163+
pub fn start<T: Into<MicrosDurationU32>>(&mut self, period: T) {
165164
const MAX_PERIOD: u32 = 0xFFFFFF;
166165

167166
let delay_us = period.into().to_micros();
@@ -183,10 +182,29 @@ impl watchdog::WatchdogEnable for Watchdog {
183182
self.load_counter(self.load_value);
184183
self.enable(true);
185184
}
185+
186+
/// Disable the watchdog timer.
187+
pub fn disable(&self) {
188+
self.enable(false)
189+
}
190+
}
191+
192+
impl watchdog::Watchdog for Watchdog {
193+
fn feed(&mut self) {
194+
(*self).feed()
195+
}
196+
}
197+
198+
impl watchdog::WatchdogEnable for Watchdog {
199+
type Time = MicrosDurationU32;
200+
201+
fn start<T: Into<Self::Time>>(&mut self, period: T) {
202+
self.start(period)
203+
}
186204
}
187205

188206
impl watchdog::WatchdogDisable for Watchdog {
189207
fn disable(&mut self) {
190-
self.enable(false)
208+
(*self).disable()
191209
}
192210
}

0 commit comments

Comments
 (0)