From e0db45736d42ca9b75f4702c9b66646742a50e44 Mon Sep 17 00:00:00 2001 From: Ashcon Mohseninia Date: Tue, 10 Dec 2024 08:13:35 +0100 Subject: [PATCH 1/4] Allow delay to be constructed with source (Clock V2) --- hal/src/delay.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hal/src/delay.rs b/hal/src/delay.rs index b683a97c8da..0ba8b4ac458 100644 --- a/hal/src/delay.rs +++ b/hal/src/delay.rs @@ -7,6 +7,8 @@ use crate::clock::GenericClockController; use crate::ehal::delay::DelayNs; use crate::ehal_02; use crate::time::Hertz; +use crate::typelevel::Increment; +use crate::clock::v2::Source; /// System timer (SysTick) as a delay provider pub struct Delay { @@ -25,6 +27,18 @@ impl Delay { } } + pub fn new_with_source(mut syst: SYST, source: S) -> (Self, S::Inc) + where S: Source + Increment { + syst.set_clock_source(SystClkSource::Core); + ( + Delay { + syst, + sysclock: source.freq(), + }, + source.inc() + ) + } + /// Releases the system timer (SysTick) resource pub fn free(self) -> SYST { self.syst From 29168c7dd05da67c1a803633221f4d15703449d1 Mon Sep 17 00:00:00 2001 From: Ashcon Mohseninia Date: Tue, 10 Dec 2024 08:31:48 +0100 Subject: [PATCH 2/4] Fix compile tests and restrict source to Gclk0 --- hal/src/delay.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/hal/src/delay.rs b/hal/src/delay.rs index 0ba8b4ac458..cfc423bcf12 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,7 +9,11 @@ use crate::ehal::delay::DelayNs; use crate::ehal_02; use crate::time::Hertz; use crate::typelevel::Increment; -use crate::clock::v2::Source; + +#[hal_cfg("rtc-d5x")] +use crate::clock::v2::{ + Source, gclk::Gclk0Id +}; /// System timer (SysTick) as a delay provider pub struct Delay { @@ -27,15 +32,18 @@ impl Delay { } } - pub fn new_with_source(mut syst: SYST, source: S) -> (Self, S::Inc) - where S: Source + Increment { + #[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: source.freq(), + sysclock: gclk0.freq(), }, - source.inc() + gclk0.inc() ) } From d8056c162958a4cd7186068cdc2d74df4947a7ae Mon Sep 17 00:00:00 2001 From: Ashcon Mohseninia Date: Mon, 6 Jan 2025 09:13:09 +0000 Subject: [PATCH 3/4] Fix compile for sam51 --- hal/src/delay.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hal/src/delay.rs b/hal/src/delay.rs index cfc423bcf12..35591260280 100644 --- a/hal/src/delay.rs +++ b/hal/src/delay.rs @@ -8,6 +8,8 @@ use crate::clock::GenericClockController; 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")] From ca1e48659ca6541588b3b63329c28bc299da8f5d Mon Sep 17 00:00:00 2001 From: Ashcon Mohseninia Date: Mon, 6 Jan 2025 09:26:52 +0000 Subject: [PATCH 4/4] Cargo fmt --- hal/src/delay.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hal/src/delay.rs b/hal/src/delay.rs index 35591260280..e3bb65d6e32 100644 --- a/hal/src/delay.rs +++ b/hal/src/delay.rs @@ -13,9 +13,7 @@ use crate::time::Hertz; use crate::typelevel::Increment; #[hal_cfg("rtc-d5x")] -use crate::clock::v2::{ - Source, gclk::Gclk0Id -}; +use crate::clock::v2::{gclk::Gclk0Id, Source}; /// System timer (SysTick) as a delay provider pub struct Delay { @@ -38,14 +36,16 @@ impl Delay { /// 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 { + where + S: Source + Increment, + { syst.set_clock_source(SystClkSource::Core); ( Delay { syst, sysclock: gclk0.freq(), }, - gclk0.inc() + gclk0.inc(), ) }