Skip to content

Commit

Permalink
[1/3] Timer abstraction: refactor systimer and timer modules into…
Browse files Browse the repository at this point in the history
… a common `timer` module (#1527)

* Refactor `systimer` and `timer` modules into a common `timer` module

* Update `CHANGELOG.md`

* Rebase and update new example
  • Loading branch information
jessebraham authored May 2, 2024
1 parent fd1c7b4 commit 68a4fb2
Show file tree
Hide file tree
Showing 46 changed files with 55 additions and 50 deletions.
4 changes: 3 additions & 1 deletion esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Updated example on i2c to use the new `interrupt_handler` parameter (#1376)

### Added

- i2c: implement `I2C:transaction` for `embedded-hal` and `embedded-hal-async`
- i2c: implement `I2C:transaction` for `embedded-hal` and `embedded-hal-async`
- ESP32-PICO-V3-02: Initial support (#1155)
- `time::current_time` API (#1503)
- ESP32-S3: Add LCD_CAM Camera driver (#1483)
Expand All @@ -30,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- RNG is no longer TRNG, the `CryptoRng` implementation has been removed. To track this being re-added see #1499 (#1498)
- Make software interrupts shareable (#1500)
- The `SystemParts` struct has been renamed to `SystemControl`, and now has a constructor which takes the `SYSTEM` peripheral (#1495)
- Timer abstraction: refactor `systimer` and `timer` modules into a common `timer` module (#1527)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl embedded_hal::delay::DelayNs for Delay {
#[cfg(riscv)]
mod implementation {
use super::*;
use crate::{clock::Clocks, systimer::SystemTimer};
use crate::{clock::Clocks, timer::systimer::SystemTimer};

impl Delay {
/// Create a new `Delay` instance
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/embassy/time_driver_systimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::AlarmState;
use crate::{
clock::Clocks,
peripherals,
systimer::{Alarm, SystemTimer, Target},
timer::systimer::{Alarm, SystemTimer, Target},
};

pub const ALARM_COUNT: usize = 3;
Expand Down
4 changes: 2 additions & 2 deletions esp-hal/src/embassy/time_driver_timg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use peripherals::TIMG0;

use super::AlarmState;
#[cfg(any(esp32, esp32s2, esp32s3))]
use crate::timer::Timer1;
use crate::timer::timg::Timer1;
use crate::{
clock::Clocks,
peripherals,
prelude::*,
timer::{Instance, Timer0, TimerGroup},
timer::timg::{Instance, Timer0, TimerGroup},
};

#[cfg(not(any(esp32, esp32s2, esp32s3)))]
Expand Down
4 changes: 1 addition & 3 deletions esp-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,8 @@ pub mod sha;
pub mod spi;
#[cfg(any(dport, hp_sys, pcr, system))]
pub mod system;
#[cfg(systimer)]
pub mod systimer;
pub mod time;
#[cfg(any(timg0, timg1))]
#[cfg(any(systimer, timg0, timg1))]
pub mod timer;
#[cfg(trace0)]
pub mod trace;
Expand Down
6 changes: 3 additions & 3 deletions esp-hal/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ pub use crate::ledc::{
timer::{TimerHW as _esp_hal_ledc_timer_TimerHW, TimerIFace as _esp_hal_ledc_timer_TimerIFace},
};
#[cfg(any(timg0, timg1))]
pub use crate::timer::{
Instance as _esp_hal_timer_Instance,
TimerGroupInstance as _esp_hal_timer_TimerGroupInstance,
pub use crate::timer::timg::{
Instance as _esp_hal_timer_timg_Instance,
TimerGroupInstance as _esp_hal_timer_timg_TimerGroupInstance,
};
#[cfg(any(uart0, uart1, uart2))]
pub use crate::uart::{Instance as _esp_hal_uart_Instance, UartPins as _esp_hal_uart_UartPins};
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/soc/esp32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use core::ptr::addr_of_mut;

use self::peripherals::{LPWR, TIMG0, TIMG1};
use crate::{rtc_cntl::Rtc, timer::Wdt};
use crate::{rtc_cntl::Rtc, timer::timg::Wdt};

pub mod cpu_control;
pub mod efuse;
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/soc/esp32c2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! for interacting with various system-related peripherals on `ESP32-C2` chip.

use self::peripherals::{LPWR, TIMG0};
use crate::{rtc_cntl::Rtc, timer::Wdt};
use crate::{rtc_cntl::Rtc, timer::timg::Wdt};

pub mod efuse;
pub mod gpio;
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/soc/esp32c3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! * I2S_DEFAULT_CLK_SRC: 2 - I2S clock source

use self::peripherals::{LPWR, TIMG0, TIMG1};
use crate::{rtc_cntl::Rtc, timer::Wdt};
use crate::{rtc_cntl::Rtc, timer::timg::Wdt};

pub mod efuse;
pub mod gpio;
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/soc/esp32c6/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! * I2S_SCLK: 160_000_000 - I2S clock frequency

use self::peripherals::{LPWR, TIMG0, TIMG1};
use crate::{rtc_cntl::Rtc, timer::Wdt};
use crate::{rtc_cntl::Rtc, timer::timg::Wdt};

pub mod efuse;
pub mod gpio;
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/soc/esp32h2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! * I2S_SCLK: 96_000_000 - I2S clock frequency

use self::peripherals::{LPWR, TIMG0, TIMG1};
use crate::{rtc_cntl::Rtc, timer::Wdt};
use crate::{rtc_cntl::Rtc, timer::timg::Wdt};

pub mod efuse;
pub mod gpio;
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/soc/esp32s2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use core::ptr::addr_of_mut;

use self::peripherals::{LPWR, TIMG0, TIMG1};
use crate::{rtc_cntl::Rtc, timer::Wdt};
use crate::{rtc_cntl::Rtc, timer::timg::Wdt};

pub mod efuse;
pub mod gpio;
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/soc/esp32s3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use core::ptr::addr_of_mut;

use self::peripherals::{LPWR, TIMG0, TIMG1};
use crate::{rtc_cntl::Rtc, timer::Wdt};
use crate::{rtc_cntl::Rtc, timer::timg::Wdt};

pub mod cpu_control;
pub mod efuse;
Expand Down
4 changes: 2 additions & 2 deletions esp-hal/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ pub fn current_time() -> fugit::Instant<u64, 1, 1_000_000> {
#[cfg(not(esp32))]
let (ticks, div) = {
// otherwise use SYSTIMER
let ticks = crate::systimer::SystemTimer::now();
let ticks = crate::timer::systimer::SystemTimer::now();
(
ticks,
(crate::systimer::SystemTimer::TICKS_PER_SECOND / 1_000_000),
(crate::timer::systimer::SystemTimer::TICKS_PER_SECOND / 1_000_000),
)
};

Expand Down
6 changes: 6 additions & 0 deletions esp-hal/src/timer/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! General-purpose timers.

#[cfg(systimer)]
pub mod systimer;
#[cfg(any(timg0, timg1))]
pub mod timg;
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/src/bin/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
rng::Rng,
systimer::SystemTimer,
timer::systimer::SystemTimer,
};
use esp_println::{print, println};
use hex_literal::hex;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};

#[embassy_executor::task]
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_hello_world_systimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
systimer::SystemTimer,
timer::systimer::SystemTimer,
};

#[embassy_executor::task]
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use lis3dh_async::{Lis3dh, Range, SlaveAddr};

Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_i2c_bmp180_calibration_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};

#[main]
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_i2s_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;

Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_i2s_sound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;

Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_multicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;
use static_cell::make_static;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_multicore_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;
use static_cell::make_static;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_multiprio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;
use static_cell::make_static;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_parl_io_rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;

Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_parl_io_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;

Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_rmt_rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn main(spawner: Spawner) {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let timer_group0 = esp_hal::timer::TimerGroup::new_async(peripherals.TIMG0, &clocks);
let timer_group0 = esp_hal::timer::timg::TimerGroup::new_async(peripherals.TIMG0, &clocks);
embassy::init(&clocks, timer_group0);

let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_rmt_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use esp_hal::{
prelude::*,
rmt::{asynch::TxChannelAsync, PulseCode, Rmt, TxChannelConfig, TxChannelCreatorAsync},
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;

Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use esp_hal::{
peripherals::{Peripherals, UART0},
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
uart::{config::AtCmdConfig, Uart, UartRx, UartTx},
Async,
};
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use esp_hal::{
SpiMode,
},
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};

#[main]
Expand Down
3 changes: 1 addition & 2 deletions examples/src/bin/embassy_systimer_delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
systimer::SystemTimer,
timer::TimerGroup,
timer::{systimer::SystemTimer, timg::TimerGroup},
};

#[main]
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_twai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use esp_hal::{
peripherals::{self, Peripherals, TWAI0},
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
twai::{self, EspTwaiFrame, TwaiRx, TwaiTx},
};
use esp_println::println;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_usb_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};

#[main]
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_usb_serial_jtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
usb_serial_jtag::{UsbSerialJtag, UsbSerialJtagRx, UsbSerialJtagTx},
Async,
};
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};

#[main]
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/etm_blinky_systimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use esp_hal::{
gpio::{etm::GpioEtmChannels, Io},
peripherals::Peripherals,
prelude::*,
systimer::{etm::SysTimerEtmEvent, SystemTimer},
timer::systimer::{etm::SysTimerEtmEvent, SystemTimer},
};
use fugit::ExtU32;

Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/etm_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use esp_hal::{
peripherals::{Peripherals, TIMG0},
prelude::*,
system::SystemControl,
timer::{
timer::timg::{
etm::{TimerEtmEvents, TimerEtmTasks},
Timer,
Timer0,
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use esp_hal::{
prelude::*,
rng::Rng,
system::SystemControl,
systimer::SystemTimer,
timer::systimer::SystemTimer,
};
use esp_println::println;
use hmac::{Hmac as HmacSw, Mac};
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/systimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use esp_hal::{
peripherals::{Interrupt, Peripherals},
prelude::*,
system::SystemControl,
systimer::{Alarm, Periodic, SystemTimer, Target},
timer::systimer::{Alarm, Periodic, SystemTimer, Target},
Blocking,
};
use esp_println::println;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/timer_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use esp_hal::{
peripherals::{Interrupt, Peripherals, TIMG0},
prelude::*,
system::SystemControl,
timer::{Timer, Timer0, TimerGroup, TimerInterrupts},
timer::timg::{Timer, Timer0, TimerGroup, TimerInterrupts},
};

static TIMER0: Mutex<RefCell<Option<Timer<Timer0<TIMG0>, esp_hal::Blocking>>>> =
Expand Down
Loading

0 comments on commit 68a4fb2

Please sign in to comment.