Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1/3] Timer refactor: system timer #2576

Merged
merged 6 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions esp-hal-embassy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ where
}

#[cfg(not(feature = "esp32"))]
impl<T, DM, COMP, UNIT> IntoAnyTimer for Alarm<'_, T, DM, COMP, UNIT>
where
DM: esp_hal::Mode,
Self: Into<AnyTimer>,
{
}
impl IntoAnyTimer for Alarm where Self: Into<AnyTimer> {}

impl<T> TimerCollection for T
where
Expand Down
10 changes: 10 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- DMA channel objects now implement `Peripheral` (#2526)
- DMA channel objects are no longer wrapped in `Channel`. The `Channel` drivers are now managed by DMA enabled peripheral drivers. (#2526)
- The `Dpi` driver and `DpiTransfer` now have a `Mode` type parameter. The driver's asyncness is determined by the asyncness of the `Lcd` used to create it. (#2526)
- `dma::{Channel, ChannelRx, ChannelTx}::set_priority` for GDMA devices (#2403)
- `SystemTimer::set_unit_count` & `SystemTimer::configure_unit` (#2576)
- `SystemTimer::set_unit_value` & `SystemTimer::configure_unit` (#2576)

### Changed

- `SystemTimer` no longer uses peripheral ref (#2576)
- `SystemTimer::now` has been renamed `SystemTimer::unit_value(Unit)` (#2576)

### Fixed

### Removed

- The `configure` and `configure_for_async` DMA channel functions has been removed (#2403)
- The DMA channel objects no longer have `tx` and `rx` fields. (#2526)
- `SysTimerAlarms` has been removed, alarms are now part of the `SystemTimer` struct (#2576)
- `FrozenUnit`, `AnyUnit`, `SpecificUnit`, `SpecificComparator`, `AnyComparator` have been removed from `systimer` (#2576)

## [0.22.0] - 2024-11-20

Expand Down
18 changes: 18 additions & 0 deletions esp-hal/MIGRATING-0.22.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,21 @@
-.with_dma(dma_channel.configure(false, DmaPriority::Priority1));
+.with_dma(dma_channel);
```

## Timer changes

The low level timers, `SystemTimer` and `TimerGroup` are now "dumb". They contain no logic for operating modes or trait implementations (except the low level `Timer` trait).

### SystemTimer

```diff
let systimer = SystemTimer::new(peripherals.SYSTIMER);
- static UNIT0: StaticCell<SpecificUnit<'static, 0>> = StaticCell::new();
- let unit0 = UNIT0.init(systimer.unit0);
- let frozen_unit = FrozenUnit::new(unit0);
- let alarm0 = Alarm::new(systimer.comparator0, &frozen_unit);
- alarm0.set_period(1u32.secs());
+ let alarm0 = systimer.alarm0;
+ let mut timer = PeriodicTimer::new(alarm0);
+ timer.start(1u64.secs());
```
8 changes: 3 additions & 5 deletions esp-hal/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ pub fn now() -> Instant {

#[cfg(not(esp32))]
let (ticks, div) = {
use crate::timer::systimer::{SystemTimer, Unit};
// otherwise use SYSTIMER
let ticks = crate::timer::systimer::SystemTimer::now();
(
ticks,
(crate::timer::systimer::SystemTimer::ticks_per_second() / 1_000_000),
)
let ticks = SystemTimer::unit_value(Unit::Unit0);
(ticks, (SystemTimer::ticks_per_second() / 1_000_000))
};

Instant::from_ticks(ticks / div)
Expand Down
24 changes: 6 additions & 18 deletions esp-hal/src/timer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,9 @@ enum AnyTimerInner {
/// Timer 1 of the TIMG1 peripheral in blocking mode.
#[cfg(all(timg1, timg_timer1))]
Timg1Timer1(timg::Timer<timg::Timer1<crate::peripherals::TIMG1>, Blocking>),
/// Systimer Alarm in periodic mode with blocking behavior.
/// Systimer Alarm
#[cfg(systimer)]
SystimerAlarmPeriodic(systimer::Alarm<'static, systimer::Periodic, Blocking>),
/// Systimer Target in periodic mode with blocking behavior.
#[cfg(systimer)]
SystimerAlarmTarget(systimer::Alarm<'static, systimer::Target, Blocking>),
SystimerAlarm(systimer::Alarm),
}

/// A type-erased timer
Expand Down Expand Up @@ -413,16 +410,9 @@ impl From<timg::Timer<timg::Timer1<crate::peripherals::TIMG1>, Blocking>> for An
}

#[cfg(systimer)]
impl From<systimer::Alarm<'static, systimer::Periodic, Blocking>> for AnyTimer {
fn from(value: systimer::Alarm<'static, systimer::Periodic, Blocking>) -> Self {
Self(AnyTimerInner::SystimerAlarmPeriodic(value))
}
}

#[cfg(systimer)]
impl From<systimer::Alarm<'static, systimer::Target, Blocking>> for AnyTimer {
fn from(value: systimer::Alarm<'static, systimer::Target, Blocking>) -> Self {
Self(AnyTimerInner::SystimerAlarmTarget(value))
impl From<systimer::Alarm> for AnyTimer {
fn from(value: systimer::Alarm) -> Self {
Self(AnyTimerInner::SystimerAlarm(value))
}
}

Expand All @@ -437,9 +427,7 @@ impl Timer for AnyTimer {
#[cfg(all(timg1,timg_timer1))]
AnyTimerInner::Timg1Timer1(inner) => inner,
#[cfg(systimer)]
AnyTimerInner::SystimerAlarmPeriodic(inner) => inner,
#[cfg(systimer)]
AnyTimerInner::SystimerAlarmTarget(inner) => inner,
AnyTimerInner::SystimerAlarm(inner) => inner,
} {
fn start(&self);
fn stop(&self);
Expand Down
Loading