Skip to content

Commit a31192f

Browse files
committed
Another probable watchdog API design (issue #98)
1 parent 036cfa4 commit a31192f

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/prelude.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ pub use crate::serial::Write as _embedded_hal_serial_Write;
2828
pub use crate::spi::FullDuplex as _embedded_hal_spi_FullDuplex;
2929
pub use crate::timer::CountDown as _embedded_hal_timer_CountDown;
3030
pub use crate::watchdog::Watchdog as _embedded_hal_watchdog_Watchdog;
31-
pub use crate::watchdog::WatchdogDisable as _embedded_hal_watchdog_WatchdogDisable;
32-
pub use crate::watchdog::WatchdogEnable as _embedded_hal_watchdog_WatchdogEnable;
31+
pub use crate::watchdog::Disable as _embedded_hal_watchdog_Disable;
32+
pub use crate::watchdog::Enable as _embedded_hal_watchdog_Enable;

src/watchdog.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,41 @@ pub trait Watchdog {
1515

1616
/// Enables A watchdog timer to reset the processor if software is frozen or
1717
/// stalled.
18-
pub trait WatchdogEnable {
19-
/// An enumeration of `WatchdogEnable` errors.
18+
pub trait Enable {
19+
/// An enumeration of `Enable` errors.
2020
///
2121
/// For infallible implementations, will be `Infallible`
2222
type Error;
2323

2424
/// Unit of time used by the watchdog
2525
type Time;
2626

27-
/// Starts the watchdog with a given period, typically once this is done
28-
/// the watchdog needs to be kicked periodically or the processor is reset.
29-
fn try_start<T>(&mut self, period: T) -> Result<(), Self::Error>
27+
/// The started watchdog that should be `feed()`
28+
type Target: Watchdog;
29+
30+
/// Starts the watchdog with a given period, typically once this is done
31+
/// the watchdog needs to be kicked periodically or the processor is reset.
32+
///
33+
/// This consumes the value and returns the `Watchdog` trait that you must
34+
/// `feed()`.
35+
fn try_start<T>(&mut self, period: T) -> Result<Self::Target, Self::Error>
3036
where
3137
T: Into<Self::Time>;
3238
}
3339

3440
/// Disables a running watchdog timer so the processor won't be reset.
35-
pub trait WatchdogDisable {
36-
/// An enumeration of `WatchdogDisable` errors.
41+
pub trait Disable {
42+
/// An enumeration of `Disable` errors.
3743
///
3844
/// For infallible implementations, will be `Infallible`
3945
type Error;
4046

47+
/// Disabled watchdog instance that can be enabled.
48+
type Target: Enable;
49+
4150
/// Disables the watchdog
42-
fn try_disable(&mut self) -> Result<(), Self::Error>;
51+
///
52+
/// This stops the watchdog and returns the `Enable` trait so that
53+
/// it can be started again.
54+
fn try_disable(&mut self) -> Result<Self::Target, Self::Error>;
4355
}

0 commit comments

Comments
 (0)