diff --git a/hal/src/delay.rs b/hal/src/delay.rs index b683a97c8da..e3bb65d6e32 100644 --- a/hal/src/delay.rs +++ b/hal/src/delay.rs @@ -1,5 +1,6 @@ //! Delays +use atsamd_hal_macros::hal_cfg; use cortex_m::peripheral::syst::SystClkSource; use cortex_m::peripheral::SYST; @@ -8,6 +9,12 @@ use crate::ehal::delay::DelayNs; use crate::ehal_02; use crate::time::Hertz; +#[hal_cfg("rtc-d5x")] +use crate::typelevel::Increment; + +#[hal_cfg("rtc-d5x")] +use crate::clock::v2::{gclk::Gclk0Id, Source}; + /// System timer (SysTick) as a delay provider pub struct Delay { sysclock: Hertz, @@ -25,6 +32,23 @@ 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(mut syst: SYST, gclk0: S) -> (Self, S::Inc) + where + S: Source + 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