diff --git a/esp-hal-common/src/embassy/time_driver_systimer.rs b/esp-hal-common/src/embassy/time_driver_systimer.rs index 56c528196c5..616ce8779a2 100644 --- a/esp-hal-common/src/embassy/time_driver_systimer.rs +++ b/esp-hal-common/src/embassy/time_driver_systimer.rs @@ -9,7 +9,7 @@ use crate::{ pub const ALARM_COUNT: usize = 3; -pub type TimerType = SystemTimer; +pub type TimerType = SystemTimer<'static>; pub struct EmbassyTimer { pub(crate) alarms: Mutex<[AlarmState; ALARM_COUNT]>, diff --git a/esp-hal-common/src/peripherals/esp32c2.rs b/esp-hal-common/src/peripherals/esp32c2.rs index b468890129b..b67329b2cd6 100644 --- a/esp-hal-common/src/peripherals/esp32c2.rs +++ b/esp-hal-common/src/peripherals/esp32c2.rs @@ -39,5 +39,6 @@ mod peripherals { SPI0, SPI1, SPI2, + SYSTIMER, } } diff --git a/esp-hal-common/src/peripherals/esp32c3.rs b/esp-hal-common/src/peripherals/esp32c3.rs index b6b69b2b645..0d41129d242 100644 --- a/esp-hal-common/src/peripherals/esp32c3.rs +++ b/esp-hal-common/src/peripherals/esp32c3.rs @@ -50,5 +50,6 @@ mod peripherals { SPI0, SPI1, SPI2, + SYSTIMER, } } diff --git a/esp-hal-common/src/peripherals/esp32s2.rs b/esp-hal-common/src/peripherals/esp32s2.rs index 029b57db8db..e4b224d0d06 100644 --- a/esp-hal-common/src/peripherals/esp32s2.rs +++ b/esp-hal-common/src/peripherals/esp32s2.rs @@ -57,5 +57,6 @@ mod peripherals { SPI2, SPI3, SPI4, + SYSTIMER, } } diff --git a/esp-hal-common/src/peripherals/esp32s3.rs b/esp-hal-common/src/peripherals/esp32s3.rs index 4f7373f987b..3c312ba6b3c 100644 --- a/esp-hal-common/src/peripherals/esp32s3.rs +++ b/esp-hal-common/src/peripherals/esp32s3.rs @@ -68,5 +68,6 @@ mod peripherals { SPI1, SPI2, SPI3, + SYSTIMER, } } diff --git a/esp-hal-common/src/systimer.rs b/esp-hal-common/src/systimer.rs index b1ad9d01dc1..c310b13800a 100644 --- a/esp-hal-common/src/systimer.rs +++ b/esp-hal-common/src/systimer.rs @@ -2,27 +2,29 @@ use core::{intrinsics::transmute, marker::PhantomData}; use fugit::MillisDurationU32; -use crate::pac::{ - generic::Reg, - systimer::{ - target0_conf::TARGET0_CONF_SPEC, - target0_hi::TARGET0_HI_SPEC, - target0_lo::TARGET0_LO_SPEC, +use crate::{ + pac::{ + generic::Reg, + systimer::{ + target0_conf::TARGET0_CONF_SPEC, + target0_hi::TARGET0_HI_SPEC, + target0_lo::TARGET0_LO_SPEC, + }, }, - SYSTIMER, + peripheral::{Peripheral, PeripheralRef}, + peripherals::SYSTIMER, }; // TODO this only handles unit0 of the systimer -#[derive(Debug)] -pub struct SystemTimer { - _inner: SYSTIMER, +pub struct SystemTimer<'d> { + _inner: PeripheralRef<'d, SYSTIMER>, pub alarm0: Alarm, pub alarm1: Alarm, pub alarm2: Alarm, } -impl SystemTimer { +impl<'d> SystemTimer<'d> { #[cfg(esp32s2)] pub const BIT_MASK: u64 = u64::MAX; #[cfg(any(esp32c2, esp32c3, esp32s3))] @@ -33,7 +35,8 @@ impl SystemTimer { #[cfg(any(esp32c2, esp32c3, esp32s3))] pub const TICKS_PER_SECOND: u64 = 16_000_000; - pub fn new(p: SYSTIMER) -> Self { + pub fn new(p: impl Peripheral

+ 'd) -> Self { + crate::into_ref!(p); Self { _inner: p, alarm0: Alarm::new(),