[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:
Jesse Braham 2024-05-02 13:27:33 +00:00 committed by GitHub
parent fd1c7b4fc7
commit 68a4fb29ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
46 changed files with 55 additions and 50 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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)))]

View File

@ -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;

View File

@ -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};

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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
View File

@ -0,0 +1,6 @@
//! General-purpose timers.
#[cfg(systimer)]
pub mod systimer;
#[cfg(any(timg0, timg1))]
pub mod timg;

View File

@ -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;

View File

@ -19,7 +19,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
#[embassy_executor::task]

View File

@ -21,7 +21,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
systimer::SystemTimer,
timer::systimer::SystemTimer,
};
#[embassy_executor::task]

View File

@ -28,7 +28,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use lis3dh_async::{Lis3dh, Range, SlaveAddr};

View File

@ -29,7 +29,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
#[main]

View File

@ -30,7 +30,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;

View File

@ -45,7 +45,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -23,7 +23,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;

View File

@ -34,7 +34,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;

View File

@ -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);

View File

@ -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;

View File

@ -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,
};

View File

@ -37,7 +37,7 @@ use esp_hal::{
SpiMode,
},
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
#[main]

View File

@ -18,8 +18,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
systimer::SystemTimer,
timer::TimerGroup,
timer::{systimer::SystemTimer, timg::TimerGroup},
};
#[main]

View File

@ -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;

View File

@ -27,7 +27,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
#[main]

View File

@ -18,7 +18,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
usb_serial_jtag::{UsbSerialJtag, UsbSerialJtagRx, UsbSerialJtagTx},
Async,
};

View File

@ -19,7 +19,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
#[main]

View File

@ -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;

View File

@ -17,7 +17,7 @@ use esp_hal::{
peripherals::{Peripherals, TIMG0},
prelude::*,
system::SystemControl,
timer::{
timer::timg::{
etm::{TimerEtmEvents, TimerEtmTasks},
Timer,
Timer0,

View File

@ -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};

View File

@ -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;

View File

@ -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>>>> =

View File

@ -15,7 +15,7 @@ use esp_hal::{
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::TimerGroup,
timer::timg::TimerGroup,
};
use esp_println::println;

View File

@ -8,6 +8,6 @@ pub fn cycles() -> u64 {
#[cfg(not(feature = "esp32"))]
{
esp_hal::systimer::SystemTimer::now()
esp_hal::timer::systimer::SystemTimer::now()
}
}

View File

@ -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));