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

Allow the construction of Delay using the clock::v2 API #803

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions hal/src/delay.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
//! Delays

use atsamd_hal_macros::hal_cfg;
use cortex_m::peripheral::syst::SystClkSource;
use cortex_m::peripheral::SYST;

use crate::clock::GenericClockController;
use crate::ehal::delay::DelayNs;
use crate::ehal_02;
use crate::time::Hertz;
use crate::typelevel::Increment;

#[hal_cfg("rtc-d5x")]
use crate::clock::v2::{
Source, gclk::Gclk0Id
};

/// System timer (SysTick) as a delay provider
pub struct Delay {
Expand All @@ -25,6 +32,21 @@ impl Delay {
}
}

#[hal_cfg("rtc-d5x")]
/// Configures the system timer (SysTick) as a delay provide, compatible
/// with the V2 clocking API
pub fn new_with_source<S>(mut syst: SYST, gclk0: S) -> (Self, S::Inc)
where S: Source<Id = Gclk0Id> + Increment {
syst.set_clock_source(SystClkSource::Core);
(
Delay {
syst,
sysclock: gclk0.freq(),
},
gclk0.inc()
)
}

/// Releases the system timer (SysTick) resource
pub fn free(self) -> SYST {
self.syst
Expand Down
Loading