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

Moved unproven feature gates to trait impl blocks #460

Closed
wants to merge 2 commits into from
Closed
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 hal/src/thumbv6m/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl Adc<ADC> {
}
}

#[cfg(feature = "unproven")]
impl<WORD, PIN> OneShot<ADC, WORD, PIN> for Adc<ADC>
where
WORD: From<u16>,
Expand Down Expand Up @@ -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<I> Channel<ADC> for v1::Pin<I, v1::PfB>
where
I: PinId,
Expand Down
3 changes: 0 additions & 3 deletions hal/src/thumbv6m/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions hal/src/thumbv6m/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl $TYPE {
}
}

#[cfg(feature = "unproven")]
impl PwmPin for $TYPE {
type Duty = u16;

Expand Down Expand Up @@ -213,6 +214,7 @@ impl $TYPE {
}
}

#[cfg(feature = "unproven")]
impl Pwm for $TYPE {
type Channel = Channel;
type Time = Hertz;
Expand Down
3 changes: 3 additions & 0 deletions hal/src/thumbv6m/watchdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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.
Expand All @@ -48,6 +50,7 @@ impl watchdog::WatchdogDisable for Watchdog {
}
}

#[cfg(feature = "unproven")]
impl watchdog::WatchdogEnable for Watchdog {
type Time = u8;

Expand Down
2 changes: 2 additions & 0 deletions hal/src/thumbv7em/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ impl<C> From<Adc<$ADC>> for InterruptAdc<$ADC, C>
}
}

#[cfg(feature = "unproven")]
impl<WORD, PIN> OneShot<$ADC, WORD, PIN> for Adc<$ADC>
where
WORD: From<u16>,
Expand Down Expand Up @@ -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<I, A> Channel<A> for v1::Pin<I, v1::PfB>
where
I: PinId,
Expand Down
5 changes: 0 additions & 5 deletions hal/src/thumbv7em/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 2 additions & 0 deletions hal/src/thumbv7em/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ impl<I: PinId> $TYPE<I> {
}
}

#[cfg(feature = "unproven")]
impl<I: PinId> PwmPin for $TYPE<I> {
type Duty = u16;

Expand Down Expand Up @@ -486,6 +487,7 @@ impl<I: PinId, M: PinMode> $TYPE<I, M> {
}
}

#[cfg(feature = "unproven")]
impl<I: PinId, M: PinMode> Pwm for $TYPE<I, M> {
type Channel = Channel;
type Time = Hertz;
Expand Down
57 changes: 43 additions & 14 deletions hal/src/thumbv7em/watchdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,60 @@ impl Watchdog {
}
}

fn feed(&mut wdt: WDT) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be the way to go, until e-h traits aren't "unproven" anymore. But I am open for suggestions/better options.

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<T: Into<u8>>(&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<T: Into<u8>>(&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);
}
}

#[cfg(feature = "unproven")]
impl watchdog::WatchdogEnable for Watchdog {
type Time = u8;

Expand All @@ -57,13 +93,6 @@ impl watchdog::WatchdogEnable for Watchdog {
where
T: Into<Self::Time>,
{
// 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);
}
}