From e4a722dd629985f14efc5609b4579ef2cc0bae80 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Fri, 5 Jul 2024 11:11:17 +0000 Subject: [PATCH] Base CountDown on Timer instead of &Timer This allows to remove the lifetime parameter from CountDown. As Timer is zero-sized, this should also reduce the size of CountDown. Due to the removal of the lifetime parameter, this is a breaking change. Closes #216 --- rp2040-hal/src/timer.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rp2040-hal/src/timer.rs b/rp2040-hal/src/timer.rs index 23dabce58..b9b49f03c 100644 --- a/rp2040-hal/src/timer.rs +++ b/rp2040-hal/src/timer.rs @@ -88,9 +88,9 @@ impl Timer { } /// Initialized a Count Down instance without starting it. - pub fn count_down(&self) -> CountDown<'_> { + pub fn count_down(&self) -> CountDown { CountDown { - timer: self, + timer: *self, period: MicrosDurationU64::nanos(0), next_end: None, } @@ -213,13 +213,13 @@ impl embedded_hal::delay::DelayNs for Timer { /// // Cancel it immediately /// count_down.cancel(); /// ``` -pub struct CountDown<'timer> { - timer: &'timer Timer, +pub struct CountDown { + timer: Timer, period: MicrosDurationU64, next_end: Option, } -impl embedded_hal_0_2::timer::CountDown for CountDown<'_> { +impl embedded_hal_0_2::timer::CountDown for CountDown { type Time = MicrosDurationU64; fn start(&mut self, count: T) @@ -250,9 +250,9 @@ impl embedded_hal_0_2::timer::CountDown for CountDown<'_> { } } -impl embedded_hal_0_2::timer::Periodic for CountDown<'_> {} +impl embedded_hal_0_2::timer::Periodic for CountDown {} -impl embedded_hal_0_2::timer::Cancel for CountDown<'_> { +impl embedded_hal_0_2::timer::Cancel for CountDown { type Error = &'static str; fn cancel(&mut self) -> Result<(), Self::Error> {