diff --git a/boards/atsame54_xpro/examples/blinky_basic.rs b/boards/atsame54_xpro/examples/blinky_basic.rs index d18af5f4adb0..f0da8c4e9006 100644 --- a/boards/atsame54_xpro/examples/blinky_basic.rs +++ b/boards/atsame54_xpro/examples/blinky_basic.rs @@ -7,7 +7,7 @@ use bsp::hal; use panic_rtt_target as _; use rtt_target::{rprintln, rtt_init_print}; -use hal::clock::GenericClockController; +use hal::clock::v2::clock_system_at_reset; use hal::delay::Delay; use hal::pac::{CorePeripherals, Peripherals}; use hal::prelude::*; @@ -15,18 +15,18 @@ use hal::prelude::*; #[cortex_m_rt::entry] fn main() -> ! { rtt_init_print!(); + let mut peripherals = Peripherals::take().unwrap(); let core = CorePeripherals::take().unwrap(); - - let mut clocks = GenericClockController::with_external_32kosc( + let (mut _buses, clocks, _tokens) = clock_system_at_reset( + peripherals.oscctrl, + peripherals.osc32kctrl, peripherals.gclk, - &mut peripherals.mclk, - &mut peripherals.osc32kctrl, - &mut peripherals.oscctrl, + peripherals.mclk, &mut peripherals.nvmctrl, ); - let mut delay = Delay::new(core.SYST, &mut clocks); + let (mut delay, _gclk0) = Delay::new(core.SYST, clocks.gclk0); let pins = bsp::Pins::new(peripherals.port); let mut led = bsp::pin_alias!(pins.led).into_push_pull_output(); diff --git a/boards/feather_m4/examples/blinky_basic.rs b/boards/feather_m4/examples/blinky_basic.rs index de7ef38ba305..00e4bb5b8bf3 100644 --- a/boards/feather_m4/examples/blinky_basic.rs +++ b/boards/feather_m4/examples/blinky_basic.rs @@ -9,7 +9,7 @@ use panic_semihosting as _; use bsp::entry; use bsp::hal; -use hal::clock::GenericClockController; +use hal::clock::v2::clock_system_at_reset; use hal::delay::Delay; use hal::pac::{CorePeripherals, Peripherals}; use hal::prelude::*; @@ -18,16 +18,17 @@ use hal::prelude::*; fn main() -> ! { let mut peripherals = Peripherals::take().unwrap(); let core = CorePeripherals::take().unwrap(); - let mut clocks = GenericClockController::with_external_32kosc( + let (mut _buses, clocks, _tokens) = clock_system_at_reset( + peripherals.oscctrl, + peripherals.osc32kctrl, peripherals.gclk, - &mut peripherals.mclk, - &mut peripherals.osc32kctrl, - &mut peripherals.oscctrl, + peripherals.mclk, &mut peripherals.nvmctrl, ); + let pins = bsp::Pins::new(peripherals.port); let mut red_led = pins.d13.into_push_pull_output(); - let mut delay = Delay::new(core.SYST, &mut clocks); + let (mut delay, _gclk0) = Delay::new(core.SYST, clocks.gclk0); loop { delay.delay_ms(2000u16); red_led.set_high().unwrap(); diff --git a/boards/metro_m4/examples/blinky_basic.rs b/boards/metro_m4/examples/blinky_basic.rs index f54b500330cd..7eea2d29ead7 100644 --- a/boards/metro_m4/examples/blinky_basic.rs +++ b/boards/metro_m4/examples/blinky_basic.rs @@ -12,7 +12,7 @@ use panic_halt as _; use panic_semihosting as _; use bsp::entry; -use hal::clock::GenericClockController; +use hal::clock::v2::clock_system_at_reset; use hal::prelude::*; use pac::{CorePeripherals, Peripherals}; @@ -22,16 +22,17 @@ use hal::delay::Delay; fn main() -> ! { let mut peripherals = Peripherals::take().unwrap(); let core = CorePeripherals::take().unwrap(); - let mut clocks = GenericClockController::with_external_32kosc( + let (mut _buses, clocks, _tokens) = clock_system_at_reset( + peripherals.oscctrl, + peripherals.osc32kctrl, peripherals.gclk, - &mut peripherals.mclk, - &mut peripherals.osc32kctrl, - &mut peripherals.oscctrl, + peripherals.mclk, &mut peripherals.nvmctrl, ); + let pins = bsp::Pins::new(peripherals.port); let mut red_led = pins.d13.into_push_pull_output(); - let mut delay = Delay::new(core.SYST, &mut clocks); + let (mut delay, _gclk0) = Delay::new(core.SYST, clocks.gclk0); loop { delay.delay_ms(200u8); red_led.set_high().unwrap(); diff --git a/boards/pygamer/examples/blinky_basic.rs b/boards/pygamer/examples/blinky_basic.rs index 56c0409d825a..e43daf5f2eb1 100644 --- a/boards/pygamer/examples/blinky_basic.rs +++ b/boards/pygamer/examples/blinky_basic.rs @@ -8,7 +8,7 @@ use bsp::{entry, hal, pac, Pins, RedLed}; use panic_halt as _; use pygamer as bsp; -use hal::clock::GenericClockController; +use hal::clock::v2::clock_system_at_reset; use hal::delay::Delay; use hal::prelude::*; use hal::watchdog::{Watchdog, WatchdogTimeout}; @@ -18,14 +18,15 @@ use pac::{CorePeripherals, Peripherals}; fn main() -> ! { let mut peripherals = Peripherals::take().unwrap(); let core = CorePeripherals::take().unwrap(); - let mut clocks = GenericClockController::with_internal_32kosc( + let (mut _buses, clocks, _tokens) = clock_system_at_reset( + peripherals.oscctrl, + peripherals.osc32kctrl, peripherals.gclk, - &mut peripherals.mclk, - &mut peripherals.osc32kctrl, - &mut peripherals.oscctrl, + peripherals.mclk, &mut peripherals.nvmctrl, ); - let mut delay = Delay::new(core.SYST, &mut clocks); + + let (mut delay, _gclk0) = Delay::new(core.SYST, clocks.gclk0); delay.delay_ms(400u16); let pins = Pins::new(peripherals.port); diff --git a/hal/src/delay.rs b/hal/src/delay.rs index 3ea6aa60bc8a..483ccc5a535a 100644 --- a/hal/src/delay.rs +++ b/hal/src/delay.rs @@ -4,11 +4,15 @@ use atsamd_hal_macros::hal_cfg; use cortex_m::peripheral::SYST; use cortex_m::peripheral::syst::SystClkSource; +#[hal_cfg(any("rtc-d11", "rtc-d21"))] use crate::clock::GenericClockController; + use crate::ehal::delay::DelayNs; use crate::ehal_02; use crate::time::Hertz; +#[hal_cfg("rtc-d5x")] +use crate::typelevel::Decrement; #[hal_cfg("rtc-d5x")] use crate::typelevel::Increment; @@ -22,6 +26,7 @@ pub struct Delay { } impl Delay { + #[hal_cfg(any("rtc-d11", "rtc-d21"))] /// Configures the system timer (SysTick) as a delay provider pub fn new(mut syst: SYST, clocks: &mut GenericClockController) -> Self { syst.set_clock_source(SystClkSource::Core); @@ -32,10 +37,15 @@ impl Delay { } } + #[hal_cfg(any("rtc-d11", "rtc-d21"))] + /// Releases the system timer (SysTick) resource + pub fn free(self) -> SYST { + self.syst + } + #[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) + /// Configures the system timer (SysTick) as a delay provide. + pub fn new(mut syst: SYST, gclk0: S) -> (Self, S::Inc) where S: Source + Increment, { @@ -49,9 +59,13 @@ impl Delay { ) } + #[hal_cfg("rtc-d5x")] /// Releases the system timer (SysTick) resource - pub fn free(self) -> SYST { - self.syst + pub fn free(self, gclk0: S) -> (SYST, S::Dec) + where + S: Source + Decrement, + { + (self.syst, gclk0.dec()) } }