Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve watchdog API design using move semantics #222

Merged
merged 3 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Changed

- The method `try_write` from the trait `blocking::i2c::WriteIter` trait
has been renamed `try_write_iter` for consistency.
- Updated `nb` dependency to version `1`.
- The watchdog API now uses move semantics. See [PR](https://github.com/rust-embedded/embedded-hal/pull/222).

## [v1.0.0-alpha.1] - 2020-06-16

Expand Down
4 changes: 2 additions & 2 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ pub use crate::spi::FullDuplex as _embedded_hal_spi_FullDuplex;
pub use crate::timer::Cancel as _embedded_hal_timer_Cancel;
pub use crate::timer::CountDown as _embedded_hal_timer_CountDown;
pub use crate::timer::Periodic as _embedded_hal_timer_Periodic;
pub use crate::watchdog::Disable as _embedded_hal_watchdog_Disable;
pub use crate::watchdog::Enable as _embedded_hal_watchdog_Enable;
pub use crate::watchdog::Watchdog as _embedded_hal_watchdog_Watchdog;
pub use crate::watchdog::WatchdogDisable as _embedded_hal_watchdog_WatchdogDisable;
pub use crate::watchdog::WatchdogEnable as _embedded_hal_watchdog_WatchdogEnable;
37 changes: 27 additions & 10 deletions src/watchdog.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Traits for interactions with a processors watchdog timer.

/// Feeds an existing watchdog to ensure the processor isn't reset. Sometimes
/// commonly referred to as "kicking" or "refreshing".
/// the "feeding" operation is also referred to as "refreshing".
pub trait Watchdog {
/// An enumeration of `Watchdog` errors.
///
Expand All @@ -15,29 +15,46 @@ pub trait Watchdog {

/// Enables A watchdog timer to reset the processor if software is frozen or
/// stalled.
pub trait WatchdogEnable {
/// An enumeration of `WatchdogEnable` errors.
pub trait Enable {
/// An enumeration of `Enable` errors.
///
/// For infallible implementations, will be `Infallible`
type Error;

/// Unit of time used by the watchdog
/// Unit of time used by the watchdog.
type Time;

/// The started watchdog that should be `feed()`.
type Target: Watchdog;

/// Starts the watchdog with a given period, typically once this is done
/// the watchdog needs to be kicked periodically or the processor is reset.
fn try_start<T>(&mut self, period: T) -> Result<(), Self::Error>
/// the watchdog needs to be `feed()` periodically, or the processor would be
/// reset.
///
/// This consumes the value and returns the `Watchdog` trait that you must
/// `feed()`.
fn try_start<T>(self, period: T) -> Result<Self::Target, Self::Error>
where
T: Into<Self::Time>;
}

/// Disables a running watchdog timer so the processor won't be reset.
pub trait WatchdogDisable {
/// An enumeration of `WatchdogDisable` errors.
///
/// Not all watchdog timers support disable operation after they've been enabled.
/// In this case, hardware support libraries would not implement this trait
/// and hardware-agnostic libraries should consider not requiring it.
pub trait Disable {
/// An enumeration of `Disable` errors.
///
/// For infallible implementations, will be `Infallible`
type Error;

/// Disables the watchdog
fn try_disable(&mut self) -> Result<(), Self::Error>;
/// Disabled watchdog instance that can be enabled.
type Target: Enable;

/// Disables the watchdog.
///
/// This stops the watchdog and returns an instance implementing the
/// `Enable` trait so that it can be started again.
fn try_disable(self) -> Result<Self::Target, Self::Error>;
}