Skip to content

Commit 8a7500b

Browse files
committed
Improve watchdog API design using move semantics
Co-authored-by: Diego Barrios Romero <[email protected]> Co-authored-by: Daniel Egger <@therealprof:matrix.org>
1 parent a31192f commit 8a7500b

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88

99
## [Unreleased]
1010

11+
### Changed
12+
13+
- The watchdog API now uses move semantics. See [PR](https://github.com/rust-embedded/embedded-hal/pull/222).
14+
1115
## [v1.0.0-alpha.1] - 2020-06-16
1216

1317
*** This is an alpha release with breaking changes (sorry) ***

src/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ pub use crate::serial::Read as _embedded_hal_serial_Read;
2727
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;
30-
pub use crate::watchdog::Watchdog as _embedded_hal_watchdog_Watchdog;
3130
pub use crate::watchdog::Disable as _embedded_hal_watchdog_Disable;
3231
pub use crate::watchdog::Enable as _embedded_hal_watchdog_Enable;
32+
pub use crate::watchdog::Watchdog as _embedded_hal_watchdog_Watchdog;

src/watchdog.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Traits for interactions with a processors watchdog timer.
22
33
/// Feeds an existing watchdog to ensure the processor isn't reset. Sometimes
4-
/// commonly referred to as "kicking" or "refreshing".
4+
/// the "feeding" operation is also referred to as "refreshing".
55
pub trait Watchdog {
66
/// An enumeration of `Watchdog` errors.
77
///
@@ -21,23 +21,28 @@ pub trait Enable {
2121
/// For infallible implementations, will be `Infallible`
2222
type Error;
2323

24-
/// Unit of time used by the watchdog
24+
/// Unit of time used by the watchdog.
2525
type Time;
2626

27-
/// The started watchdog that should be `feed()`
27+
/// The started watchdog that should be `feed()`.
2828
type Target: Watchdog;
2929

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.
30+
/// Starts the watchdog with a given period, typically once this is done
31+
/// the watchdog needs to be `feed()` periodically, or the processor would be
32+
/// reset.
3233
///
3334
/// This consumes the value and returns the `Watchdog` trait that you must
3435
/// `feed()`.
35-
fn try_start<T>(&mut self, period: T) -> Result<Self::Target, Self::Error>
36+
fn try_start<T>(self, period: T) -> Result<Self::Target, Self::Error>
3637
where
3738
T: Into<Self::Time>;
3839
}
3940

4041
/// Disables a running watchdog timer so the processor won't be reset.
42+
///
43+
/// Not all watchdog timers support disable operation after they've been enabled.
44+
/// In this case, hardware support libraries would not implement this trait
45+
/// and hardware-agnostic libraries should consider not requiring it.
4146
pub trait Disable {
4247
/// An enumeration of `Disable` errors.
4348
///
@@ -47,9 +52,9 @@ pub trait Disable {
4752
/// Disabled watchdog instance that can be enabled.
4853
type Target: Enable;
4954

50-
/// Disables the watchdog
55+
/// Disables the watchdog.
5156
///
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>;
57+
/// This stops the watchdog and returns an instance implementing the
58+
/// `Enable` trait so that it can be started again.
59+
fn try_disable(self) -> Result<Self::Target, Self::Error>;
5560
}

0 commit comments

Comments
 (0)