From 7303edb8085053dfce908dfb26345d0c5d3d76da Mon Sep 17 00:00:00 2001 From: Sympatron <35803463+Sympatron@users.noreply.github.com> Date: Thu, 24 Jun 2021 11:37:42 +0200 Subject: [PATCH 1/2] Moved `unproven` feature gates to trait impl blocks --- hal/src/thumbv6m/adc.rs | 2 ++ hal/src/thumbv6m/mod.rs | 3 --- hal/src/thumbv6m/pwm.rs | 2 ++ hal/src/thumbv6m/watchdog.rs | 3 +++ hal/src/thumbv7em/adc.rs | 2 ++ hal/src/thumbv7em/mod.rs | 5 ----- hal/src/thumbv7em/pwm.rs | 2 ++ hal/src/thumbv7em/watchdog.rs | 3 +++ 8 files changed, 14 insertions(+), 8 deletions(-) diff --git a/hal/src/thumbv6m/adc.rs b/hal/src/thumbv6m/adc.rs index f60378c55b44..6b700d34e901 100644 --- a/hal/src/thumbv6m/adc.rs +++ b/hal/src/thumbv6m/adc.rs @@ -140,6 +140,7 @@ impl Adc { } } +#[cfg(feature = "unproven")] impl OneShot for Adc where WORD: From, @@ -179,6 +180,7 @@ macro_rules! adc_pins { /// Implement [`Channel`] for [`v1::Pin`]s based on the implementations for /// `v2` [`Pin`]s +#[cfg(feature = "unproven")] impl Channel for v1::Pin where I: PinId, diff --git a/hal/src/thumbv6m/mod.rs b/hal/src/thumbv6m/mod.rs index 42f1820bd1a4..06868d82f1f1 100644 --- a/hal/src/thumbv6m/mod.rs +++ b/hal/src/thumbv6m/mod.rs @@ -10,13 +10,10 @@ pub mod calibration; pub mod clock; pub mod timer; -#[cfg(feature = "unproven")] pub mod adc; -#[cfg(feature = "unproven")] pub mod pwm; -#[cfg(feature = "unproven")] pub mod watchdog; #[cfg(feature = "usb")] diff --git a/hal/src/thumbv6m/pwm.rs b/hal/src/thumbv6m/pwm.rs index e593d9824f94..88e4a31dfba5 100644 --- a/hal/src/thumbv6m/pwm.rs +++ b/hal/src/thumbv6m/pwm.rs @@ -97,6 +97,7 @@ impl $TYPE { } } +#[cfg(feature = "unproven")] impl PwmPin for $TYPE { type Duty = u16; @@ -213,6 +214,7 @@ impl $TYPE { } } +#[cfg(feature = "unproven")] impl Pwm for $TYPE { type Channel = Channel; type Time = Hertz; diff --git a/hal/src/thumbv6m/watchdog.rs b/hal/src/thumbv6m/watchdog.rs index 38718171b3cf..5d9515542aa1 100644 --- a/hal/src/thumbv6m/watchdog.rs +++ b/hal/src/thumbv6m/watchdog.rs @@ -30,6 +30,7 @@ impl Watchdog { } } +#[cfg(feature = "unproven")] impl watchdog::Watchdog for Watchdog { /// Feeds an existing watchdog to ensure the processor isn't reset. /// Sometimes commonly referred to as "kicking" or "refreshing". @@ -39,6 +40,7 @@ impl watchdog::Watchdog for Watchdog { } /// Disables a running watchdog timer so the processor won't be reset. +#[cfg(feature = "unproven")] impl watchdog::WatchdogDisable for Watchdog { fn disable(&mut self) { // Disable the watchdog timer. @@ -48,6 +50,7 @@ impl watchdog::WatchdogDisable for Watchdog { } } +#[cfg(feature = "unproven")] impl watchdog::WatchdogEnable for Watchdog { type Time = u8; diff --git a/hal/src/thumbv7em/adc.rs b/hal/src/thumbv7em/adc.rs index dd97e7a797b2..9eabb536b272 100644 --- a/hal/src/thumbv7em/adc.rs +++ b/hal/src/thumbv7em/adc.rs @@ -247,6 +247,7 @@ impl From> for InterruptAdc<$ADC, C> } } +#[cfg(feature = "unproven")] impl OneShot<$ADC, WORD, PIN> for Adc<$ADC> where WORD: From, @@ -288,6 +289,7 @@ macro_rules! adc_pins { /// Implement [`Channel`] for [`v1::Pin`]s based on the implementations for /// `v2` [`Pin`]s +#[cfg(feature = "unproven")] impl Channel for v1::Pin where I: PinId, diff --git a/hal/src/thumbv7em/mod.rs b/hal/src/thumbv7em/mod.rs index 7bfd577cfcb2..474b1741e698 100644 --- a/hal/src/thumbv7em/mod.rs +++ b/hal/src/thumbv7em/mod.rs @@ -15,11 +15,6 @@ pub use reset_cause::*; mod serial_number; pub use serial_number::*; -#[cfg(feature = "unproven")] pub mod adc; - -#[cfg(feature = "unproven")] pub mod pwm; - -#[cfg(feature = "unproven")] pub mod watchdog; diff --git a/hal/src/thumbv7em/pwm.rs b/hal/src/thumbv7em/pwm.rs index 4b4857187340..1efe39409739 100644 --- a/hal/src/thumbv7em/pwm.rs +++ b/hal/src/thumbv7em/pwm.rs @@ -166,6 +166,7 @@ impl $TYPE { } } +#[cfg(feature = "unproven")] impl PwmPin for $TYPE { type Duty = u16; @@ -486,6 +487,7 @@ impl $TYPE { } } +#[cfg(feature = "unproven")] impl Pwm for $TYPE { type Channel = Channel; type Time = Hertz; diff --git a/hal/src/thumbv7em/watchdog.rs b/hal/src/thumbv7em/watchdog.rs index 485b7fc62685..21cbec5c8f4b 100644 --- a/hal/src/thumbv7em/watchdog.rs +++ b/hal/src/thumbv7em/watchdog.rs @@ -30,6 +30,7 @@ impl Watchdog { } } +#[cfg(feature = "unproven")] impl watchdog::Watchdog for Watchdog { /// Feeds an existing watchdog to ensure the processor isn't reset. /// Sometimes commonly referred to as "kicking" or "refreshing". @@ -39,6 +40,7 @@ impl watchdog::Watchdog for Watchdog { } /// Disables a running watchdog timer so the processor won't be reset. +#[cfg(feature = "unproven")] impl watchdog::WatchdogDisable for Watchdog { fn disable(&mut self) { // Disable the watchdog timer. @@ -48,6 +50,7 @@ impl watchdog::WatchdogDisable for Watchdog { } } +#[cfg(feature = "unproven")] impl watchdog::WatchdogEnable for Watchdog { type Time = u8; From 1be02853a76586014be28bc5b7e72a45d691029b Mon Sep 17 00:00:00 2001 From: Sympatron <35803463+Sympatron@users.noreply.github.com> Date: Thu, 24 Jun 2021 12:10:02 +0200 Subject: [PATCH 2/2] Made thumbv7 Watchdog trait impls wrappers around common API --- hal/src/thumbv7em/watchdog.rs | 54 ++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/hal/src/thumbv7em/watchdog.rs b/hal/src/thumbv7em/watchdog.rs index 21cbec5c8f4b..a984d3547edb 100644 --- a/hal/src/thumbv7em/watchdog.rs +++ b/hal/src/thumbv7em/watchdog.rs @@ -30,23 +30,56 @@ impl Watchdog { } } +fn feed(&mut wdt: WDT) { + wdt.clear.write(|w| unsafe { w.clear().bits(0xA5) }); +} +fn disable(&mut wdt: WDT) { + // Disable the watchdog timer. + wdt.ctrla.write(|w| w.enable().clear_bit()); + // Wait for watchdog timer to be disabled. + while wdt.syncbusy.read().enable().bit_is_set() {} +} +fn start>(&mut wdt: WDT, period: T) { + // Write the timeout configuration. + wdt.config.write(|w| unsafe { w.per().bits(period.into()) }); + // Enable the watchdog timer. + wdt.ctrla.write(|w| w.enable().set_bit()); + // Wait for watchdog timer to be enabled. + while wdt.syncbusy.read().enable().bit_is_set() {} +} + +#[cfg(not(feature = "unproven"))] +impl Watchdog { + /// Feeds an existing watchdog to ensure the processor isn't reset. + /// Sometimes commonly referred to as "kicking" or "refreshing". + fn feed(&mut self) { + feed(&mut self.wdt); + } + /// Disables a running watchdog timer so the processor won't be reset. + fn disable(&mut self) { + disable(&mut self.wdt); + } + /// Enables a watchdog timer to reset the processor if software is frozen + /// or stalled. + fn start>(&mut self, period: T) { + start(&mut self.wdt, period); + } +} + #[cfg(feature = "unproven")] impl watchdog::Watchdog for Watchdog { /// Feeds an existing watchdog to ensure the processor isn't reset. /// Sometimes commonly referred to as "kicking" or "refreshing". fn feed(&mut self) { - self.wdt.clear.write(|w| unsafe { w.clear().bits(0xA5) }); + feed(&mut self.wdt); } } -/// Disables a running watchdog timer so the processor won't be reset. #[cfg(feature = "unproven")] impl watchdog::WatchdogDisable for Watchdog { + /// Disables a running watchdog timer so the processor won't be reset. fn disable(&mut self) { - // Disable the watchdog timer. - self.wdt.ctrla.write(|w| w.enable().clear_bit()); - // Wait for watchdog timer to be disabled. - while self.wdt.syncbusy.read().enable().bit_is_set() {} + disable(&mut self.wdt); } } @@ -60,13 +93,6 @@ impl watchdog::WatchdogEnable for Watchdog { where T: Into, { - // Write the timeout configuration. - self.wdt - .config - .write(|w| unsafe { w.per().bits(period.into()) }); - // Enable the watchdog timer. - self.wdt.ctrla.write(|w| w.enable().set_bit()); - // Wait for watchdog timer to be enabled. - while self.wdt.syncbusy.read().enable().bit_is_set() {} + start(&mut self.wdt, period); } }