mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-27 04:10:28 +00:00
[1/3] Timer abstraction: refactor systimer
and timer
modules into a common timer
module (#1527)
* Refactor `systimer` and `timer` modules into a common `timer` module * Update `CHANGELOG.md` * Rebase and update new example
This commit is contained in:
parent
fd1c7b4fc7
commit
68a4fb29ed
@ -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)
|
||||
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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)))]
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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),
|
||||
)
|
||||
};
|
||||
|
||||
|
6
esp-hal/src/timer/mod.rs
Normal file
6
esp-hal/src/timer/mod.rs
Normal file
@ -0,0 +1,6 @@
|
||||
//! General-purpose timers.
|
||||
|
||||
#[cfg(systimer)]
|
||||
pub mod systimer;
|
||||
#[cfg(any(timg0, timg1))]
|
||||
pub mod timg;
|
@ -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;
|
||||
|
@ -19,7 +19,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
|
||||
#[embassy_executor::task]
|
||||
|
@ -21,7 +21,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
systimer::SystemTimer,
|
||||
timer::systimer::SystemTimer,
|
||||
};
|
||||
|
||||
#[embassy_executor::task]
|
||||
|
@ -28,7 +28,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use lis3dh_async::{Lis3dh, Range, SlaveAddr};
|
||||
|
||||
|
@ -29,7 +29,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
|
||||
#[main]
|
||||
|
@ -30,7 +30,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
|
@ -45,7 +45,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -23,7 +23,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
|
@ -34,7 +34,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -37,7 +37,7 @@ use esp_hal::{
|
||||
SpiMode,
|
||||
},
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
|
||||
#[main]
|
||||
|
@ -18,8 +18,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
systimer::SystemTimer,
|
||||
timer::TimerGroup,
|
||||
timer::{systimer::SystemTimer, timg::TimerGroup},
|
||||
};
|
||||
|
||||
#[main]
|
||||
|
@ -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;
|
||||
|
@ -27,7 +27,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
|
||||
#[main]
|
||||
|
@ -18,7 +18,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
usb_serial_jtag::{UsbSerialJtag, UsbSerialJtagRx, UsbSerialJtagTx},
|
||||
Async,
|
||||
};
|
||||
|
@ -19,7 +19,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
|
||||
#[main]
|
||||
|
@ -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;
|
||||
|
||||
|
@ -17,7 +17,7 @@ use esp_hal::{
|
||||
peripherals::{Peripherals, TIMG0},
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::{
|
||||
timer::timg::{
|
||||
etm::{TimerEtmEvents, TimerEtmTasks},
|
||||
Timer,
|
||||
Timer0,
|
||||
|
@ -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};
|
||||
|
@ -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;
|
||||
|
@ -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>>>> =
|
||||
|
@ -15,7 +15,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
|
@ -8,6 +8,6 @@ pub fn cycles() -> u64 {
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
{
|
||||
esp_hal::systimer::SystemTimer::now()
|
||||
esp_hal::timer::systimer::SystemTimer::now()
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ use esp_hal::{
|
||||
macros::handler,
|
||||
peripherals::Peripherals,
|
||||
system::SystemControl,
|
||||
timer::TimerGroup,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
|
||||
static COUNTER: Mutex<RefCell<u32>> = Mutex::new(RefCell::new(0));
|
||||
|
Loading…
x
Reference in New Issue
Block a user