diff --git a/esp-hal-embassy/CHANGELOG.md b/esp-hal-embassy/CHANGELOG.md index 11dc227c643..8f458e15771 100644 --- a/esp-hal-embassy/CHANGELOG.md +++ b/esp-hal-embassy/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Updated to latest release (`0.6.0`) for `embassy-executor` (#1942) +- Changed `init` to accept timers of multiple types (#1957) ### Fixed diff --git a/esp-hal-embassy/Cargo.toml b/esp-hal-embassy/Cargo.toml index ff5bc8d0305..83ceebff460 100644 --- a/esp-hal-embassy/Cargo.toml +++ b/esp-hal-embassy/Cargo.toml @@ -21,6 +21,7 @@ esp-hal = { version = "0.19.0", path = "../esp-hal" } log = { version = "0.4.22", optional = true } macros = { version = "0.12.0", features = ["embassy"], package = "esp-hal-procmacros", path = "../esp-hal-procmacros" } portable-atomic = "1.6.0" +static_cell = "2.1.0" [build-dependencies] cfg-if = "1.0.0" diff --git a/esp-hal-embassy/src/lib.rs b/esp-hal-embassy/src/lib.rs index 93b6a1114bf..fe6fbfb563a 100644 --- a/esp-hal-embassy/src/lib.rs +++ b/esp-hal-embassy/src/lib.rs @@ -36,7 +36,12 @@ // MUST be the first module mod fmt; -use esp_hal::clock::Clocks; +#[cfg(not(feature = "esp32"))] +use esp_hal::timer::systimer::Alarm; +use esp_hal::{ + clock::Clocks, + timer::{timg::Timer as TimgTimer, ErasedTimer}, +}; pub use macros::main; #[cfg(feature = "executors")] @@ -47,7 +52,100 @@ use self::time_driver::{EmbassyTimer, Timer}; mod executor; mod time_driver; -/// Initialize embassy -pub fn init(clocks: &Clocks, time_driver: &'static mut [Timer]) { - EmbassyTimer::init(clocks, time_driver) +macro_rules! mk_static { + ($t:ty,$val:expr) => {{ + static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); + #[deny(unused_attributes)] + let x = STATIC_CELL.uninit().write(($val)); + x + }}; +} + +/// A trait to allow better UX for initializing the timers. +/// +/// This trait is meant to be used only for the `init` function. +/// Calling `timers()` multiple times may panic. +pub trait TimerCollection { + /// Returns the timers as a slice. + fn timers(self) -> &'static mut [Timer]; +} + +/// Helper trait to reduce boilerplate. +/// +/// We can't blanket-implement for `Into` because of possible +/// conflicting implementations. +trait IntoErasedTimer: Into {} + +impl IntoErasedTimer for ErasedTimer {} + +impl IntoErasedTimer for TimgTimer +where + DM: esp_hal::Mode, + Self: Into, +{ +} + +#[cfg(not(feature = "esp32"))] +impl IntoErasedTimer for Alarm<'_, T, DM, COMP, UNIT> +where + DM: esp_hal::Mode, + Self: Into, +{ +} + +impl TimerCollection for T +where + T: IntoErasedTimer, +{ + fn timers(self) -> &'static mut [Timer] { + Timer::new(self.into()).timers() + } +} + +impl TimerCollection for Timer { + fn timers(self) -> &'static mut [Timer] { + let timers = mk_static!([Timer; 1], [self]); + timers.timers() + } +} + +impl TimerCollection for &'static mut [Timer] { + fn timers(self) -> &'static mut [Timer] { + self + } +} + +impl TimerCollection for &'static mut [Timer; N] { + fn timers(self) -> &'static mut [Timer] { + self.as_mut() + } +} + +/// Initialize embassy. +/// +/// Call this as soon as possible, before the first timer-related operation. +/// +/// The time driver can be one of a number of different options: +/// +/// - A timg `Timer` instance +/// - A systimer `Alarm` instance +/// - An `ErasedTimer` instance +/// - A `OneShotTimer` instance +/// - A mutable static slice of `OneShotTimer` instances +/// - A mutable static array of `OneShotTimer` instances +/// +/// # Examples +/// +/// ```rust, no_run +#[doc = esp_hal::before_snippet!()] +/// use esp_hal::timg::TimerGroup; +/// +/// let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); +/// esp_hal_embassy::init(&clocks, timg0.timer0); +/// +/// // ... now you can spawn embassy tasks or use `Timer::after` etc. +/// # } +/// ``` +pub fn init(clocks: &Clocks, time_driver: impl TimerCollection) { + EmbassyTimer::init(clocks, time_driver.timers()) } diff --git a/esp-hal/src/lib.rs b/esp-hal/src/lib.rs index d43566cb785..ca6574dec21 100644 --- a/esp-hal/src/lib.rs +++ b/esp-hal/src/lib.rs @@ -680,7 +680,10 @@ unsafe extern "C" fn stack_chk_fail() { #[macro_export] macro_rules! before_snippet { () => { - core::include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/doc-helper/before")) + core::include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../esp-hal/doc-helper/before" + )) }; } @@ -690,6 +693,9 @@ macro_rules! before_snippet { #[macro_export] macro_rules! before_snippet { () => { - core::include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "\\doc-helper\\before")) + core::include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "\\..\\esp-hal\\doc-helper\\before" + )) }; } diff --git a/esp-hal/src/timer/timg.rs b/esp-hal/src/timer/timg.rs index 3fb12060b9d..b860255979c 100644 --- a/esp-hal/src/timer/timg.rs +++ b/esp-hal/src/timer/timg.rs @@ -369,7 +369,7 @@ where } } - /// Block until the timer has elasped. + /// Block until the timer has elapsed. pub fn wait(&mut self) { while !self.has_elapsed() {} } diff --git a/esp-wifi/CHANGELOG.md b/esp-wifi/CHANGELOG.md index b11a898719f..cbff9b1a532 100644 --- a/esp-wifi/CHANGELOG.md +++ b/esp-wifi/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Changed `init` to accept timers of multiple types (#1957) + ### Fixed - Increased NPL event queue size to prevent overflow (#1891) diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index 856fc9863f6..5e59dcc764c 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -53,8 +53,9 @@ atomic-waker = { version = "1.1.2", default-features = false, features = [ ] } [build-dependencies] -toml-cfg = "0.2.0" -esp-build = { version = "0.1.0", path = "../esp-build" } +toml-cfg = "0.2.0" +esp-build = { version = "0.1.0", path = "../esp-build" } +esp-metadata = { version = "0.2.0", path = "../esp-metadata" } [features] default = ["log"] diff --git a/esp-wifi/README.md b/esp-wifi/README.md index 04b338e7297..c7e9fa1501b 100644 --- a/esp-wifi/README.md +++ b/esp-wifi/README.md @@ -28,7 +28,7 @@ Minimum supported Rust compiler version: 1.72.0.0 ### Importing -Ensure that the right features are enabled for your chip. See [Examples] for more examples. +Ensure that the right features are enabled for your chip. See [Examples](https://github.com/esp-rs/esp-hal/tree/main/examples#examples) for more examples. ```toml [dependencies.esp-wifi] diff --git a/esp-wifi/build.rs b/esp-wifi/build.rs index e389bc7500c..14f089947e2 100644 --- a/esp-wifi/build.rs +++ b/esp-wifi/build.rs @@ -1,11 +1,41 @@ +use std::{error::Error, str::FromStr}; + use esp_build::assert_unique_used_features; +use esp_metadata::{Chip, Config}; -fn main() -> Result<(), String> { +fn main() -> Result<(), Box> { // Ensure that only a single chip is specified: assert_unique_used_features!( "esp32", "esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32s2", "esp32s3" ); + // NOTE: update when adding new device support! + // Determine the name of the configured device: + let device_name = if cfg!(feature = "esp32") { + "esp32" + } else if cfg!(feature = "esp32c2") { + "esp32c2" + } else if cfg!(feature = "esp32c3") { + "esp32c3" + } else if cfg!(feature = "esp32c6") { + "esp32c6" + } else if cfg!(feature = "esp32h2") { + "esp32h2" + } else if cfg!(feature = "esp32s2") { + "esp32s2" + } else if cfg!(feature = "esp32s3") { + "esp32s3" + } else { + unreachable!() // We've confirmed exactly one known device was selected + }; + + // Load the configuration file for the configured device: + let chip = Chip::from_str(device_name)?; + let config = Config::for_chip(&chip); + + // Define all necessary configuration symbols for the configured device: + config.define_symbols(); + #[cfg(all(feature = "ble", feature = "esp32s2"))] { panic!( @@ -38,39 +68,17 @@ fn main() -> Result<(), String> { "# ); } - match std::env::var("OPT_LEVEL") { - Ok(level) => { - if level != "2" && level != "3" { - let message = format!( - "esp-wifi should be built with optimization level 2 or 3 - yours is {level}. - See https://github.com/esp-rs/esp-wifi", - ); - print_warning(message); - } + if let Ok(level) = std::env::var("OPT_LEVEL") { + if level != "2" && level != "3" { + let message = format!( + "esp-wifi should be built with optimization level 2 or 3 - yours is {level}. + See https://github.com/esp-rs/esp-wifi", + ); + print_warning(message); } - Err(_err) => (), } - #[cfg(feature = "esp32")] - println!("cargo:rustc-cfg=esp32"); - - #[cfg(feature = "esp32c2")] - println!("cargo:rustc-cfg=esp32c2"); - - #[cfg(feature = "esp32c3")] - println!("cargo:rustc-cfg=esp32c3"); - - #[cfg(feature = "esp32c6")] - println!("cargo:rustc-cfg=esp32c6"); - - #[cfg(feature = "esp32h2")] - println!("cargo:rustc-cfg=esp32h2"); - - #[cfg(feature = "esp32s2")] - println!("cargo:rustc-cfg=esp32s2"); - - #[cfg(feature = "esp32s3")] - println!("cargo:rustc-cfg=esp32s3"); + println!("cargo:rustc-cfg={}", device_name); #[cfg(feature = "coex")] { diff --git a/esp-wifi/src/lib.rs b/esp-wifi/src/lib.rs index 6accfc2b246..094a6e2785b 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -17,8 +17,14 @@ use core::{cell::RefCell, mem::MaybeUninit, ptr::addr_of_mut}; use common_adapter::{chip_specific::phy_mem_init, init_radio_clock_control, RADIO_CLOCKS}; use critical_section::Mutex; use esp_hal as hal; +#[cfg(not(feature = "esp32"))] +use esp_hal::timer::systimer::Alarm; use fugit::MegahertzU32; -use hal::{clock::Clocks, system::RadioClockController}; +use hal::{ + clock::Clocks, + system::RadioClockController, + timer::{timg::Timer as TimgTimer, ErasedTimer, PeriodicTimer}, +}; use linked_list_allocator::Heap; #[cfg(feature = "wifi")] use wifi::WifiError; @@ -142,7 +148,7 @@ fn init_heap() { }); } -pub(crate) type EspWifiTimer = crate::timer::TimeBase; +type TimeBase = PeriodicTimer<'static, ErasedTimer>; #[derive(Debug, PartialEq, PartialOrd)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -215,10 +221,86 @@ impl EspWifiInitFor { } } -/// Initialize for using WiFi and or BLE +/// A trait to allow better UX for initializing esp-wifi. +/// +/// This trait is meant to be used only for the `init` function. +/// Calling `timers()` multiple times may panic. +pub trait EspWifiTimerSource { + /// Returns the timer source. + fn timer(self) -> TimeBase; +} + +/// Helper trait to reduce boilerplate. +/// +/// We can't blanket-implement for `Into` because of possible +/// conflicting implementations. +trait IntoErasedTimer: Into {} + +impl IntoErasedTimer for TimgTimer +where + DM: esp_hal::Mode, + Self: Into, +{ +} + +#[cfg(not(feature = "esp32"))] +impl IntoErasedTimer for Alarm<'_, T, DM, COMP, UNIT> +where + DM: esp_hal::Mode, + Self: Into, +{ +} + +impl IntoErasedTimer for ErasedTimer {} + +impl EspWifiTimerSource for T +where + T: IntoErasedTimer, +{ + fn timer(self) -> TimeBase { + TimeBase::new(self.into()).timer() + } +} + +impl EspWifiTimerSource for TimeBase { + fn timer(self) -> TimeBase { + self + } +} + +/// Initialize for using WiFi and or BLE. +/// +/// # The `timer` argument +/// +/// The `timer` argument is a timer source that is used by the WiFi driver to +/// schedule internal tasks. The timer source can be any of the following: +/// +/// - A timg `Timer` instance +/// - A systimer `Alarm` instance +/// - An `ErasedTimer` instance +/// - A `OneShotTimer` instance +/// +/// # Examples +/// +/// ```rust, no_run +#[doc = esp_hal::before_snippet!()] +/// use esp_hal::{rng::Rng, timg::TimerGroup}; +/// use esp_wifi::EspWifiInitFor; +/// +/// let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); +/// let init = esp_wifi::initialize( +/// EspWifiInitFor::Wifi, +/// timg0.timer0, +/// Rng::new(peripherals.RNG), +/// peripherals.RADIO_CLK, +/// &clocks, +/// ) +/// .unwrap(); +/// # } +/// ``` pub fn initialize( init_for: EspWifiInitFor, - timer: EspWifiTimer, + timer: impl EspWifiTimerSource, rng: hal::rng::Rng, radio_clocks: hal::peripherals::RADIO_CLK, clocks: &Clocks, @@ -238,7 +320,7 @@ pub fn initialize( init_radio_clock_control(radio_clocks); init_rng(rng); init_tasks(); - setup_timer_isr(timer)?; + setup_timer_isr(timer.timer())?; wifi_set_log_verbose(); init_clocks(); diff --git a/esp-wifi/src/timer/mod.rs b/esp-wifi/src/timer/mod.rs index 37a865d8637..a8240425394 100644 --- a/esp-wifi/src/timer/mod.rs +++ b/esp-wifi/src/timer/mod.rs @@ -14,6 +14,8 @@ mod arch_specific; pub use arch_specific::*; pub use chip_specific::*; +use crate::TimeBase; + pub fn setup_timer_isr(timebase: TimeBase) -> Result<(), esp_hal::timer::Error> { setup_radio_isr(); diff --git a/esp-wifi/src/timer/riscv.rs b/esp-wifi/src/timer/riscv.rs index 0b7778b62ba..ea9837652a5 100644 --- a/esp-wifi/src/timer/riscv.rs +++ b/esp-wifi/src/timer/riscv.rs @@ -1,10 +1,7 @@ use core::cell::RefCell; use critical_section::Mutex; -use esp_hal::{ - interrupt::InterruptHandler, - timer::{ErasedTimer, PeriodicTimer}, -}; +use esp_hal::interrupt::InterruptHandler; #[cfg(any(feature = "esp32c6", feature = "esp32h2"))] use peripherals::INTPRI as SystemPeripheral; #[cfg(not(any(feature = "esp32c6", feature = "esp32h2")))] @@ -17,10 +14,10 @@ use crate::{ riscv, }, preempt::preempt::task_switch, + TimeBase, }; /// The timer responsible for time slicing. -pub type TimeBase = PeriodicTimer<'static, ErasedTimer>; static ALARM0: Mutex>> = Mutex::new(RefCell::new(None)); const TIMESLICE_FREQUENCY: fugit::HertzU64 = fugit::HertzU64::from_raw(crate::CONFIG.tick_rate_hz as u64); diff --git a/esp-wifi/src/timer/xtensa.rs b/esp-wifi/src/timer/xtensa.rs index e4044d9abc5..6f7443207d3 100644 --- a/esp-wifi/src/timer/xtensa.rs +++ b/esp-wifi/src/timer/xtensa.rs @@ -1,18 +1,15 @@ use core::cell::RefCell; use critical_section::Mutex; -use esp_hal::{ - interrupt::InterruptHandler, - timer::{ErasedTimer, PeriodicTimer}, -}; +use esp_hal::interrupt::InterruptHandler; use crate::{ hal::{interrupt, trapframe::TrapFrame, xtensa_lx, xtensa_lx_rt}, preempt::preempt::task_switch, + TimeBase, }; /// The timer responsible for time slicing. -pub type TimeBase = PeriodicTimer<'static, ErasedTimer>; static TIMER1: Mutex>> = Mutex::new(RefCell::new(None)); const TIMESLICE_FREQUENCY: fugit::HertzU64 = fugit::HertzU64::from_raw(crate::CONFIG.tick_rate_hz as u64); diff --git a/examples/src/bin/embassy_hello_world.rs b/examples/src/bin/embassy_hello_world.rs index 786435e4b4b..9f289cb230a 100644 --- a/examples/src/bin/embassy_hello_world.rs +++ b/examples/src/bin/embassy_hello_world.rs @@ -16,19 +16,9 @@ use esp_hal::{ clock::ClockControl, peripherals::Peripherals, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, }; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[embassy_executor::task] async fn run() { loop { @@ -47,10 +37,7 @@ async fn main(spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); spawner.spawn(run()).ok(); diff --git a/examples/src/bin/embassy_i2c.rs b/examples/src/bin/embassy_i2c.rs index 5585a737131..9ef50be70d6 100644 --- a/examples/src/bin/embassy_i2c.rs +++ b/examples/src/bin/embassy_i2c.rs @@ -26,20 +26,10 @@ use esp_hal::{ peripherals::Peripherals, prelude::*, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, }; use lis3dh_async::{Lis3dh, Range, SlaveAddr}; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { let peripherals = Peripherals::take(); @@ -47,10 +37,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs b/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs index 48ee77717f6..1e4482f101d 100644 --- a/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs +++ b/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs @@ -27,19 +27,9 @@ use esp_hal::{ peripherals::Peripherals, prelude::*, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, }; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { let peripherals = Peripherals::take(); @@ -47,10 +37,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_i2s_read.rs b/examples/src/bin/embassy_i2s_read.rs index f64b6bbb476..edffeec2885 100644 --- a/examples/src/bin/embassy_i2s_read.rs +++ b/examples/src/bin/embassy_i2s_read.rs @@ -28,20 +28,10 @@ use esp_hal::{ peripherals::Peripherals, prelude::*, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, }; use esp_println::println; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { println!("Init!"); @@ -50,10 +40,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_i2s_sound.rs b/examples/src/bin/embassy_i2s_sound.rs index 35ba3c6d7af..bc136a6d6b2 100644 --- a/examples/src/bin/embassy_i2s_sound.rs +++ b/examples/src/bin/embassy_i2s_sound.rs @@ -42,7 +42,7 @@ use esp_hal::{ peripherals::Peripherals, prelude::*, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, }; use esp_println::println; @@ -54,16 +54,6 @@ const SINE: [i16; 64] = [ -28897, -27244, -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211, ]; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { println!("Init!"); @@ -72,10 +62,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_multiprio.rs b/examples/src/bin/embassy_multiprio.rs index 472b79323e8..c068be165c8 100644 --- a/examples/src/bin/embassy_multiprio.rs +++ b/examples/src/bin/embassy_multiprio.rs @@ -105,8 +105,7 @@ async fn main(low_prio_spawner: Spawner) { OneShotTimer::new(alarm0) }; - let timers = [timer0, timer1]; - let timers = mk_static!([OneShotTimer; 2], timers); + let timers = mk_static!([OneShotTimer; 2], [timer0, timer1]); esp_hal_embassy::init(&clocks, timers); static EXECUTOR: StaticCell> = StaticCell::new(); diff --git a/examples/src/bin/embassy_parl_io_rx.rs b/examples/src/bin/embassy_parl_io_rx.rs index 8e419cb8ad7..43328f2e037 100644 --- a/examples/src/bin/embassy_parl_io_rx.rs +++ b/examples/src/bin/embassy_parl_io_rx.rs @@ -22,24 +22,10 @@ use esp_hal::{ peripherals::Peripherals, prelude::*, system::SystemControl, - timer::{ - systimer::{SystemTimer, Target}, - ErasedTimer, - OneShotTimer, - }, + timer::systimer::{SystemTimer, Target}, }; use esp_println::println; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); @@ -48,10 +34,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - let alarm0: ErasedTimer = systimer.alarm0.into(); - let timers = [OneShotTimer::new(alarm0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, systimer.alarm0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_parl_io_tx.rs b/examples/src/bin/embassy_parl_io_tx.rs index e692ca64b19..ae747156dfc 100644 --- a/examples/src/bin/embassy_parl_io_tx.rs +++ b/examples/src/bin/embassy_parl_io_tx.rs @@ -33,24 +33,10 @@ use esp_hal::{ peripherals::Peripherals, prelude::*, system::SystemControl, - timer::{ - systimer::{SystemTimer, Target}, - ErasedTimer, - OneShotTimer, - }, + timer::systimer::{SystemTimer, Target}, }; use esp_println::println; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); @@ -59,10 +45,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - let alarm0: ErasedTimer = systimer.alarm0.into(); - let timers = [OneShotTimer::new(alarm0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, systimer.alarm0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_rmt_rx.rs b/examples/src/bin/embassy_rmt_rx.rs index cf174a7c205..16d48dce79c 100644 --- a/examples/src/bin/embassy_rmt_rx.rs +++ b/examples/src/bin/embassy_rmt_rx.rs @@ -19,7 +19,7 @@ use esp_hal::{ prelude::*, rmt::{asynch::RxChannelAsync, PulseCode, Rmt, RxChannelConfig, RxChannelCreatorAsync}, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, }; use esp_println::{print, println}; @@ -28,16 +28,6 @@ const WIDTH: usize = 80; #[cfg(debug_assertions)] compile_error!("Run this example in release mode"); -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[embassy_executor::task] async fn signal_task(mut pin: Output<'static, Gpio5>) { loop { @@ -57,10 +47,7 @@ async fn main(spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_rmt_tx.rs b/examples/src/bin/embassy_rmt_tx.rs index 45244988e3e..8c179bcd02a 100644 --- a/examples/src/bin/embassy_rmt_tx.rs +++ b/examples/src/bin/embassy_rmt_tx.rs @@ -21,20 +21,10 @@ use esp_hal::{ prelude::*, rmt::{asynch::TxChannelAsync, PulseCode, Rmt, TxChannelConfig, TxChannelCreatorAsync}, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, }; use esp_println::println; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { println!("Init!"); @@ -43,10 +33,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_serial.rs b/examples/src/bin/embassy_serial.rs index 223138040e2..fc9ea25a82b 100644 --- a/examples/src/bin/embassy_serial.rs +++ b/examples/src/bin/embassy_serial.rs @@ -17,7 +17,7 @@ use esp_hal::{ gpio::Io, peripherals::{Peripherals, UART0}, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, uart::{ config::{AtCmdConfig, Config}, Uart, @@ -33,16 +33,6 @@ const READ_BUF_SIZE: usize = 64; // EOT (CTRL-D) const AT_CMD: u8 = 0x04; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[embassy_executor::task] async fn writer( mut tx: UartTx<'static, UART0, Async>, @@ -95,10 +85,7 @@ async fn main(spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_spi.rs b/examples/src/bin/embassy_spi.rs index fbfd24dd4a1..e406089626c 100644 --- a/examples/src/bin/embassy_spi.rs +++ b/examples/src/bin/embassy_spi.rs @@ -33,19 +33,9 @@ use esp_hal::{ SpiMode, }, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, }; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); @@ -54,10 +44,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; diff --git a/examples/src/bin/embassy_touch.rs b/examples/src/bin/embassy_touch.rs index 9d677b90085..eb686243575 100644 --- a/examples/src/bin/embassy_touch.rs +++ b/examples/src/bin/embassy_touch.rs @@ -22,21 +22,11 @@ use esp_hal::{ peripherals::Peripherals, rtc_cntl::Rtc, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, touch::{Touch, TouchConfig, TouchPad}, }; use esp_println::println; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::logger::init_logger_from_env(); @@ -46,10 +36,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let mut rtc = Rtc::new(peripherals.LPWR); diff --git a/examples/src/bin/embassy_twai.rs b/examples/src/bin/embassy_twai.rs index 38189e17f03..6c0984d4db6 100644 --- a/examples/src/bin/embassy_twai.rs +++ b/examples/src/bin/embassy_twai.rs @@ -30,7 +30,7 @@ use esp_hal::{ interrupt, peripherals::{self, Peripherals, TWAI0}, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, twai::{self, EspTwaiFrame, TwaiMode, TwaiRx, TwaiTx}, }; use esp_println::println; @@ -38,16 +38,6 @@ use static_cell::StaticCell; type TwaiOutbox = Channel; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[embassy_executor::task] async fn receiver( mut rx: TwaiRx<'static, TWAI0, esp_hal::Async>, @@ -99,10 +89,7 @@ async fn main(spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_usb_serial.rs b/examples/src/bin/embassy_usb_serial.rs index 9e489984e1b..cd37616c907 100644 --- a/examples/src/bin/embassy_usb_serial.rs +++ b/examples/src/bin/embassy_usb_serial.rs @@ -29,19 +29,9 @@ use esp_hal::{ }, peripherals::Peripherals, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, }; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) -> () { esp_println::println!("Init!"); @@ -50,10 +40,7 @@ async fn main(_spawner: Spawner) -> () { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_usb_serial_jtag.rs b/examples/src/bin/embassy_usb_serial_jtag.rs index 2501270ebb3..4282ed4c971 100644 --- a/examples/src/bin/embassy_usb_serial_jtag.rs +++ b/examples/src/bin/embassy_usb_serial_jtag.rs @@ -15,7 +15,7 @@ use esp_hal::{ clock::ClockControl, peripherals::Peripherals, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, usb_serial_jtag::{UsbSerialJtag, UsbSerialJtagRx, UsbSerialJtagTx}, Async, }; @@ -23,16 +23,6 @@ use static_cell::StaticCell; const MAX_BUFFER_SIZE: usize = 512; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[embassy_executor::task] async fn writer( mut tx: UsbSerialJtagTx<'static, Async>, @@ -80,10 +70,7 @@ async fn main(spawner: Spawner) -> () { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let (tx, rx) = UsbSerialJtag::new_async(peripherals.USB_DEVICE).split(); diff --git a/examples/src/bin/embassy_wait.rs b/examples/src/bin/embassy_wait.rs index 2f6c9d30dae..82e8d3c86b2 100644 --- a/examples/src/bin/embassy_wait.rs +++ b/examples/src/bin/embassy_wait.rs @@ -16,19 +16,9 @@ use esp_hal::{ gpio::{Input, Io, Pull}, peripherals::Peripherals, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, + timer::timg::TimerGroup, }; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); @@ -37,10 +27,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] diff --git a/examples/src/bin/wifi_access_point.rs b/examples/src/bin/wifi_access_point.rs index 06e449cc84d..d9807afa65f 100644 --- a/examples/src/bin/wifi_access_point.rs +++ b/examples/src/bin/wifi_access_point.rs @@ -21,7 +21,7 @@ use esp_hal::{ prelude::*, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::{print, println}; use esp_wifi::{ @@ -48,12 +48,10 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Wifi, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, diff --git a/examples/src/bin/wifi_access_point_with_sta.rs b/examples/src/bin/wifi_access_point_with_sta.rs index b47feead409..9ca5aaccb41 100644 --- a/examples/src/bin/wifi_access_point_with_sta.rs +++ b/examples/src/bin/wifi_access_point_with_sta.rs @@ -22,7 +22,7 @@ use esp_hal::{ prelude::*, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::{print, println}; use esp_wifi::{ @@ -55,12 +55,10 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Wifi, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, diff --git a/examples/src/bin/wifi_bench.rs b/examples/src/bin/wifi_bench.rs index 83005f34fd3..5427e3b11e6 100644 --- a/examples/src/bin/wifi_bench.rs +++ b/examples/src/bin/wifi_bench.rs @@ -22,7 +22,7 @@ use esp_hal::{ prelude::*, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::println; use esp_wifi::{ @@ -68,12 +68,10 @@ fn main() -> ! { let server_address: Ipv4Address = HOST_IP.parse().expect("Invalid HOST_IP address"); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Wifi, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, diff --git a/examples/src/bin/wifi_ble.rs b/examples/src/bin/wifi_ble.rs index b264ded3df6..34bf83e936f 100644 --- a/examples/src/bin/wifi_ble.rs +++ b/examples/src/bin/wifi_ble.rs @@ -30,7 +30,7 @@ use esp_hal::{ prelude::*, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::println; use esp_wifi::{ble::controller::BleConnector, initialize, EspWifiInitFor}; @@ -45,12 +45,10 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Ble, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, diff --git a/examples/src/bin/wifi_coex.rs b/examples/src/bin/wifi_coex.rs index 16fa94e1cd6..4f94af99076 100644 --- a/examples/src/bin/wifi_coex.rs +++ b/examples/src/bin/wifi_coex.rs @@ -32,7 +32,7 @@ use esp_hal::{ prelude::*, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::{print, println}; use esp_wifi::{ @@ -61,12 +61,10 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::WifiBle, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, diff --git a/examples/src/bin/wifi_dhcp.rs b/examples/src/bin/wifi_dhcp.rs index 72183c5ece8..0ae1adb2191 100644 --- a/examples/src/bin/wifi_dhcp.rs +++ b/examples/src/bin/wifi_dhcp.rs @@ -19,7 +19,7 @@ use esp_hal::{ prelude::*, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::{print, println}; use esp_wifi::{ @@ -54,12 +54,10 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Wifi, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, diff --git a/examples/src/bin/wifi_embassy_access_point.rs b/examples/src/bin/wifi_embassy_access_point.rs index 16a4edd1aa8..6b99c22a985 100644 --- a/examples/src/bin/wifi_embassy_access_point.rs +++ b/examples/src/bin/wifi_embassy_access_point.rs @@ -32,7 +32,7 @@ use esp_hal::{ peripherals::Peripherals, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::{print, println}; use esp_wifi::{ @@ -69,12 +69,10 @@ async fn main(spawner: Spawner) -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Wifi, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, @@ -88,20 +86,14 @@ async fn main(spawner: Spawner) -> ! { #[cfg(feature = "esp32")] { let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let timer0: ErasedTimer = timg1.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg1.timer0); } #[cfg(not(feature = "esp32"))] { let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) .split::(); - let alarm0: ErasedTimer = systimer.alarm0.into(); - let timers = [OneShotTimer::new(alarm0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, systimer.alarm0); } let config = Config::ipv4_static(StaticConfigV4 { diff --git a/examples/src/bin/wifi_embassy_access_point_with_sta.rs b/examples/src/bin/wifi_embassy_access_point_with_sta.rs index b7fdb2b9bf7..6bc52865a8c 100644 --- a/examples/src/bin/wifi_embassy_access_point_with_sta.rs +++ b/examples/src/bin/wifi_embassy_access_point_with_sta.rs @@ -35,7 +35,7 @@ use esp_hal::{ peripherals::Peripherals, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::{print, println}; use esp_wifi::{ @@ -77,12 +77,10 @@ async fn main(spawner: Spawner) -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Wifi, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, @@ -96,20 +94,14 @@ async fn main(spawner: Spawner) -> ! { #[cfg(feature = "esp32")] { let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let timer0: ErasedTimer = timg1.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg1.timer0); } #[cfg(not(feature = "esp32"))] { let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) .split::(); - let alarm0: ErasedTimer = systimer.alarm0.into(); - let timers = [OneShotTimer::new(alarm0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, systimer.alarm0); } let ap_config = Config::ipv4_static(StaticConfigV4 { diff --git a/examples/src/bin/wifi_embassy_bench.rs b/examples/src/bin/wifi_embassy_bench.rs index 09f306c5fad..81fce5ae720 100644 --- a/examples/src/bin/wifi_embassy_bench.rs +++ b/examples/src/bin/wifi_embassy_bench.rs @@ -26,7 +26,7 @@ use esp_hal::{ peripherals::Peripherals, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::println; use esp_wifi::{ @@ -81,12 +81,10 @@ async fn main(spawner: Spawner) -> ! { let server_address: Ipv4Address = HOST_IP.parse().expect("Invalid HOST_IP address"); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Wifi, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, @@ -100,20 +98,14 @@ async fn main(spawner: Spawner) -> ! { #[cfg(feature = "esp32")] { let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let timer0: ErasedTimer = timg1.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg1.timer0); } #[cfg(not(feature = "esp32"))] { let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) .split::(); - let alarm0: ErasedTimer = systimer.alarm0.into(); - let timers = [OneShotTimer::new(alarm0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, systimer.alarm0); } let config = Config::dhcpv4(Default::default()); diff --git a/examples/src/bin/wifi_embassy_ble.rs b/examples/src/bin/wifi_embassy_ble.rs index 76eb5d2fffa..89fb122ac67 100644 --- a/examples/src/bin/wifi_embassy_ble.rs +++ b/examples/src/bin/wifi_embassy_ble.rs @@ -32,21 +32,11 @@ use esp_hal::{ peripherals::*, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::println; use esp_wifi::{ble::controller::asynch::BleConnector, initialize, EspWifiInitFor}; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); @@ -57,12 +47,10 @@ async fn main(_spawner: Spawner) -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Ble, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, @@ -83,20 +71,14 @@ async fn main(_spawner: Spawner) -> ! { #[cfg(feature = "esp32")] { let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let timer0: ErasedTimer = timg1.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg1.timer0); } #[cfg(not(feature = "esp32"))] { let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) .split::(); - let alarm0: ErasedTimer = systimer.alarm0.into(); - let timers = [OneShotTimer::new(alarm0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, systimer.alarm0); } let mut bluetooth = peripherals.BT; diff --git a/examples/src/bin/wifi_embassy_dhcp.rs b/examples/src/bin/wifi_embassy_dhcp.rs index 6e72eb7af49..961ef175cdb 100644 --- a/examples/src/bin/wifi_embassy_dhcp.rs +++ b/examples/src/bin/wifi_embassy_dhcp.rs @@ -22,7 +22,7 @@ use esp_hal::{ peripherals::Peripherals, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::println; use esp_wifi::{ @@ -62,12 +62,10 @@ async fn main(spawner: Spawner) -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Wifi, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, @@ -81,20 +79,14 @@ async fn main(spawner: Spawner) -> ! { #[cfg(feature = "esp32")] { let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let timer0: ErasedTimer = timg1.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg1.timer0); } #[cfg(not(feature = "esp32"))] { let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) .split::(); - let alarm0: ErasedTimer = systimer.alarm0.into(); - let timers = [OneShotTimer::new(alarm0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, systimer.alarm0); } let config = Config::dhcpv4(Default::default()); diff --git a/examples/src/bin/wifi_embassy_esp_now.rs b/examples/src/bin/wifi_embassy_esp_now.rs index 2d30dda13d0..a00179d0f15 100644 --- a/examples/src/bin/wifi_embassy_esp_now.rs +++ b/examples/src/bin/wifi_embassy_esp_now.rs @@ -19,7 +19,7 @@ use esp_hal::{ peripherals::Peripherals, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::println; use esp_wifi::{ @@ -28,16 +28,6 @@ use esp_wifi::{ EspWifiInitFor, }; -// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - #[esp_hal_embassy::main] async fn main(_spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); @@ -48,12 +38,10 @@ async fn main(_spawner: Spawner) -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Wifi, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, @@ -67,20 +55,14 @@ async fn main(_spawner: Spawner) -> ! { #[cfg(feature = "esp32")] { let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let timer0: ErasedTimer = timg1.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg1.timer0); } #[cfg(not(feature = "esp32"))] { let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) .split::(); - let alarm0: ErasedTimer = systimer.alarm0.into(); - let timers = [OneShotTimer::new(alarm0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, systimer.alarm0); } let mut ticker = Ticker::every(Duration::from_secs(5)); diff --git a/examples/src/bin/wifi_embassy_esp_now_duplex.rs b/examples/src/bin/wifi_embassy_esp_now_duplex.rs index f03d7428730..e3d02644f24 100644 --- a/examples/src/bin/wifi_embassy_esp_now_duplex.rs +++ b/examples/src/bin/wifi_embassy_esp_now_duplex.rs @@ -19,7 +19,7 @@ use esp_hal::{ peripherals::Peripherals, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::println; use esp_wifi::{ @@ -48,12 +48,10 @@ async fn main(spawner: Spawner) -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Wifi, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, @@ -67,20 +65,14 @@ async fn main(spawner: Spawner) -> ! { #[cfg(feature = "esp32")] { let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let timer0: ErasedTimer = timg1.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg1.timer0); } #[cfg(not(feature = "esp32"))] { let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) .split::(); - let alarm0: ErasedTimer = systimer.alarm0.into(); - let timers = [OneShotTimer::new(alarm0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, systimer.alarm0); } let (manager, sender, receiver) = esp_now.split(); diff --git a/examples/src/bin/wifi_esp_now.rs b/examples/src/bin/wifi_esp_now.rs index 35e61e43b9b..9dd365c25a1 100644 --- a/examples/src/bin/wifi_esp_now.rs +++ b/examples/src/bin/wifi_esp_now.rs @@ -15,7 +15,7 @@ use esp_hal::{ prelude::*, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::println; use esp_wifi::{ @@ -35,12 +35,10 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Wifi, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, diff --git a/examples/src/bin/wifi_static_ip.rs b/examples/src/bin/wifi_static_ip.rs index 855ceca940f..f4d86620cc7 100644 --- a/examples/src/bin/wifi_static_ip.rs +++ b/examples/src/bin/wifi_static_ip.rs @@ -20,7 +20,7 @@ use esp_hal::{ prelude::*, rng::Rng, system::SystemControl, - timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer}, + timer::timg::TimerGroup, }; use esp_println::{print, println}; use esp_wifi::{ @@ -54,12 +54,10 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timer = PeriodicTimer::new(timer0); let init = initialize( EspWifiInitFor::Wifi, - timer, + timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, &clocks, diff --git a/hil-test/tests/embassy_timers_executors.rs b/hil-test/tests/embassy_timers_executors.rs index e24533c89dd..4693680fe98 100644 --- a/hil-test/tests/embassy_timers_executors.rs +++ b/hil-test/tests/embassy_timers_executors.rs @@ -120,17 +120,13 @@ struct Resources { impl Resources { fn set_up_embassy_with_timg0(self) { let timg0 = TimerGroup::new(self.timg0, &self.clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = mk_static!(OneShotTimer, OneShotTimer::new(timer0)); - esp_hal_embassy::init(&self.clocks, core::slice::from_mut(timers)); + esp_hal_embassy::init(&self.clocks, timg0.timer0); } #[cfg(not(feature = "esp32"))] fn set_up_embassy_with_systimer(self) { let systimer = SystemTimer::new(self.systimer).split::(); - let alarm0: ErasedTimer = systimer.alarm0.into(); - let timers = mk_static!(OneShotTimer, OneShotTimer::new(alarm0)); - esp_hal_embassy::init(&self.clocks, core::slice::from_mut(timers)); + esp_hal_embassy::init(&self.clocks, systimer.alarm0); } } diff --git a/hil-test/tests/gpio.rs b/hil-test/tests/gpio.rs index 0c5cbdb0e59..9c257ab27c4 100644 --- a/hil-test/tests/gpio.rs +++ b/hil-test/tests/gpio.rs @@ -55,10 +55,7 @@ impl<'d> Context<'d> { let delay = Delay::new(&clocks); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let timer0: ErasedTimer = timg0.timer0.into(); - let timers = [OneShotTimer::new(timer0)]; - let timers = mk_static!([OneShotTimer; 1], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(&clocks, timg0.timer0); Context { io2: Input::new(io.pins.gpio2, Pull::Down),