From 99e39ef4d8c3870cf7d1b89995edc4817e756009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Wed, 4 Sep 2024 15:05:07 +0200 Subject: [PATCH 1/8] Clean up passing clocks to drivers --- esp-hal-embassy/src/lib.rs | 13 +- esp-hal-embassy/src/time_driver.rs | 3 +- esp-hal-smartled/src/lib.rs | 6 +- esp-hal/CHANGELOG.md | 1 + esp-hal/Cargo.toml | 1 + esp-hal/MIGRATING-0.20.md | 2 +- esp-hal/src/analog/adc/mod.rs | 2 +- esp-hal/src/analog/dac.rs | 2 +- esp-hal/src/clock/mod.rs | 215 ++++++------------ esp-hal/src/delay.rs | 6 +- esp-hal/src/dma/mod.rs | 1 - esp-hal/src/i2c.rs | 19 +- esp-hal/src/i2s.rs | 16 +- esp-hal/src/lcd_cam/cam.rs | 3 +- esp-hal/src/lcd_cam/lcd/i8080.rs | 6 +- esp-hal/src/ledc/mod.rs | 17 +- esp-hal/src/ledc/timer.rs | 37 +-- esp-hal/src/lib.rs | 15 +- esp-hal/src/mcpwm/mod.rs | 29 ++- esp-hal/src/mcpwm/operator.rs | 4 +- esp-hal/src/mcpwm/timer.rs | 18 +- esp-hal/src/parl_io.rs | 4 - esp-hal/src/peripheral.rs | 3 +- esp-hal/src/rmt.rs | 15 +- esp-hal/src/rng.rs | 1 - esp-hal/src/rom/md5.rs | 4 +- esp-hal/src/rtc_cntl/mod.rs | 2 +- esp-hal/src/soc/esp32/cpu_control.rs | 2 +- esp-hal/src/soc/esp32/efuse/mod.rs | 2 +- esp-hal/src/soc/esp32c2/efuse/mod.rs | 2 +- esp-hal/src/soc/esp32c3/efuse/mod.rs | 2 +- esp-hal/src/soc/esp32c6/efuse/mod.rs | 2 +- esp-hal/src/soc/esp32h2/efuse/mod.rs | 2 +- esp-hal/src/soc/esp32s2/efuse/mod.rs | 2 +- esp-hal/src/soc/esp32s3/cpu_control.rs | 2 +- esp-hal/src/soc/esp32s3/efuse/mod.rs | 2 +- esp-hal/src/spi/master.rs | 36 ++- esp-hal/src/timer/mod.rs | 4 +- esp-hal/src/timer/systimer.rs | 6 +- esp-hal/src/timer/timg.rs | 17 +- esp-hal/src/twai/mod.rs | 27 +-- esp-hal/src/uart.rs | 76 +++---- esp-wifi/src/lib.rs | 5 +- examples/src/bin/adc.rs | 4 +- examples/src/bin/adc_cal.rs | 4 +- examples/src/bin/advanced_serial.rs | 6 +- examples/src/bin/blinky.rs | 4 +- examples/src/bin/blinky_erased_pins.rs | 4 +- examples/src/bin/dac.rs | 4 +- examples/src/bin/debug_assist.rs | 2 +- examples/src/bin/dma_extmem2mem.rs | 4 +- examples/src/bin/dma_mem2mem.rs | 4 +- examples/src/bin/embassy_hello_world.rs | 6 +- examples/src/bin/embassy_i2c.rs | 14 +- .../embassy_i2c_bmp180_calibration_data.rs | 16 +- examples/src/bin/embassy_i2s_read.rs | 9 +- examples/src/bin/embassy_i2s_sound.rs | 9 +- examples/src/bin/embassy_multicore.rs | 6 +- .../src/bin/embassy_multicore_interrupt.rs | 6 +- examples/src/bin/embassy_multiprio.rs | 8 +- examples/src/bin/embassy_parl_io_rx.rs | 5 +- examples/src/bin/embassy_parl_io_tx.rs | 5 +- examples/src/bin/embassy_rmt_rx.rs | 8 +- examples/src/bin/embassy_rmt_tx.rs | 8 +- examples/src/bin/embassy_serial.rs | 9 +- examples/src/bin/embassy_spi.rs | 8 +- examples/src/bin/embassy_touch.rs | 6 +- examples/src/bin/embassy_twai.rs | 7 +- examples/src/bin/embassy_usb_serial.rs | 6 +- examples/src/bin/embassy_usb_serial_jtag.rs | 6 +- examples/src/bin/embassy_wait.rs | 6 +- examples/src/bin/etm_blinky_systimer.rs | 2 +- examples/src/bin/etm_gpio.rs | 2 +- examples/src/bin/etm_timer.rs | 6 +- examples/src/bin/gpio_interrupt.rs | 4 +- examples/src/bin/hello_rgb.rs | 8 +- examples/src/bin/hello_world.rs | 6 +- examples/src/bin/hmac.rs | 2 +- .../src/bin/i2c_bmp180_calibration_data.rs | 10 +- examples/src/bin/i2c_display.rs | 12 +- examples/src/bin/i2s_read.rs | 3 +- examples/src/bin/i2s_sound.rs | 3 +- .../src/bin/ieee802154_receive_all_frames.rs | 2 +- examples/src/bin/ieee802154_receive_frame.rs | 2 +- .../bin/ieee802154_send_broadcast_frame.rs | 4 +- examples/src/bin/ieee802154_send_frame.rs | 4 +- examples/src/bin/ieee802154_sniffer.rs | 4 +- examples/src/bin/lcd_cam_ov2640.rs | 7 +- examples/src/bin/lcd_i8080.rs | 5 +- examples/src/bin/ledc.rs | 4 +- examples/src/bin/lp_core_basic.rs | 2 +- examples/src/bin/lp_core_i2c.rs | 2 +- examples/src/bin/lp_core_uart.rs | 3 +- examples/src/bin/mcpwm.rs | 4 +- examples/src/bin/multicore.rs | 4 +- examples/src/bin/parl_io_rx.rs | 5 +- examples/src/bin/parl_io_tx.rs | 5 +- examples/src/bin/pcnt_encoder.rs | 2 +- examples/src/bin/psram_octal.rs | 2 +- examples/src/bin/psram_quad.rs | 2 +- examples/src/bin/qspi_flash.rs | 6 +- examples/src/bin/ram.rs | 4 +- examples/src/bin/rmt_rx.rs | 6 +- examples/src/bin/rmt_tx.rs | 6 +- examples/src/bin/rng.rs | 2 +- examples/src/bin/rtc_time.rs | 4 +- examples/src/bin/rtc_watchdog.rs | 2 +- examples/src/bin/serial_interrupts.rs | 7 +- examples/src/bin/sleep_timer.rs | 4 +- examples/src/bin/sleep_timer_ext0.rs | 4 +- examples/src/bin/sleep_timer_ext1.rs | 4 +- examples/src/bin/sleep_timer_lpio.rs | 4 +- examples/src/bin/sleep_timer_rtcio.rs | 4 +- examples/src/bin/software_interrupts.rs | 4 +- .../spi_halfduplex_read_manufacturer_id.rs | 21 +- examples/src/bin/spi_loopback.rs | 6 +- examples/src/bin/spi_loopback_dma.rs | 6 +- examples/src/bin/spi_slave_dma.rs | 4 +- examples/src/bin/systimer.rs | 4 +- examples/src/bin/timer_interrupt.rs | 4 +- examples/src/bin/touch.rs | 4 +- examples/src/bin/twai.rs | 3 +- examples/src/bin/ulp_riscv_core_basic.rs | 2 +- examples/src/bin/usb_serial.rs | 2 +- examples/src/bin/usb_serial_jtag.rs | 4 +- examples/src/bin/watchdog.rs | 6 +- examples/src/bin/wifi_80211_tx.rs | 7 +- examples/src/bin/wifi_access_point.rs | 5 +- .../src/bin/wifi_access_point_with_sta.rs | 5 +- examples/src/bin/wifi_bench.rs | 7 +- examples/src/bin/wifi_ble.rs | 5 +- examples/src/bin/wifi_coex.rs | 5 +- examples/src/bin/wifi_dhcp.rs | 5 +- examples/src/bin/wifi_embassy_access_point.rs | 11 +- .../bin/wifi_embassy_access_point_with_sta.rs | 11 +- examples/src/bin/wifi_embassy_bench.rs | 11 +- examples/src/bin/wifi_embassy_ble.rs | 11 +- examples/src/bin/wifi_embassy_dhcp.rs | 11 +- examples/src/bin/wifi_embassy_esp_now.rs | 11 +- .../src/bin/wifi_embassy_esp_now_duplex.rs | 11 +- examples/src/bin/wifi_esp_now.rs | 5 +- examples/src/bin/wifi_sniffer.rs | 5 +- examples/src/bin/wifi_static_ip.rs | 5 +- hil-test/tests/aes.rs | 2 +- hil-test/tests/aes_dma.rs | 3 +- hil-test/tests/clock_monitor.rs | 2 +- hil-test/tests/delay.rs | 2 +- hil-test/tests/dma_mem2mem.rs | 2 +- hil-test/tests/ecc.rs | 2 +- hil-test/tests/embassy_interrupt_executor.rs | 6 +- hil-test/tests/embassy_interrupt_spi_dma.rs | 21 +- hil-test/tests/embassy_timers_executors.rs | 56 +++-- hil-test/tests/get_time.rs | 23 +- hil-test/tests/gpio.rs | 6 +- hil-test/tests/i2s.rs | 8 +- hil-test/tests/i2s_async.rs | 6 +- hil-test/tests/interrupt.rs | 2 +- hil-test/tests/lcd_cam_i8080.rs | 7 +- hil-test/tests/lcd_cam_i8080_async.rs | 7 +- hil-test/tests/pcnt.rs | 4 +- hil-test/tests/qspi_read.rs | 13 +- hil-test/tests/qspi_write.rs | 11 +- hil-test/tests/qspi_write_read.rs | 13 +- hil-test/tests/rmt.rs | 4 +- hil-test/tests/rsa.rs | 2 +- hil-test/tests/rsa_async.rs | 3 +- hil-test/tests/sha.rs | 2 +- hil-test/tests/spi_full_duplex.rs | 4 +- hil-test/tests/spi_full_duplex_dma.rs | 4 +- hil-test/tests/spi_full_duplex_dma_async.rs | 4 +- hil-test/tests/spi_full_duplex_dma_pcnt.rs | 4 +- hil-test/tests/spi_half_duplex_read.rs | 4 +- hil-test/tests/spi_half_duplex_write.rs | 4 +- hil-test/tests/systimer.rs | 7 +- hil-test/tests/twai.rs | 3 +- hil-test/tests/uart.rs | 19 +- hil-test/tests/uart_async.rs | 4 +- hil-test/tests/uart_tx_rx.rs | 6 +- hil-test/tests/uart_tx_rx_async.rs | 6 +- hil-test/tests/usb_serial_jtag.rs | 6 +- 180 files changed, 610 insertions(+), 869 deletions(-) diff --git a/esp-hal-embassy/src/lib.rs b/esp-hal-embassy/src/lib.rs index 34c1d06d21d..eae0a3a4ee3 100644 --- a/esp-hal-embassy/src/lib.rs +++ b/esp-hal-embassy/src/lib.rs @@ -38,10 +38,7 @@ mod fmt; #[cfg(not(feature = "esp32"))] use esp_hal::timer::systimer::Alarm; -use esp_hal::{ - clock::Clocks, - timer::{timg::Timer as TimgTimer, ErasedTimer}, -}; +use esp_hal::timer::{timg::Timer as TimgTimer, ErasedTimer}; pub use macros::main; #[cfg(feature = "executors")] @@ -158,12 +155,12 @@ impl_array!(4); #[doc = esp_hal::before_snippet!()] /// use esp_hal::timg::TimerGroup; /// -/// let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); -/// esp_hal_embassy::init(&clocks, timg0.timer0); +/// let timg0 = TimerGroup::new(peripherals.TIMG0); +/// esp_hal_embassy::init(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()) +pub fn init(time_driver: impl TimerCollection) { + EmbassyTimer::init(time_driver.timers()) } diff --git a/esp-hal-embassy/src/time_driver.rs b/esp-hal-embassy/src/time_driver.rs index 6c0c3e9ece2..052d2fa0acc 100644 --- a/esp-hal-embassy/src/time_driver.rs +++ b/esp-hal-embassy/src/time_driver.rs @@ -3,7 +3,6 @@ use core::cell::{Cell, RefCell}; use critical_section::Mutex; use embassy_time_driver::{AlarmHandle, Driver}; use esp_hal::{ - clock::Clocks, interrupt::{InterruptHandler, Priority}, prelude::*, time::current_time, @@ -45,7 +44,7 @@ embassy_time_driver::time_driver_impl!(static DRIVER: EmbassyTimer = EmbassyTime }); impl EmbassyTimer { - pub(super) fn init(_clocks: &Clocks, timers: &'static mut [Timer]) { + pub(super) fn init(timers: &'static mut [Timer]) { if timers.len() > MAX_SUPPORTED_ALARM_COUNT { panic!( "Maximum of {} timers can be used.", diff --git a/esp-hal-smartled/src/lib.rs b/esp-hal-smartled/src/lib.rs index 981647793bb..ff3016aa6b8 100644 --- a/esp-hal-smartled/src/lib.rs +++ b/esp-hal-smartled/src/lib.rs @@ -12,10 +12,10 @@ //! //! ```rust,ignore //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); -//! let rmt = Rmt::new(peripherals.RMT, 80.MHz(), &clocks, None).unwrap(); +//! let rmt = Rmt::new(peripherals.RMT, 80.MHz(), None).unwrap(); //! //! let rmt_buffer = smartLedBuffer!(1); -//! let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio2, rmt_buffer, &clocks); +//! let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio2, rmt_buffer); //! ``` //! //! ## Feature Flags @@ -89,7 +89,6 @@ where channel: C, pin: impl Peripheral

+ 'd, rmt_buffer: [u32; BUFFER_SIZE], - clocks: &Clocks, ) -> SmartLedsAdapter where O: OutputPin + 'd, @@ -107,6 +106,7 @@ where let channel = channel.configure(pin, config).unwrap(); // Assume the RMT peripheral is set up to use the APB clock + let clocks = Clocks::get(); let src_clock = clocks.apb_clock.to_MHz(); Self { diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 5935c60c46c..903f03ecf44 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -80,6 +80,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed `FlashSafeDma` (#1856) - Remove redundant WithDmaSpi traits (#1975) - `IsFullDuplex` and `IsHalfDuplex` traits (#1985) +- `Peripherals::take` (#1999) ## [0.19.0] - 2024-07-15 diff --git a/esp-hal/Cargo.toml b/esp-hal/Cargo.toml index 2090fa79a13..c935dfd4845 100644 --- a/esp-hal/Cargo.toml +++ b/esp-hal/Cargo.toml @@ -139,6 +139,7 @@ defmt = [ "esp32h2?/defmt", "esp32s2?/defmt", "esp32s3?/defmt", + "fugit/defmt", ] #! ### PSRAM Feature Flags diff --git a/esp-hal/MIGRATING-0.20.md b/esp-hal/MIGRATING-0.20.md index 7a42dd6fb9e..6c6da2d65b6 100644 --- a/esp-hal/MIGRATING-0.20.md +++ b/esp-hal/MIGRATING-0.20.md @@ -30,7 +30,7 @@ Instead of manually grabbing peripherals and setting up clocks, you should now c - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); -+ let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); ++ let peripherals = esp_hal::init(esp_hal::Config::default()); // ... } diff --git a/esp-hal/src/analog/adc/mod.rs b/esp-hal/src/analog/adc/mod.rs index f9a53fce2a4..b7d4e58d2a8 100644 --- a/esp-hal/src/analog/adc/mod.rs +++ b/esp-hal/src/analog/adc/mod.rs @@ -46,7 +46,7 @@ //! ); //! let mut adc1 = Adc::new(peripherals.ADC1, adc1_config); //! -//! let mut delay = Delay::new(&clocks); +//! let mut delay = Delay::new(); //! //! loop { //! let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut pin)).unwrap(); diff --git a/esp-hal/src/analog/dac.rs b/esp-hal/src/analog/dac.rs index 9b5f64e7caa..8cb1e859db3 100644 --- a/esp-hal/src/analog/dac.rs +++ b/esp-hal/src/analog/dac.rs @@ -27,7 +27,7 @@ #![cfg_attr(esp32s2, doc = "let dac1_pin = io.pins.gpio17;")] //! let mut dac1 = Dac::new(peripherals.DAC1, dac1_pin); //! -//! let mut delay = Delay::new(&clocks); +//! let mut delay = Delay::new(); //! //! let mut voltage_dac1 = 200u8; //! diff --git a/esp-hal/src/clock/mod.rs b/esp-hal/src/clock/mod.rs index 59cb01cf6a1..26fcebbb01c 100644 --- a/esp-hal/src/clock/mod.rs +++ b/esp-hal/src/clock/mod.rs @@ -48,14 +48,14 @@ //! # } //! # fn main() { //! // Initialize with the highest possible frequency for this chip -//! let (peripherals, clocks) = esp_hal::init({ +//! let peripherals = esp_hal::init({ //! let mut config = esp_hal::Config::default(); //! config.cpu_clock = CpuClock::max(); //! config //! }); //! //! // Initialize with custom clock frequency -//! // let (peripherals, clocks) = esp_hal::init({ +//! // let peripherals = esp_hal::init({ //! // let mut config = esp_hal::Config::default(); #![cfg_attr( not(any(esp32c2, esp32h2)), @@ -67,15 +67,11 @@ //! // }); //! // //! // Initialize with default clock frequency for this chip -//! // let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); +//! // let peripherals = esp_hal::init(esp_hal::Config::default()); //! # } //! ``` -use core::marker::PhantomData; - use fugit::HertzU32; -#[cfg(esp32c2)] -use portable_atomic::{AtomicU32, Ordering}; #[cfg(any(esp32, esp32c2))] use crate::rtc_cntl::RtcClock; @@ -275,38 +271,11 @@ impl Clock for ApbClock { } } -/// Frozen clock frequencies -/// -/// The instantiation of this type indicates that the clock configuration can no -/// longer be changed. -pub struct Clocks<'a> { - _private: PhantomData<&'a ()>, - rates: RawClocks, -} - -impl<'a> Clocks<'a> { - /// This should not be used in user code. - /// The whole point this exists is make it possible to have other crates - /// (i.e. esp-wifi) create `Clocks` - #[doc(hidden)] - pub(crate) fn from_raw_clocks(raw_clocks: RawClocks) -> Clocks<'a> { - Self { - _private: PhantomData, - rates: raw_clocks, - } - } -} - -impl core::ops::Deref for Clocks<'_> { - type Target = RawClocks; - - fn deref(&self) -> &RawClocks { - &self.rates - } -} - -/// The list of the clock frequencies that are used in the system. -pub struct RawClocks { +/// Clock frequencies. +#[derive(Debug, Clone, Copy)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[non_exhaustive] +pub struct Clocks { /// CPU clock frequency pub cpu_clock: HertzU32, @@ -341,51 +310,30 @@ pub struct RawClocks { pub pll_96m_clock: HertzU32, } -cfg_if::cfg_if! { - if #[cfg(esp32c2)] { - static XTAL_FREQ_MHZ: AtomicU32 = AtomicU32::new(40); +static mut ACTIVE_CLOCKS: Option = None; - pub(crate) fn xtal_freq_mhz() -> u32 { - XTAL_FREQ_MHZ.load(Ordering::Relaxed) - } - } else if #[cfg(esp32h2)] { - pub(crate) fn xtal_freq_mhz() -> u32 { - 32 - } - } else if #[cfg(any(esp32, esp32s2))] { - // Function would be unused - } else { - pub(crate) fn xtal_freq_mhz() -> u32 { - 40 - } - } -} - -/// Used to configure the frequencies of the clocks present in the chip. -/// -/// After setting all frequencies, call the freeze function to apply the -/// configuration. -pub struct ClockControl { - desired_rates: RawClocks, -} - -impl ClockControl { - pub(crate) fn new(clock: CpuClock) -> Self { - Self::configure(clock) +impl Clocks { + pub(crate) fn init(cpu_clock_speed: CpuClock) { + unsafe { ACTIVE_CLOCKS = Some(Self::configure(cpu_clock_speed)) }; } - /// Applies the clock configuration and returns a Clocks struct that - /// signifies that the clocks are frozen, and contains the frequencies - /// used. After this function is called, the clocks can not change - pub fn freeze(self) -> Clocks<'static> { - Clocks::from_raw_clocks(self.desired_rates) + /// Get the active clock configuration. + // This should be fine since we only allow reading after initialization. + // + // FIXME: technically, this needs to be unsafe to avoid requiring a critical + // section - we need the user to promise not to poll `Clocks::get` at the + // same time as `esp_hal::init` is running (e.g. initializing in an interrupt + // handler). Alternatively, we can require a peripheral reference (any) to be + // passed as those can only be returned by `esp_hal::init`. + pub fn get() -> &'static Clocks { + unwrap!(unsafe { ACTIVE_CLOCKS.as_ref() }) } } #[cfg(esp32)] -impl ClockControl { +impl Clocks { /// Configure the CPU clock speed. - pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { let xtal_freq = if RtcClock::estimate_xtal_frequency() > 33 { XtalClock::RtcXtalFreq40M } else { @@ -405,31 +353,28 @@ impl ClockControl { clocks_ll::set_cpu_freq(cpu_clock_speed); } - ClockControl { - desired_rates: RawClocks { - cpu_clock: cpu_clock_speed.frequency(), - apb_clock: HertzU32::MHz(80), - xtal_clock: HertzU32::MHz(xtal_freq.mhz()), - i2c_clock: HertzU32::MHz(80), - // The docs are unclear here. pwm_clock seems to be tied to clocks.apb_clock - // while simultaneously being fixed at 160 MHz. - // Testing showed 160 MHz to be correct for current clock configurations. - pwm_clock: HertzU32::MHz(160), - }, + Self { + cpu_clock: cpu_clock_speed.frequency(), + apb_clock: HertzU32::MHz(80), + xtal_clock: HertzU32::MHz(xtal_freq.mhz()), + i2c_clock: HertzU32::MHz(80), + // The docs are unclear here. pwm_clock seems to be tied to clocks.apb_clock + // while simultaneously being fixed at 160 MHz. + // Testing showed 160 MHz to be correct for current clock configurations. + pwm_clock: HertzU32::MHz(160), } } } #[cfg(esp32c2)] -impl ClockControl { +impl Clocks { /// Configure the CPU clock speed. - pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { let xtal_freq = if RtcClock::estimate_xtal_frequency() > 33 { XtalClock::RtcXtalFreq40M } else { XtalClock::RtcXtalFreq26M }; - XTAL_FREQ_MHZ.store(xtal_freq.mhz(), Ordering::Relaxed); let apb_freq; if cpu_clock_speed != CpuClock::default() { @@ -450,20 +395,18 @@ impl ClockControl { apb_freq = ApbClock::ApbFreq40MHz; } - ClockControl { - desired_rates: RawClocks { - cpu_clock: cpu_clock_speed.frequency(), - apb_clock: apb_freq.frequency(), - xtal_clock: xtal_freq.frequency(), - }, + Self { + cpu_clock: cpu_clock_speed.frequency(), + apb_clock: apb_freq.frequency(), + xtal_clock: xtal_freq.frequency(), } } } #[cfg(esp32c3)] -impl ClockControl { +impl Clocks { /// Configure the CPU clock speed. - pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { let xtal_freq = XtalClock::RtcXtalFreq40M; let apb_freq; @@ -484,20 +427,18 @@ impl ClockControl { apb_freq = ApbClock::ApbFreq80MHz; } - ClockControl { - desired_rates: RawClocks { - cpu_clock: cpu_clock_speed.frequency(), - apb_clock: apb_freq.frequency(), - xtal_clock: xtal_freq.frequency(), - }, + Self { + cpu_clock: cpu_clock_speed.frequency(), + apb_clock: apb_freq.frequency(), + xtal_clock: xtal_freq.frequency(), } } } #[cfg(esp32c6)] -impl ClockControl { +impl Clocks { /// Configure the CPU clock speed. - pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { let xtal_freq = XtalClock::RtcXtalFreq40M; let apb_freq; @@ -518,21 +459,19 @@ impl ClockControl { apb_freq = ApbClock::ApbFreq80MHz; } - ClockControl { - desired_rates: RawClocks { - cpu_clock: cpu_clock_speed.frequency(), - apb_clock: apb_freq.frequency(), - xtal_clock: xtal_freq.frequency(), - crypto_clock: HertzU32::MHz(160), - }, + Self { + cpu_clock: cpu_clock_speed.frequency(), + apb_clock: apb_freq.frequency(), + xtal_clock: xtal_freq.frequency(), + crypto_clock: HertzU32::MHz(160), } } } #[cfg(esp32h2)] -impl ClockControl { +impl Clocks { /// Configure the CPU clock speed. - pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { let xtal_freq = XtalClock::RtcXtalFreq32M; let apb_freq; @@ -553,52 +492,46 @@ impl ClockControl { apb_freq = ApbClock::ApbFreq32MHz; } - ClockControl { - desired_rates: RawClocks { - cpu_clock: cpu_clock_speed.frequency(), - apb_clock: apb_freq.frequency(), - xtal_clock: xtal_freq.frequency(), - pll_48m_clock: HertzU32::MHz(48), - crypto_clock: HertzU32::MHz(96), - pll_96m_clock: HertzU32::MHz(96), - }, + Self { + cpu_clock: cpu_clock_speed.frequency(), + apb_clock: apb_freq.frequency(), + xtal_clock: xtal_freq.frequency(), + pll_48m_clock: HertzU32::MHz(48), + crypto_clock: HertzU32::MHz(96), + pll_96m_clock: HertzU32::MHz(96), } } } #[cfg(esp32s2)] -impl ClockControl { +impl Clocks { /// Configure the CPU clock speed. - pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { if cpu_clock_speed != CpuClock::default() { clocks_ll::set_cpu_clock(cpu_clock_speed); } - ClockControl { - desired_rates: RawClocks { - cpu_clock: cpu_clock_speed.frequency(), - apb_clock: HertzU32::MHz(80), - xtal_clock: HertzU32::MHz(40), - }, + Self { + cpu_clock: cpu_clock_speed.frequency(), + apb_clock: HertzU32::MHz(80), + xtal_clock: HertzU32::MHz(40), } } } #[cfg(esp32s3)] -impl ClockControl { +impl Clocks { /// Configure the CPU clock speed. - pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { if cpu_clock_speed != CpuClock::default() { clocks_ll::set_cpu_clock(cpu_clock_speed); } - ClockControl { - desired_rates: RawClocks { - cpu_clock: cpu_clock_speed.frequency(), - apb_clock: HertzU32::MHz(80), - xtal_clock: HertzU32::MHz(40), - crypto_pwm_clock: HertzU32::MHz(160), - }, + Self { + cpu_clock: cpu_clock_speed.frequency(), + apb_clock: HertzU32::MHz(80), + xtal_clock: HertzU32::MHz(40), + crypto_pwm_clock: HertzU32::MHz(160), } } } diff --git a/esp-hal/src/delay.rs b/esp-hal/src/delay.rs index 4ce5d0d6421..4de0bcf19d8 100644 --- a/esp-hal/src/delay.rs +++ b/esp-hal/src/delay.rs @@ -22,7 +22,7 @@ #![doc = crate::before_snippet!()] //! # use esp_hal::delay::Delay; //! # use embedded_hal::delay::DelayNs; -//! let mut delay = Delay::new(&clocks); +//! let mut delay = Delay::new(); //! //! delay.delay_ms(1000 as u32); //! # } @@ -35,8 +35,6 @@ pub use fugit::MicrosDurationU64; -use crate::clock::Clocks; - /// Delay driver /// /// Uses the `SYSTIMER` peripheral internally for RISC-V devices, and the @@ -72,7 +70,7 @@ impl embedded_hal::delay::DelayNs for Delay { impl Delay { /// Creates a new `Delay` instance. // Do not remove the argument, it makes sure that the clocks are initialized. - pub fn new(_clocks: &Clocks<'_>) -> Self { + pub fn new() -> Self { Self {} } diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs index 7cfe3df7bf8..eba51c11714 100644 --- a/esp-hal/src/dma/mod.rs +++ b/esp-hal/src/dma/mod.rs @@ -34,7 +34,6 @@ //! peripherals.SPI2, //! 100.kHz(), //! SpiMode::Mode0, -//! &clocks //! ) //! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) //! .with_dma(dma_channel.configure( diff --git a/esp-hal/src/i2c.rs b/esp-hal/src/i2c.rs index 774f855c560..078e7fc8f0e 100644 --- a/esp-hal/src/i2c.rs +++ b/esp-hal/src/i2c.rs @@ -42,7 +42,6 @@ //! io.pins.gpio1, //! io.pins.gpio2, //! 100.kHz(), -//! &clocks, //! ); //! //! loop { @@ -303,7 +302,6 @@ where sda: impl Peripheral

+ 'd, scl: impl Peripheral

+ 'd, frequency: HertzU32, - clocks: &Clocks<'d>, timeout: Option, ) -> Self { crate::into_ref!(i2c, sda, scl); @@ -355,7 +353,7 @@ where crate::private::Internal, ); - i2c.peripheral.setup(frequency, clocks, timeout); + i2c.peripheral.setup(frequency, timeout); i2c } @@ -379,9 +377,8 @@ where sda: impl Peripheral

+ 'd, scl: impl Peripheral

+ 'd, frequency: HertzU32, - clocks: &Clocks<'d>, ) -> Self { - Self::new_with_timeout(i2c, sda, scl, frequency, clocks, None) + Self::new_with_timeout(i2c, sda, scl, frequency, None) } /// Create a new I2C instance with a custom timeout value. @@ -392,10 +389,9 @@ where sda: impl Peripheral

+ 'd, scl: impl Peripheral

+ 'd, frequency: HertzU32, - clocks: &Clocks<'d>, timeout: Option, ) -> Self { - Self::new_internal(i2c, sda, scl, frequency, clocks, timeout) + Self::new_internal(i2c, sda, scl, frequency, timeout) } } @@ -422,9 +418,8 @@ where sda: impl Peripheral

+ 'd, scl: impl Peripheral

+ 'd, frequency: HertzU32, - clocks: &Clocks<'d>, ) -> Self { - Self::new_with_timeout_async(i2c, sda, scl, frequency, clocks, None) + Self::new_with_timeout_async(i2c, sda, scl, frequency, None) } /// Create a new I2C instance with a custom timeout value. @@ -435,10 +430,9 @@ where sda: impl Peripheral

+ 'd, scl: impl Peripheral

+ 'd, frequency: HertzU32, - clocks: &Clocks<'d>, timeout: Option, ) -> Self { - let mut this = Self::new_internal(i2c, sda, scl, frequency, clocks, timeout); + let mut this = Self::new_internal(i2c, sda, scl, frequency, timeout); let handler = match T::I2C_NUMBER { 0 => asynch::i2c0_handler, @@ -1011,7 +1005,7 @@ pub trait Instance: crate::private::Sealed { /// Configures the I2C peripheral with the specified frequency, clocks, and /// optional timeout. - fn setup(&mut self, frequency: HertzU32, clocks: &Clocks<'_>, timeout: Option) { + fn setup(&mut self, frequency: HertzU32, timeout: Option) { self.register_block().ctr().modify(|_, w| unsafe { // Clear register w.bits(0) @@ -1043,6 +1037,7 @@ pub trait Instance: crate::private::Sealed { self.set_filter(Some(7), Some(7)); // Configure frequency + let clocks = Clocks::get(); cfg_if::cfg_if! { if #[cfg(esp32)] { self.set_frequency(clocks.i2c_clock.convert(), frequency, timeout); diff --git a/esp-hal/src/i2s.rs b/esp-hal/src/i2s.rs index 70598c88600..bdf80b99975 100644 --- a/esp-hal/src/i2s.rs +++ b/esp-hal/src/i2s.rs @@ -54,7 +54,6 @@ //! ), //! tx_descriptors, //! rx_descriptors, -//! &clocks, //! ); #![cfg_attr(not(esp32), doc = "let i2s = i2s.with_mclk(io.pins.gpio0);")] //! let mut i2s_rx = i2s.i2s_rx @@ -88,7 +87,6 @@ use private::*; #[cfg(any(esp32, esp32s3))] use crate::dma::I2s1Peripheral; use crate::{ - clock::Clocks, dma::{ dma_private::{DmaSupport, DmaSupportRx, DmaSupportTx}, Channel, @@ -350,7 +348,6 @@ where mut channel: Channel<'d, CH, DmaMode>, tx_descriptors: &'static mut [DmaDescriptor], rx_descriptors: &'static mut [DmaDescriptor], - clocks: &Clocks<'d>, ) -> Self { // on ESP32-C3 / ESP32-S3 and later RX and TX are independent and // could be configured totally independently but for now handle all @@ -359,12 +356,7 @@ where channel.tx.init_channel(); PeripheralClockControl::reset(I::get_peripheral()); PeripheralClockControl::enable(I::get_peripheral()); - I::set_clock(calculate_clock( - sample_rate, - 2, - data_format.channel_bits(), - clocks, - )); + I::set_clock(calculate_clock(sample_rate, 2, data_format.channel_bits())); I::configure(&standard, &data_format); I::set_master(); I::update(); @@ -457,7 +449,6 @@ where channel: Channel<'d, CH, DmaMode>, tx_descriptors: &'static mut [DmaDescriptor], rx_descriptors: &'static mut [DmaDescriptor], - clocks: &Clocks<'d>, ) -> Self where I: I2s0Instance, @@ -472,7 +463,6 @@ where channel, tx_descriptors, rx_descriptors, - clocks, ) } @@ -488,7 +478,6 @@ where channel: Channel<'d, CH, DmaMode>, tx_descriptors: &'static mut [DmaDescriptor], rx_descriptors: &'static mut [DmaDescriptor], - clocks: &Clocks<'d>, ) -> Self where I: I2s1Instance, @@ -502,7 +491,6 @@ where channel, tx_descriptors, rx_descriptors, - clocks, ) } @@ -901,7 +889,6 @@ mod private { #[cfg(any(esp32, esp32s3))] use crate::peripherals::{i2s1::RegisterBlock, I2S1}; use crate::{ - clock::Clocks, dma::{ChannelRx, ChannelTx, DmaChannel, DmaDescriptor, DmaPeripheral}, gpio::{InputPin, InputSignal, OutputPin, OutputSignal}, interrupt::InterruptHandler, @@ -2114,7 +2101,6 @@ mod private { sample_rate: impl Into, channels: u8, data_bits: u8, - _clocks: &Clocks<'_>, ) -> I2sClockDividers { // this loosely corresponds to `i2s_std_calculate_clock` and // `i2s_ll_tx_set_mclk` in esp-idf diff --git a/esp-hal/src/lcd_cam/cam.rs b/esp-hal/src/lcd_cam/cam.rs index a37a6f40fe3..6d59b76a33f 100644 --- a/esp-hal/src/lcd_cam/cam.rs +++ b/esp-hal/src/lcd_cam/cam.rs @@ -55,7 +55,6 @@ //! rx_descriptors, //! data_pins, //! 20u32.MHz(), -//! &clocks //! ) //! // Remove this for slave mode. //! .with_master_clock(mclk_pin) @@ -146,10 +145,10 @@ where descriptors: &'static mut [DmaDescriptor], _pins: P, frequency: HertzU32, - clocks: &Clocks<'d>, ) -> Self { let lcd_cam = cam.lcd_cam; + let clocks = Clocks::get(); let (i, divider) = calculate_clkm( frequency.to_Hz() as _, &[ diff --git a/esp-hal/src/lcd_cam/lcd/i8080.rs b/esp-hal/src/lcd_cam/lcd/i8080.rs index f3770d93853..4f8a7c8f7a7 100644 --- a/esp-hal/src/lcd_cam/lcd/i8080.rs +++ b/esp-hal/src/lcd_cam/lcd/i8080.rs @@ -50,7 +50,6 @@ //! tx_pins, //! 20.MHz(), //! Config::default(), -//! &clocks, //! ) //! .with_ctrl_pins(io.pins.gpio0, io.pins.gpio47); //! @@ -113,18 +112,17 @@ where mut pins: P, frequency: HertzU32, config: Config, - clocks: &Clocks<'d>, ) -> Self { let is_2byte_mode = size_of::() == 2; let lcd_cam = lcd.lcd_cam; + let clocks = Clocks::get(); // Due to https://www.espressif.com/sites/default/files/documentation/esp32-s3_errata_en.pdf // the LCD_PCLK divider must be at least 2. To make up for this the user // provided frequency is doubled to match. - let (i, divider) = calculate_clkm( - (frequency.to_Hz() * 2) as _, + (frequency.to_Hz() * 2 ) as _, &[ clocks.xtal_clock.to_Hz() as _, clocks.cpu_clock.to_Hz() as _, diff --git a/esp-hal/src/ledc/mod.rs b/esp-hal/src/ledc/mod.rs index 86a8f18a5fb..dc862b11045 100644 --- a/esp-hal/src/ledc/mod.rs +++ b/esp-hal/src/ledc/mod.rs @@ -33,7 +33,7 @@ //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let led = io.pins.gpio0; //! -//! let mut ledc = Ledc::new(peripherals.LEDC, &clocks); +//! let mut ledc = Ledc::new(peripherals.LEDC); //! ledc.set_global_slow_clock(LSGlobalClkSource::APBClk); //! //! let mut lstimer0 = ledc.get_timer::(timer::Number::Timer0); @@ -65,7 +65,6 @@ use self::{ timer::{Timer, TimerSpeed}, }; use crate::{ - clock::Clocks, gpio::OutputPin, peripheral::{Peripheral, PeripheralRef}, system::{Peripheral as PeripheralEnable, PeripheralClockControl}, @@ -85,7 +84,6 @@ pub enum LSGlobalClkSource { pub struct Ledc<'d> { _instance: PeripheralRef<'d, crate::peripherals::LEDC>, ledc: &'d crate::peripherals::ledc::RegisterBlock, - clock_control_config: &'d Clocks<'d>, } #[cfg(esp32)] @@ -112,21 +110,14 @@ impl Speed for LowSpeed { impl<'d> Ledc<'d> { /// Return a new LEDC - pub fn new( - _instance: impl Peripheral

+ 'd, - clock_control_config: &'d Clocks<'d>, - ) -> Self { + pub fn new(_instance: impl Peripheral

+ 'd) -> Self { crate::into_ref!(_instance); PeripheralClockControl::reset(PeripheralEnable::Ledc); PeripheralClockControl::enable(PeripheralEnable::Ledc); let ledc = unsafe { &*crate::peripherals::LEDC::ptr() }; - Ledc { - _instance, - ledc, - clock_control_config, - } + Ledc { _instance, ledc } } /// Set global slow clock source @@ -170,7 +161,7 @@ impl<'d> Ledc<'d> { /// Return a new timer pub fn get_timer(&self, number: timer::Number) -> Timer<'d, S> { - Timer::new(self.ledc, self.clock_control_config, number) + Timer::new(self.ledc, number) } /// Return a new channel diff --git a/esp-hal/src/ledc/timer.rs b/esp-hal/src/ledc/timer.rs index dee5876b9b4..ef3d7b7b630 100644 --- a/esp-hal/src/ledc/timer.rs +++ b/esp-hal/src/ledc/timer.rs @@ -184,7 +184,6 @@ pub trait TimerHW { /// Timer struct pub struct Timer<'a, S: TimerSpeed> { ledc: &'a crate::peripherals::ledc::RegisterBlock, - clock_control_config: &'a Clocks<'a>, number: Number, duty: Option, frequency: u32, @@ -256,15 +255,10 @@ where } impl<'a, S: TimerSpeed> Timer<'a, S> { - /// Create a new intance of a timer - pub fn new( - ledc: &'a ledc::RegisterBlock, - clock_control_config: &'a Clocks<'a>, - number: Number, - ) -> Self { + /// Create a new instance of a timer + pub fn new(ledc: &'a ledc::RegisterBlock, number: Number) -> Self { Timer { ledc, - clock_control_config, number, duty: None, frequency: 0u32, @@ -278,9 +272,12 @@ impl<'a, S: TimerSpeed> Timer<'a, S> { /// Timer HW implementation for LowSpeed timers impl<'a> TimerHW for Timer<'a, LowSpeed> { /// Get the current source timer frequency from the HW - fn get_freq_hw(&self) -> Option { - self.clock_source.map(|cs| match cs { - LSClockSource::APBClk => self.clock_control_config.apb_clock, + fn get_freq_hw(&self) -> Option { + self.clock_source.map(|source| match source { + LSClockSource::APBClk => { + let clocks = Clocks::get(); + clocks.apb_clock + } }) } @@ -322,10 +319,13 @@ impl<'a> TimerHW for Timer<'a, LowSpeed> { /// Update the timer in HW fn update_hw(&self) { - #[cfg(esp32)] - let tmr = self.ledc.lstimer(self.number as usize); - #[cfg(not(esp32))] - let tmr = self.ledc.timer(self.number as usize); + cfg_if::cfg_if! { + if #[cfg(esp32)] { + let tmr = self.ledc.lstimer(self.number as usize); + } else { + let tmr = self.ledc.timer(self.number as usize); + } + } tmr.conf().modify(|_, w| w.para_up().set_bit()); } @@ -336,8 +336,11 @@ impl<'a> TimerHW for Timer<'a, LowSpeed> { impl<'a> TimerHW for Timer<'a, HighSpeed> { /// Get the current source timer frequency from the HW fn get_freq_hw(&self) -> Option { - self.clock_source.map(|cs| match cs { - HSClockSource::APBClk => self.clock_control_config.apb_clock, + self.clock_source.map(|source| match source { + HSClockSource::APBClk => { + let clocks = Clocks::get(); + clocks.apb_clock + } }) } diff --git a/esp-hal/src/lib.rs b/esp-hal/src/lib.rs index 44886ba9766..0e5ef65b2bd 100644 --- a/esp-hal/src/lib.rs +++ b/esp-hal/src/lib.rs @@ -73,13 +73,13 @@ //! //! #[entry] //! fn main() -> ! { -//! let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); +//! let peripherals = esp_hal::init(esp_hal::Config::default()); //! //! // Set GPIO0 as an output, and set its state high initially. //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! let mut led = Output::new(io.pins.gpio0, Level::High); //! -//! let delay = Delay::new(&clocks); +//! let delay = Delay::new(); //! //! loop { //! led.toggle(); @@ -712,13 +712,13 @@ macro_rules! before_snippet { # loop {} # } # fn main() { -# let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); +# let peripherals = esp_hal::init(esp_hal::Config::default()); "# }; } use crate::{ - clock::{ClockControl, Clocks, CpuClock}, + clock::{Clocks, CpuClock}, peripherals::Peripherals, }; @@ -733,9 +733,10 @@ pub struct Config { /// Initialize the system. /// /// This function sets up the CPU clock and returns the peripherals and clocks. -pub fn init(config: Config) -> (Peripherals, Clocks<'static>) { +pub fn init(config: Config) -> Peripherals { let peripherals = Peripherals::take(); - let clocks = ClockControl::new(config.cpu_clock).freeze(); - (peripherals, clocks) + Clocks::init(config.cpu_clock); + + peripherals } diff --git a/esp-hal/src/mcpwm/mod.rs b/esp-hal/src/mcpwm/mod.rs index 0d1b1cfcd16..a4907be376f 100644 --- a/esp-hal/src/mcpwm/mod.rs +++ b/esp-hal/src/mcpwm/mod.rs @@ -60,11 +60,11 @@ //! // initialize peripheral #![cfg_attr( esp32h2, - doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40.MHz()).unwrap();" + doc = "let clock_cfg = PeripheralClockConfig::with_frequency(40.MHz()).unwrap();" )] #![cfg_attr( not(esp32h2), - doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32.MHz()).unwrap();" + doc = "let clock_cfg = PeripheralClockConfig::with_frequency(32.MHz()).unwrap();" )] //! let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg); //! @@ -87,7 +87,7 @@ //! # } //! ``` -use core::{marker::PhantomData, ops::Deref}; +use core::ops::Deref; use fugit::HertzU32; use operator::Operator; @@ -130,7 +130,7 @@ impl<'d, PWM: PwmPeripheral> McPwm<'d, PWM> { // clocks.crypto_pwm_clock normally is 160 MHz pub fn new( peripheral: impl Peripheral

+ 'd, - peripheral_clock: PeripheralClockConfig<'d>, + peripheral_clock: PeripheralClockConfig, ) -> Self { crate::into_ref!(peripheral); @@ -190,13 +190,12 @@ impl<'d, PWM: PwmPeripheral> McPwm<'d, PWM> { /// Clock configuration of the MCPWM peripheral #[derive(Copy, Clone)] -pub struct PeripheralClockConfig<'a> { +pub struct PeripheralClockConfig { frequency: HertzU32, prescaler: u8, - phantom: PhantomData<&'a Clocks<'a>>, } -impl<'a> PeripheralClockConfig<'a> { +impl PeripheralClockConfig { /// Get a clock configuration with the given prescaler. /// /// With standard system clock configurations the input clock to the MCPWM @@ -204,7 +203,8 @@ impl<'a> PeripheralClockConfig<'a> { /// /// The peripheral clock frequency is calculated as: /// `peripheral_clock = input_clock / (prescaler + 1)` - pub fn with_prescaler(clocks: &'a Clocks<'a>, prescaler: u8) -> Self { + pub fn with_prescaler(prescaler: u8) -> Self { + let clocks = Clocks::get(); cfg_if::cfg_if! { if #[cfg(esp32)] { let source_clock = clocks.pwm_clock; @@ -220,7 +220,6 @@ impl<'a> PeripheralClockConfig<'a> { Self { frequency: source_clock / (prescaler as u32 + 1), prescaler, - phantom: PhantomData, } } @@ -238,10 +237,8 @@ impl<'a> PeripheralClockConfig<'a> { /// Only divisors of the input clock (`160 Mhz / 1`, `160 Mhz / 2`, ..., /// `160 Mhz / 256`) are representable exactly. Other target frequencies /// will be rounded up to the next divisor. - pub fn with_frequency( - clocks: &'a Clocks<'a>, - target_freq: HertzU32, - ) -> Result { + pub fn with_frequency(target_freq: HertzU32) -> Result { + let clocks = Clocks::get(); cfg_if::cfg_if! { if #[cfg(esp32)] { let source_clock = clocks.pwm_clock; @@ -263,7 +260,7 @@ impl<'a> PeripheralClockConfig<'a> { return Err(FrequencyError); } - Ok(Self::with_prescaler(clocks, prescaler as u8)) + Ok(Self::with_prescaler(prescaler as u8)) } /// Get the peripheral clock frequency. @@ -288,7 +285,7 @@ impl<'a> PeripheralClockConfig<'a> { period: u16, mode: timer::PwmWorkingMode, prescaler: u8, - ) -> timer::TimerClockConfig<'a> { + ) -> timer::TimerClockConfig { timer::TimerClockConfig::with_prescaler(self, period, mode, prescaler) } @@ -306,7 +303,7 @@ impl<'a> PeripheralClockConfig<'a> { period: u16, mode: timer::PwmWorkingMode, target_freq: HertzU32, - ) -> Result, FrequencyError> { + ) -> Result { timer::TimerClockConfig::with_frequency(self, period, mode, target_freq) } } diff --git a/esp-hal/src/mcpwm/operator.rs b/esp-hal/src/mcpwm/operator.rs index b21a3e050ef..8f4a1536310 100644 --- a/esp-hal/src/mcpwm/operator.rs +++ b/esp-hal/src/mcpwm/operator.rs @@ -491,11 +491,11 @@ impl<'d, Pin: OutputPin, PWM: PwmPeripheral, const OP: u8, const IS_A: bool> /// true); #[cfg_attr( esp32h2, - doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40.MHz()).unwrap();" + doc = "let clock_cfg = PeripheralClockConfig::with_frequency(40.MHz()).unwrap();" )] #[cfg_attr( not(esp32h2), - doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32.MHz()).unwrap();" + doc = "let clock_cfg = PeripheralClockConfig::with_frequency(32.MHz()).unwrap();" )] /// let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg); /// diff --git a/esp-hal/src/mcpwm/timer.rs b/esp-hal/src/mcpwm/timer.rs index 340ebef33bd..5afe5a37426 100644 --- a/esp-hal/src/mcpwm/timer.rs +++ b/esp-hal/src/mcpwm/timer.rs @@ -8,10 +8,7 @@ use core::marker::PhantomData; use fugit::HertzU32; -use crate::{ - clock::Clocks, - mcpwm::{FrequencyError, PeripheralClockConfig, PwmPeripheral}, -}; +use crate::mcpwm::{FrequencyError, PeripheralClockConfig, PwmPeripheral}; /// A MCPWM timer /// @@ -47,7 +44,7 @@ impl Timer { /// /// The hardware supports writing these settings in sync with certain timer /// events but this HAL does not expose these for now. - pub fn start(&mut self, timer_config: TimerClockConfig<'_>) { + pub fn start(&mut self, timer_config: TimerClockConfig) { // write prescaler and period with immediate update method self.cfg0().write(|w| unsafe { w.prescale().bits(timer_config.prescaler); @@ -115,18 +112,17 @@ impl Timer { /// Use [`PeripheralClockConfig::timer_clock_with_prescaler`](super::PeripheralClockConfig::timer_clock_with_prescaler) or /// [`PeripheralClockConfig::timer_clock_with_frequency`](super::PeripheralClockConfig::timer_clock_with_frequency) to it. #[derive(Copy, Clone)] -pub struct TimerClockConfig<'a> { +pub struct TimerClockConfig { frequency: HertzU32, period: u16, period_updating_method: PeriodUpdatingMethod, prescaler: u8, mode: PwmWorkingMode, - phantom: PhantomData<&'a Clocks<'a>>, } -impl<'a> TimerClockConfig<'a> { +impl TimerClockConfig { pub(super) fn with_prescaler( - clock: &PeripheralClockConfig<'a>, + clock: &PeripheralClockConfig, period: u16, mode: PwmWorkingMode, prescaler: u8, @@ -144,12 +140,11 @@ impl<'a> TimerClockConfig<'a> { period, period_updating_method: PeriodUpdatingMethod::Immediately, mode, - phantom: PhantomData, } } pub(super) fn with_frequency( - clock: &PeripheralClockConfig<'a>, + clock: &PeripheralClockConfig, period: u16, mode: PwmWorkingMode, target_freq: HertzU32, @@ -178,7 +173,6 @@ impl<'a> TimerClockConfig<'a> { period, period_updating_method: PeriodUpdatingMethod::Immediately, mode, - phantom: PhantomData, }) } diff --git a/esp-hal/src/parl_io.rs b/esp-hal/src/parl_io.rs index 9cd74eb562a..c87be8ccb24 100644 --- a/esp-hal/src/parl_io.rs +++ b/esp-hal/src/parl_io.rs @@ -31,7 +31,6 @@ use peripheral::PeripheralRef; use private::*; use crate::{ - clock::Clocks, dma::{ dma_private::{DmaSupport, DmaSupportRx, DmaSupportTx}, Channel, @@ -1123,7 +1122,6 @@ where tx_descriptors: &'static mut [DmaDescriptor], rx_descriptors: &'static mut [DmaDescriptor], frequency: HertzU32, - _clocks: &Clocks<'d>, ) -> Result { internal_init(&mut dma_channel, frequency)?; @@ -1217,7 +1215,6 @@ where mut dma_channel: Channel<'d, CH, DM>, descriptors: &'static mut [DmaDescriptor], frequency: HertzU32, - _clocks: &Clocks<'d>, ) -> Result { internal_init(&mut dma_channel, frequency)?; @@ -1306,7 +1303,6 @@ where mut dma_channel: Channel<'d, CH, DM>, descriptors: &'static mut [DmaDescriptor], frequency: HertzU32, - _clocks: &Clocks<'d>, ) -> Result { internal_init(&mut dma_channel, frequency)?; diff --git a/esp-hal/src/peripheral.rs b/esp-hal/src/peripheral.rs index 1077dce9e38..bdba4866b27 100644 --- a/esp-hal/src/peripheral.rs +++ b/esp-hal/src/peripheral.rs @@ -287,8 +287,7 @@ mod peripheral_macros { impl Peripherals { /// Returns all the peripherals *once* #[inline] - pub fn take() -> Self { - + pub(crate) fn take() -> Self { #[no_mangle] static mut _ESP_HAL_DEVICE_PERIPHERALS: bool = false; diff --git a/esp-hal/src/rmt.rs b/esp-hal/src/rmt.rs index a858b3d02c5..e505d7d1688 100644 --- a/esp-hal/src/rmt.rs +++ b/esp-hal/src/rmt.rs @@ -55,12 +55,11 @@ //! # use esp_hal::rmt::TxChannelConfig; //! # use esp_hal::rmt::Rmt; //! # use esp_hal::gpio::Io; -//! # use esp_hal::clock::ClockControl; //! # use crate::esp_hal::rmt::TxChannelCreator; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); #![cfg_attr(esp32h2, doc = "let freq = 32.MHz();")] #![cfg_attr(not(esp32h2), doc = "let freq = 80.MHz();")] -//! let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap(); +//! let rmt = Rmt::new(peripherals.RMT, freq).unwrap(); //! let mut channel = rmt //! .channel0 //! .configure( @@ -86,7 +85,6 @@ use core::marker::PhantomData; use fugit::HertzU32; use crate::{ - clock::Clocks, gpio::{InputPin, OutputPin}, interrupt::InterruptHandler, peripheral::Peripheral, @@ -217,7 +215,6 @@ where pub(crate) fn new_internal( peripheral: impl Peripheral

+ 'd, frequency: HertzU32, - _clocks: &Clocks<'d>, ) -> Result { let me = Rmt::create(peripheral); @@ -233,7 +230,7 @@ where if #[cfg(any(esp32, esp32s2))] { self::chip_specific::configure_clock(); } else { - me.configure_clock(frequency, _clocks)?; + me.configure_clock(frequency)?; } } @@ -249,7 +246,7 @@ where } #[cfg(not(any(esp32, esp32s2)))] - fn configure_clock(&self, frequency: HertzU32, _clocks: &Clocks<'d>) -> Result<(), Error> { + fn configure_clock(&self, frequency: HertzU32) -> Result<(), Error> { let src_clock = crate::soc::constants::RMT_CLOCK_SRC_FREQ; if frequency > src_clock { @@ -273,9 +270,8 @@ impl<'d> Rmt<'d, crate::Blocking> { pub fn new( peripheral: impl Peripheral

+ 'd, frequency: HertzU32, - _clocks: &Clocks<'d>, ) -> Result { - Self::new_internal(peripheral, frequency, _clocks) + Self::new_internal(peripheral, frequency) } } @@ -292,9 +288,8 @@ impl<'d> Rmt<'d, crate::Async> { pub fn new_async( peripheral: impl Peripheral

+ 'd, frequency: HertzU32, - _clocks: &Clocks<'d>, ) -> Result { - let mut this = Self::new_internal(peripheral, frequency, _clocks)?; + let mut this = Self::new_internal(peripheral, frequency)?; this.internal_set_interrupt_handler(asynch::async_interrupt_handler); Ok(this) } diff --git a/esp-hal/src/rng.rs b/esp-hal/src/rng.rs index 903e5dac177..8e469bd43d5 100644 --- a/esp-hal/src/rng.rs +++ b/esp-hal/src/rng.rs @@ -143,7 +143,6 @@ impl rand_core::RngCore for Rng { /// # use esp_hal::analog::adc::{AdcConfig, Attenuation, Adc}; /// # use esp_hal::gpio::Io; /// -/// let mut peripherals = Peripherals::take(); /// let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); /// let mut buf = [0u8; 16]; /// diff --git a/esp-hal/src/rom/md5.rs b/esp-hal/src/rom/md5.rs index 43b5b7e7e72..985334104d0 100644 --- a/esp-hal/src/rom/md5.rs +++ b/esp-hal/src/rom/md5.rs @@ -36,7 +36,7 @@ //! # use core::writeln; //! # use core::fmt::Write; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); -//! # let mut uart0 = Uart::new(peripherals.UART0, &clocks, io.pins.gpio1, io.pins.gpio2).unwrap(); +//! # let mut uart0 = Uart::new(peripherals.UART0, io.pins.gpio1, io.pins.gpio2).unwrap(); //! # let data = "Dummy"; //! let d: md5::Digest = md5::compute(&data); //! writeln!(uart0, "{}", d); @@ -52,7 +52,7 @@ //! # use core::writeln; //! # use core::fmt::Write; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); -//! # let mut uart0 = Uart::new(peripherals.UART0, &clocks, io.pins.gpio1, io.pins.gpio2).unwrap(); +//! # let mut uart0 = Uart::new(peripherals.UART0, io.pins.gpio1, io.pins.gpio2).unwrap(); //! # let data0 = "Dummy"; //! # let data1 = "Dummy"; //! # diff --git a/esp-hal/src/rtc_cntl/mod.rs b/esp-hal/src/rtc_cntl/mod.rs index b9f40129602..bb27210630a 100644 --- a/esp-hal/src/rtc_cntl/mod.rs +++ b/esp-hal/src/rtc_cntl/mod.rs @@ -29,7 +29,7 @@ //! # use crate::esp_hal::prelude::_fugit_ExtU64; //! # use crate::esp_hal::InterruptConfigurable; //! static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); -//! let mut delay = Delay::new(&clocks); +//! let mut delay = Delay::new(); //! //! let mut rtc = Rtc::new(peripherals.LPWR); //! diff --git a/esp-hal/src/soc/esp32/cpu_control.rs b/esp-hal/src/soc/esp32/cpu_control.rs index 0bf03828969..974a216e405 100644 --- a/esp-hal/src/soc/esp32/cpu_control.rs +++ b/esp-hal/src/soc/esp32/cpu_control.rs @@ -15,7 +15,7 @@ //! # use esp_hal::prelude::*; //! static mut APP_CORE_STACK: Stack<8192> = Stack::new(); //! -//! # let delay = Delay::new(&clocks); +//! # let delay = Delay::new(); //! //! let counter = Mutex::new(RefCell::new(0)); //! diff --git a/esp-hal/src/soc/esp32/efuse/mod.rs b/esp-hal/src/soc/esp32/efuse/mod.rs index 63eff59fb7c..ab1e40073e1 100644 --- a/esp-hal/src/soc/esp32/efuse/mod.rs +++ b/esp-hal/src/soc/esp32/efuse/mod.rs @@ -29,7 +29,7 @@ //! # use core::writeln; //! # use core::fmt::Write; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); -//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); +//! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap(); //! let mac_address = Efuse::read_base_mac_address(); //! writeln!( //! serial_tx, diff --git a/esp-hal/src/soc/esp32c2/efuse/mod.rs b/esp-hal/src/soc/esp32c2/efuse/mod.rs index 93db7e33dca..3aeb5fc0a94 100644 --- a/esp-hal/src/soc/esp32c2/efuse/mod.rs +++ b/esp-hal/src/soc/esp32c2/efuse/mod.rs @@ -26,7 +26,7 @@ //! # use core::writeln; //! # use core::fmt::Write; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); -//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); +//! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap(); //! let mac_address = Efuse::read_base_mac_address(); //! writeln!( //! serial_tx, diff --git a/esp-hal/src/soc/esp32c3/efuse/mod.rs b/esp-hal/src/soc/esp32c3/efuse/mod.rs index 08d81adf092..f1f3b0e2fb5 100644 --- a/esp-hal/src/soc/esp32c3/efuse/mod.rs +++ b/esp-hal/src/soc/esp32c3/efuse/mod.rs @@ -27,7 +27,7 @@ //! # use core::writeln; //! # use core::fmt::Write; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); -//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); +//! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap(); //! let mac_address = Efuse::read_base_mac_address(); //! writeln!( //! serial_tx, diff --git a/esp-hal/src/soc/esp32c6/efuse/mod.rs b/esp-hal/src/soc/esp32c6/efuse/mod.rs index a49f21870c1..0caa975a253 100644 --- a/esp-hal/src/soc/esp32c6/efuse/mod.rs +++ b/esp-hal/src/soc/esp32c6/efuse/mod.rs @@ -27,7 +27,7 @@ //! # use core::writeln; //! # use core::fmt::Write; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); -//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); +//! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap(); //! let mac_address = Efuse::read_base_mac_address(); //! writeln!( //! serial_tx, diff --git a/esp-hal/src/soc/esp32h2/efuse/mod.rs b/esp-hal/src/soc/esp32h2/efuse/mod.rs index fbf928a8dec..73bdcd57b31 100644 --- a/esp-hal/src/soc/esp32h2/efuse/mod.rs +++ b/esp-hal/src/soc/esp32h2/efuse/mod.rs @@ -27,7 +27,7 @@ //! # use core::writeln; //! # use core::fmt::Write; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); -//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); +//! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap(); //! let mac_address = Efuse::read_base_mac_address(); //! writeln!( //! serial_tx, diff --git a/esp-hal/src/soc/esp32s2/efuse/mod.rs b/esp-hal/src/soc/esp32s2/efuse/mod.rs index bebbf7a1976..6dd75ceca7c 100644 --- a/esp-hal/src/soc/esp32s2/efuse/mod.rs +++ b/esp-hal/src/soc/esp32s2/efuse/mod.rs @@ -29,7 +29,7 @@ //! # use core::writeln; //! # use core::fmt::Write; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); -//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); +//! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap(); //! let mac_address = Efuse::read_base_mac_address(); //! writeln!( //! serial_tx, diff --git a/esp-hal/src/soc/esp32s3/cpu_control.rs b/esp-hal/src/soc/esp32s3/cpu_control.rs index be5b2ae03f0..1628dce2f87 100644 --- a/esp-hal/src/soc/esp32s3/cpu_control.rs +++ b/esp-hal/src/soc/esp32s3/cpu_control.rs @@ -13,7 +13,7 @@ //! # use esp_hal::cpu_control::{CpuControl, Stack}; //! # use core::{cell::RefCell, ptr::addr_of_mut}; //! # use critical_section::Mutex; -//! # let delay = Delay::new(&clocks); +//! # let delay = Delay::new(); //! static mut APP_CORE_STACK: Stack<8192> = Stack::new(); //! //! let counter = Mutex::new(RefCell::new(0)); diff --git a/esp-hal/src/soc/esp32s3/efuse/mod.rs b/esp-hal/src/soc/esp32s3/efuse/mod.rs index 79445ae675d..d4303daf85c 100644 --- a/esp-hal/src/soc/esp32s3/efuse/mod.rs +++ b/esp-hal/src/soc/esp32s3/efuse/mod.rs @@ -27,7 +27,7 @@ //! # use core::writeln; //! # use core::fmt::Write; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); -//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); +//! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap(); //! let mac_address = Efuse::read_base_mac_address(); //! writeln!( //! serial_tx, diff --git a/esp-hal/src/spi/master.rs b/esp-hal/src/spi/master.rs index c6a986928a9..c0c0287f06a 100644 --- a/esp-hal/src/spi/master.rs +++ b/esp-hal/src/spi/master.rs @@ -50,7 +50,6 @@ //! peripherals.SPI2, //! 100.kHz(), //! SpiMode::Mode0, -//! &clocks, //! ) //! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)); //! # } @@ -509,10 +508,9 @@ where spi: impl Peripheral

+ 'd, frequency: HertzU32, mode: SpiMode, - clocks: &Clocks<'d>, ) -> Spi<'d, T, FullDuplexMode> { crate::into_ref!(spi); - Self::new_internal(spi, frequency, mode, clocks) + Self::new_internal(spi, frequency, mode) } /// Assign the SCK (Serial Clock) pin for the SPI instance. @@ -612,7 +610,6 @@ where spi: PeripheralRef<'d, T>, frequency: HertzU32, mode: SpiMode, - clocks: &Clocks<'d>, ) -> Spi<'d, T, FullDuplexMode> { spi.reset_peripheral(); spi.enable_peripheral(); @@ -621,7 +618,7 @@ where spi, _mode: PhantomData, }; - spi.spi.setup(frequency, clocks); + spi.spi.setup(frequency); spi.spi.init(); spi.spi.set_data_mode(mode); @@ -632,8 +629,8 @@ where /// /// This method allows user to update the bus frequency for the SPI /// communication after the instance has been created. - pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'d>) { - self.spi.ch_bus_freq(frequency, clocks); + pub fn change_bus_frequency(&mut self, frequency: HertzU32) { + self.spi.ch_bus_freq(frequency); } } @@ -649,10 +646,9 @@ where spi: impl Peripheral

+ 'd, frequency: HertzU32, mode: SpiMode, - clocks: &Clocks<'d>, ) -> Spi<'d, T, HalfDuplexMode> { crate::into_ref!(spi); - Self::new_internal(spi, frequency, mode, clocks) + Self::new_internal(spi, frequency, mode) } /// Assign the SCK (Serial Clock) pin for the SPI instance. @@ -820,7 +816,6 @@ where spi: PeripheralRef<'d, T>, frequency: HertzU32, mode: SpiMode, - clocks: &Clocks<'d>, ) -> Spi<'d, T, HalfDuplexMode> { spi.reset_peripheral(); spi.enable_peripheral(); @@ -829,7 +824,7 @@ where spi, _mode: PhantomData, }; - spi.spi.setup(frequency, clocks); + spi.spi.setup(frequency); spi.spi.init(); spi.spi.set_data_mode(mode); @@ -840,8 +835,8 @@ where /// /// This method allows you to update the bus frequency for the SPI /// communication after the instance has been created. - pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'d>) { - self.spi.ch_bus_freq(frequency, clocks); + pub fn change_bus_frequency(&mut self, frequency: HertzU32) { + self.spi.ch_bus_freq(frequency); } /// Set the bit order for the SPI instance. @@ -1127,8 +1122,8 @@ mod dma { M: Mode, { /// Changes the SPI bus frequency for the DMA-enabled SPI instance. - pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'d>) { - self.spi.ch_bus_freq(frequency, clocks); + pub fn change_bus_frequency(&mut self, frequency: HertzU32) { + self.spi.ch_bus_freq(frequency); } } @@ -1645,9 +1640,9 @@ mod dma { } /// Changes the SPI bus frequency for the DMA-enabled SPI instance. - pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'d>) { + pub fn change_bus_frequency(&mut self, frequency: HertzU32) { let (mut spi_dma, tx_buf, rx_buf) = self.wait_for_idle(); - spi_dma.change_bus_frequency(frequency, clocks); + spi_dma.change_bus_frequency(frequency); self.state = State::Idle(spi_dma, tx_buf, rx_buf); } @@ -2831,7 +2826,8 @@ pub trait Instance: private::Sealed { } // taken from https://github.com/apache/incubator-nuttx/blob/8267a7618629838231256edfa666e44b5313348e/arch/risc-v/src/esp32c3/esp32c3_spi.c#L496 - fn setup(&mut self, frequency: HertzU32, clocks: &Clocks<'_>) { + fn setup(&mut self, frequency: HertzU32) { + let clocks = Clocks::get(); cfg_if::cfg_if! { if #[cfg(esp32h2)] { // ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK @@ -3033,7 +3029,7 @@ pub trait Instance: private::Sealed { self } - fn ch_bus_freq(&mut self, frequency: HertzU32, clocks: &Clocks<'_>) { + fn ch_bus_freq(&mut self, frequency: HertzU32) { // Disable clock source #[cfg(not(any(esp32, esp32s2)))] self.register_block().clk_gate().modify(|_, w| { @@ -3046,7 +3042,7 @@ pub trait Instance: private::Sealed { }); // Change clock frequency - self.setup(frequency, clocks); + self.setup(frequency); // Enable clock source #[cfg(not(any(esp32, esp32s2)))] diff --git a/esp-hal/src/timer/mod.rs b/esp-hal/src/timer/mod.rs index 90f6c5fd234..fa69e8b3898 100644 --- a/esp-hal/src/timer/mod.rs +++ b/esp-hal/src/timer/mod.rs @@ -18,7 +18,7 @@ #![doc = crate::before_snippet!()] //! # use esp_hal::timer::{OneShotTimer, PeriodicTimer, timg::TimerGroup}; //! # -//! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); +//! let timg0 = TimerGroup::new(peripherals.TIMG0); //! let one_shot = OneShotTimer::new(timg0.timer0); //! //! one_shot.delay_millis(500); @@ -30,7 +30,7 @@ #![doc = crate::before_snippet!()] //! # use esp_hal::timer::{PeriodicTimer, timg::TimerGroup}; //! # -//! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); +//! let timg0 = TimerGroup::new(peripherals.TIMG0); //! let mut periodic = PeriodicTimer::new(timg0.timer0); //! //! periodic.start(1.secs()); diff --git a/esp-hal/src/timer/systimer.rs b/esp-hal/src/timer/systimer.rs index 9f06162c626..149c05d26ac 100644 --- a/esp-hal/src/timer/systimer.rs +++ b/esp-hal/src/timer/systimer.rs @@ -129,21 +129,21 @@ impl<'d> SystemTimer<'d> { pub fn ticks_per_second() -> u64 { cfg_if::cfg_if! { if #[cfg(esp32s2)] { - 80_000_000 + const MULTIPLIER: u64 = 2_000_000; } else if #[cfg(esp32h2)] { // The counters and comparators are driven using `XTAL_CLK`. // The average clock frequency is fXTAL_CLK/2, which is 16 MHz. // The timer counting is incremented by 1/16 μs on each `CNT_CLK` cycle. const MULTIPLIER: u64 = 10_000_000 / 20; - crate::clock::xtal_freq_mhz() as u64 * MULTIPLIER } else { // The counters and comparators are driven using `XTAL_CLK`. // The average clock frequency is fXTAL_CLK/2.5, which is 16 MHz. // The timer counting is incremented by 1/16 μs on each `CNT_CLK` cycle. const MULTIPLIER: u64 = 10_000_000 / 25; - crate::clock::xtal_freq_mhz() as u64 * MULTIPLIER } } + let xtal_freq_mhz = crate::clock::Clocks::get().xtal_clock.to_MHz(); + xtal_freq_mhz as u64 * MULTIPLIER } /// Create a new instance. diff --git a/esp-hal/src/timer/timg.rs b/esp-hal/src/timer/timg.rs index 8421fe2816c..a3cab18ef92 100644 --- a/esp-hal/src/timer/timg.rs +++ b/esp-hal/src/timer/timg.rs @@ -28,7 +28,7 @@ #![doc = crate::before_snippet!()] //! # use esp_hal::timer::timg::TimerGroup; //! -//! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); +//! let timg0 = TimerGroup::new(peripherals.TIMG0); //! let timer0 = timg0.timer0; //! //! // Get the current timestamp, in microseconds: @@ -51,7 +51,7 @@ #![doc = crate::before_snippet!()] //! # use esp_hal::timer::timg::TimerGroup; //! -//! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); +//! let timg0 = TimerGroup::new(peripherals.TIMG0); //! let mut wdt = timg0.wdt; //! //! wdt.set_timeout(5_000.millis()); @@ -256,7 +256,7 @@ where DM: crate::Mode, { /// Construct a new instance of [`TimerGroup`] in blocking mode - pub fn new_inner(_timer_group: impl Peripheral

+ 'd, clocks: &Clocks<'d>) -> Self { + pub fn new_inner(_timer_group: impl Peripheral

+ 'd) -> Self { crate::into_ref!(_timer_group); T::reset_peripheral(); @@ -264,6 +264,7 @@ where T::configure_src_clk(); + let clocks = Clocks::get(); cfg_if::cfg_if! { if #[cfg(esp32h2)] { // ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK @@ -271,7 +272,7 @@ where } else { let apb_clk_freq = clocks.apb_clock; } - }; + } let timer0 = Timer::new( Timer0 { @@ -303,8 +304,8 @@ where T: TimerGroupInstance, { /// Construct a new instance of [`TimerGroup`] in blocking mode - pub fn new(timer_group: impl Peripheral

+ 'd, clocks: &Clocks<'d>) -> Self { - Self::new_inner(timer_group, clocks) + pub fn new(_timer_group: impl Peripheral

+ 'd) -> Self { + Self::new_inner(_timer_group) } } @@ -313,8 +314,8 @@ where T: TimerGroupInstance, { /// Construct a new instance of [`TimerGroup`] in asynchronous mode - pub fn new_async(timer_group: impl Peripheral

+ 'd, clocks: &Clocks<'d>) -> Self { - Self::new_inner(timer_group, clocks) + pub fn new_async(_timer_group: impl Peripheral

+ 'd) -> Self { + Self::new_inner(_timer_group) } } diff --git a/esp-hal/src/twai/mod.rs b/esp-hal/src/twai/mod.rs index 721a47fd225..75a6dcd54f0 100644 --- a/esp-hal/src/twai/mod.rs +++ b/esp-hal/src/twai/mod.rs @@ -50,7 +50,6 @@ //! peripherals.TWAI0, //! can_tx_pin, //! can_rx_pin, -//! &clocks, //! TWAI_BAUDRATE, //! TwaiMode::Normal //! ); @@ -105,7 +104,6 @@ //! peripherals.TWAI0, //! can_tx_pin, //! can_rx_pin, -//! &clocks, //! TWAI_BAUDRATE, //! TwaiMode::SelfTest //! ); @@ -135,7 +133,6 @@ use core::marker::PhantomData; use self::filter::{Filter, FilterType}; use crate::{ - clock::Clocks, gpio::{InputPin, InputSignal, OutputPin, OutputSignal}, interrupt::InterruptHandler, peripheral::{Peripheral, PeripheralRef}, @@ -723,7 +720,6 @@ where _peripheral: impl Peripheral

+ 'd, tx_pin: impl Peripheral

+ 'd, rx_pin: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, baud_rate: BaudRate, no_transceiver: bool, mode: TwaiMode, @@ -787,7 +783,7 @@ where phantom: PhantomData, }; - cfg.set_baud_rate(baud_rate, clocks); + cfg.set_baud_rate(baud_rate); cfg } @@ -801,11 +797,14 @@ where /// Set the bitrate of the bus. /// /// Note: The timings currently assume a APB_CLK of 80MHz. - fn set_baud_rate(&mut self, baud_rate: BaudRate, _clocks: &Clocks<'d>) { + fn set_baud_rate(&mut self, baud_rate: BaudRate) { // TWAI is clocked from the APB_CLK according to Table 6-4 [ESP32C3 Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf) // Included timings are all for 80MHz so assert that we are running at 80MHz. #[cfg(not(esp32c6))] - assert!(_clocks.apb_clock == fugit::HertzU32::MHz(80)); + { + let apb_clock = crate::clock::Clocks::get().apb_clock; + assert!(apb_clock == fugit::HertzU32::MHz(80)); + } // Unpack the baud rate timings and convert them to the values needed for the // register. Many of the registers have a minimum value of 1 which is @@ -908,11 +907,10 @@ where peripheral: impl Peripheral

+ 'd, tx_pin: impl Peripheral

+ 'd, rx_pin: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, baud_rate: BaudRate, mode: TwaiMode, ) -> Self { - Self::new_internal(peripheral, tx_pin, rx_pin, clocks, baud_rate, false, mode) + Self::new_internal(peripheral, tx_pin, rx_pin, baud_rate, false, mode) } /// Create a new instance of [TwaiConfiguration] meant to connect two ESP32s @@ -924,11 +922,10 @@ where peripheral: impl Peripheral

+ 'd, tx_pin: impl Peripheral

+ 'd, rx_pin: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, baud_rate: BaudRate, mode: TwaiMode, ) -> Self { - Self::new_internal(peripheral, tx_pin, rx_pin, clocks, baud_rate, true, mode) + Self::new_internal(peripheral, tx_pin, rx_pin, baud_rate, true, mode) } } @@ -954,12 +951,10 @@ where peripheral: impl Peripheral

+ 'd, tx_pin: impl Peripheral

+ 'd, rx_pin: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, baud_rate: BaudRate, mode: TwaiMode, ) -> Self { - let mut this = - Self::new_internal(peripheral, tx_pin, rx_pin, clocks, baud_rate, false, mode); + let mut this = Self::new_internal(peripheral, tx_pin, rx_pin, baud_rate, false, mode); this.internal_set_interrupt_handler(T::async_handler()); this } @@ -973,12 +968,10 @@ where peripheral: impl Peripheral

+ 'd, tx_pin: impl Peripheral

+ 'd, rx_pin: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, baud_rate: BaudRate, mode: TwaiMode, ) -> Self { - let mut this = - Self::new_internal(peripheral, tx_pin, rx_pin, clocks, baud_rate, true, mode); + let mut this = Self::new_internal(peripheral, tx_pin, rx_pin, baud_rate, true, mode); this.internal_set_interrupt_handler(T::async_handler()); this } diff --git a/esp-hal/src/uart.rs b/esp-hal/src/uart.rs index 5427a2f8668..c7b11fd3054 100644 --- a/esp-hal/src/uart.rs +++ b/esp-hal/src/uart.rs @@ -29,7 +29,6 @@ //! //! let mut uart1 = Uart::new( //! peripherals.UART1, -//! &clocks, //! io.pins.gpio1, //! io.pins.gpio2, //! ).unwrap(); @@ -62,7 +61,6 @@ //! # let mut uart1 = Uart::new_with_config( //! # peripherals.UART1, //! # Config::default(), -//! # &clocks, //! # io.pins.gpio1, //! # io.pins.gpio2, //! # ).unwrap(); @@ -80,7 +78,6 @@ //! # let mut uart1 = Uart::new_with_config( //! # peripherals.UART1, //! # Config::default(), -//! # &clocks, //! # io.pins.gpio1, //! # io.pins.gpio2, //! # ).unwrap(); @@ -105,7 +102,6 @@ //! let rx = AnyPin::new_inverted(io.pins.gpio2); //! let mut uart1 = Uart::new( //! peripherals.UART1, -//! &clocks, //! tx, //! rx, //! ).unwrap(); @@ -120,10 +116,8 @@ //! //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! -//! let tx = UartTx::new(peripherals.UART0, &clocks, -//! io.pins.gpio1).unwrap(); -//! let rx = UartRx::new(peripherals.UART1, &clocks, -//! io.pins.gpio2).unwrap(); +//! let tx = UartTx::new(peripherals.UART0, io.pins.gpio1).unwrap(); +//! let rx = UartRx::new(peripherals.UART1, io.pins.gpio2).unwrap(); //! # } //! ``` //! @@ -579,10 +573,9 @@ where /// Create a new UART TX instance in [`Blocking`] mode. pub fn new( uart: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, tx: impl Peripheral

+ 'd, ) -> Result { - Self::new_with_config(uart, Default::default(), clocks, tx) + Self::new_with_config(uart, Default::default(), tx) } /// Create a new UART TX instance with configuration options in @@ -590,15 +583,13 @@ where pub fn new_with_config( uart: impl Peripheral

+ 'd, config: Config, - clocks: &Clocks<'d>, tx: impl Peripheral

+ 'd, ) -> Result { crate::into_ref!(tx); tx.set_to_push_pull_output(Internal); tx.connect_peripheral_to_output(T::tx_signal(), Internal); - let (uart_tx, _) = - Uart::<'d, T, Blocking>::new_with_config_inner(uart, config, clocks)?.split(); + let (uart_tx, _) = Uart::<'d, T, Blocking>::new_with_config_inner(uart, config)?.split(); Ok(uart_tx) } @@ -787,10 +778,9 @@ where /// Create a new UART RX instance in [`Blocking`] mode. pub fn new( uart: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, rx: impl Peripheral

+ 'd, ) -> Result { - Self::new_with_config(uart, Default::default(), clocks, rx) + Self::new_with_config(uart, Default::default(), rx) } /// Create a new UART RX instance with configuration options in @@ -798,15 +788,13 @@ where pub fn new_with_config( uart: impl Peripheral

+ 'd, config: Config, - clocks: &Clocks<'d>, rx: impl Peripheral

+ 'd, ) -> Result { crate::into_ref!(rx); rx.set_to_input(Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal); - let (_, uart_rx) = - Uart::<'d, T, Blocking>::new_with_config_inner(uart, config, clocks)?.split(); + let (_, uart_rx) = Uart::<'d, T, Blocking>::new_with_config_inner(uart, config)?.split(); Ok(uart_rx) } @@ -821,7 +809,6 @@ where pub fn new_with_config( uart: impl Peripheral

+ 'd, config: Config, - clocks: &Clocks<'d>, tx: impl Peripheral

+ 'd, rx: impl Peripheral

+ 'd, ) -> Result { @@ -832,13 +819,12 @@ where rx.set_to_input(Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal); - Self::new_with_config_inner(uart, config, clocks) + Self::new_with_config_inner(uart, config) } /// Create a new UART instance with defaults in [`Blocking`] mode. pub fn new( uart: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, tx: impl Peripheral

+ 'd, rx: impl Peripheral

+ 'd, ) -> Result { @@ -849,14 +835,13 @@ where rx.set_to_input(Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal); - Self::new_inner(uart, clocks) + Self::new_inner(uart) } /// Create a new UART instance with defaults in [`Blocking`] mode. /// Verify that the default pins (DefaultTxPin and DefaultRxPin) are used. pub fn new_with_default_pins( uart: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, tx: &mut DefaultTxPin, rx: &mut DefaultRxPin, ) -> Result { @@ -865,7 +850,7 @@ where rx.set_to_input(Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal); - Self::new_inner(uart, clocks) + Self::new_inner(uart) } } @@ -877,7 +862,6 @@ where pub(crate) fn new_with_config_inner( _uart: impl Peripheral

+ 'd, config: Config, - clocks: &Clocks<'d>, ) -> Result { Self::init(); @@ -893,7 +877,7 @@ where .rx .set_rx_fifo_full_threshold(config.rx_fifo_full_threshold)?; serial.rx.set_rx_timeout(config.rx_timeout)?; - serial.change_baud_internal(config.baudrate, config.clock_source, clocks); + serial.change_baud_internal(config.baudrate, config.clock_source); serial.change_data_bits(config.data_bits); serial.change_parity(config.parity); serial.change_stop_bits(config.stop_bits); @@ -925,8 +909,8 @@ where } } - fn new_inner(uart: impl Peripheral

+ 'd, clocks: &Clocks<'d>) -> Result { - Self::new_with_config_inner(uart, Default::default(), clocks) + fn new_inner(uart: impl Peripheral

+ 'd) -> Result { + Self::new_with_config_inner(uart, Default::default()) } /// Configure CTS pin @@ -1157,7 +1141,8 @@ where } #[cfg(any(esp32c2, esp32c3, esp32s3))] - fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource, clocks: &Clocks<'d>) { + fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource) { + let clocks = Clocks::get(); let clk = match clock_source { ClockSource::Apb => clocks.apb_clock.to_Hz(), ClockSource::Xtal => clocks.xtal_clock.to_Hz(), @@ -1194,7 +1179,8 @@ where } #[cfg(any(esp32c6, esp32h2))] - fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource, clocks: &Clocks<'d>) { + fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource) { + let clocks = Clocks::get(); let clk = match clock_source { ClockSource::Apb => clocks.apb_clock.to_Hz(), ClockSource::Xtal => clocks.xtal_clock.to_Hz(), @@ -1265,11 +1251,12 @@ where } #[cfg(any(esp32, esp32s2))] - fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource, clocks: &Clocks<'d>) { + fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource) { + let clocks = Clocks::get(); let clk = match clock_source { ClockSource::Apb => clocks.apb_clock.to_Hz(), ClockSource::RefTick => REF_TICK.to_Hz(), /* ESP32(/-S2) TRM, section 3.2.4.2 - * (6.2.4.2 for S2) */ + * (6.2.4.2 for S2) */ }; T::register_block().conf0().modify(|_, w| { @@ -1304,8 +1291,8 @@ where } /// Modify UART baud rate and reset TX/RX fifo. - pub fn change_baud(&mut self, baudrate: u32, clock_source: ClockSource, clocks: &Clocks<'d>) { - self.change_baud_internal(baudrate, clock_source, clocks); + pub fn change_baud(&mut self, baudrate: u32, clock_source: ClockSource) { + self.change_baud_internal(baudrate, clock_source); self.txfifo_reset(); self.rxfifo_reset(); } @@ -2146,7 +2133,6 @@ mod asynch { pub fn new_async_with_config( uart: impl Peripheral

+ 'd, config: Config, - clocks: &Clocks<'d>, tx: impl Peripheral

+ 'd, rx: impl Peripheral

+ 'd, ) -> Result { @@ -2157,7 +2143,7 @@ mod asynch { rx.set_to_input(Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal); - let mut this = Self::new_with_config_inner(uart, config, clocks)?; + let mut this = Self::new_with_config_inner(uart, config)?; this.inner_set_interrupt_handler(match T::uart_number() { #[cfg(uart0)] @@ -2175,21 +2161,19 @@ mod asynch { /// Create a new UART instance with defaults in [`Async`] mode. pub fn new_async( uart: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, tx: impl Peripheral

+ 'd, rx: impl Peripheral

+ 'd, ) -> Result { - Self::new_async_with_config(uart, Default::default(), clocks, tx, rx) + Self::new_async_with_config(uart, Default::default(), tx, rx) } /// Create a new UART instance with defaults in [`Async`] mode. pub fn new_async_with_default_pins( uart: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, tx: DefaultTxPin, rx: DefaultRxPin, ) -> Result { - Self::new_async_with_config(uart, Default::default(), clocks, tx, rx) + Self::new_async_with_config(uart, Default::default(), tx, rx) } } @@ -2221,10 +2205,9 @@ mod asynch { /// Create a new UART TX instance in [`Async`] mode. pub fn new_async( uart: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, tx: impl Peripheral

+ 'd, ) -> Result { - Self::new_async_with_config(uart, Default::default(), clocks, tx) + Self::new_async_with_config(uart, Default::default(), tx) } /// Create a new UART TX instance with configuration options in @@ -2232,14 +2215,13 @@ mod asynch { pub fn new_async_with_config( uart: impl Peripheral

+ 'd, config: Config, - clocks: &Clocks<'d>, tx: impl Peripheral

+ 'd, ) -> Result { crate::into_ref!(tx); tx.set_to_push_pull_output(Internal); tx.connect_peripheral_to_output(T::tx_signal(), Internal); - let mut uart = Uart::<'d, T, Async>::new_with_config_inner(uart, config, clocks)?; + let mut uart = Uart::<'d, T, Async>::new_with_config_inner(uart, config)?; uart.inner_set_interrupt_handler(match T::uart_number() { #[cfg(uart0)] @@ -2308,10 +2290,9 @@ mod asynch { /// Create a new UART RX instance in [`Async`] mode. pub fn new_async( uart: impl Peripheral

+ 'd, - clocks: &Clocks<'d>, rx: impl Peripheral

+ 'd, ) -> Result { - Self::new_async_with_config(uart, Default::default(), clocks, rx) + Self::new_async_with_config(uart, Default::default(), rx) } /// Create a new UART RX instance with configuration options in @@ -2319,14 +2300,13 @@ mod asynch { pub fn new_async_with_config( uart: impl Peripheral

+ 'd, config: Config, - clocks: &Clocks<'d>, rx: impl Peripheral

+ 'd, ) -> Result { crate::into_ref!(rx); rx.set_to_input(Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal); - let mut uart = Uart::<'d, T, Async>::new_with_config_inner(uart, config, clocks)?; + let mut uart = Uart::<'d, T, Async>::new_with_config_inner(uart, config)?; uart.inner_set_interrupt_handler(match T::uart_number() { #[cfg(uart0)] diff --git a/esp-wifi/src/lib.rs b/esp-wifi/src/lib.rs index cac6719ca92..5d8027bd037 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -293,13 +293,12 @@ impl EspWifiTimerSource for TimeBase { /// use esp_hal::{rng::Rng, timg::TimerGroup}; /// use esp_wifi::EspWifiInitFor; /// -/// let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); +/// let timg0 = TimerGroup::new(peripherals.TIMG0); /// let init = esp_wifi::initialize( /// EspWifiInitFor::Wifi, /// timg0.timer0, /// Rng::new(peripherals.RNG), /// peripherals.RADIO_CLK, -/// &clocks, /// ) /// .unwrap(); /// # } @@ -309,10 +308,10 @@ pub fn initialize( timer: impl EspWifiTimerSource, rng: hal::rng::Rng, radio_clocks: hal::peripherals::RADIO_CLK, - clocks: &Clocks, ) -> Result { // A minimum clock of 80MHz is required to operate WiFi module. const MIN_CLOCK: u32 = 80; + let clocks = Clocks::get(); if clocks.cpu_clock < MegahertzU32::MHz(MIN_CLOCK) { return Err(InitializationError::WrongClockConfig); } diff --git a/examples/src/bin/adc.rs b/examples/src/bin/adc.rs index 1c9413e2c26..08fe4b3786a 100644 --- a/examples/src/bin/adc.rs +++ b/examples/src/bin/adc.rs @@ -27,7 +27,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); cfg_if::cfg_if! { @@ -45,7 +45,7 @@ fn main() -> ! { let mut adc1_pin = adc1_config.enable_pin(analog_pin, Attenuation::Attenuation11dB); let mut adc1 = Adc::new(peripherals.ADC1, adc1_config); - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap(); diff --git a/examples/src/bin/adc_cal.rs b/examples/src/bin/adc_cal.rs index 1466e01cc46..a025a6ba52f 100644 --- a/examples/src/bin/adc_cal.rs +++ b/examples/src/bin/adc_cal.rs @@ -23,7 +23,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); cfg_if::cfg_if! { @@ -49,7 +49,7 @@ fn main() -> ! { adc1_config.enable_pin_with_cal::<_, AdcCal>(analog_pin, Attenuation::Attenuation11dB); let mut adc1 = Adc::new(peripherals.ADC1, adc1_config); - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { let pin_mv = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap(); diff --git a/examples/src/bin/advanced_serial.rs b/examples/src/bin/advanced_serial.rs index b4a3760189f..b0c4e8d90b3 100644 --- a/examples/src/bin/advanced_serial.rs +++ b/examples/src/bin/advanced_serial.rs @@ -19,13 +19,13 @@ use nb::block; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let mut serial1 = Uart::new(peripherals.UART1, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); + let mut serial1 = Uart::new(peripherals.UART1, io.pins.gpio4, io.pins.gpio5).unwrap(); - let delay = Delay::new(&clocks); + let delay = Delay::new(); println!("Start"); loop { diff --git a/examples/src/bin/blinky.rs b/examples/src/bin/blinky.rs index 114854599eb..f863b8b19b8 100644 --- a/examples/src/bin/blinky.rs +++ b/examples/src/bin/blinky.rs @@ -17,13 +17,13 @@ use esp_hal::{ #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); // Set GPIO0 as an output, and set its state high initially. let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let mut led = Output::new(io.pins.gpio0, Level::High); - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { led.toggle(); diff --git a/examples/src/bin/blinky_erased_pins.rs b/examples/src/bin/blinky_erased_pins.rs index 65204583333..c34d3d12158 100644 --- a/examples/src/bin/blinky_erased_pins.rs +++ b/examples/src/bin/blinky_erased_pins.rs @@ -20,7 +20,7 @@ use esp_hal::{ #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -39,7 +39,7 @@ fn main() -> ! { let mut pins = [led1, led2, led3]; - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { toggle_pins(&mut pins, &button); diff --git a/examples/src/bin/dac.rs b/examples/src/bin/dac.rs index 825600c09a5..d83740d97da 100644 --- a/examples/src/bin/dac.rs +++ b/examples/src/bin/dac.rs @@ -23,7 +23,7 @@ use esp_hal::{analog::dac::Dac, delay::Delay, gpio::Io, prelude::*}; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -41,7 +41,7 @@ fn main() -> ! { let mut dac1 = Dac::new(peripherals.DAC1, dac1_pin); let mut dac2 = Dac::new(peripherals.DAC2, dac2_pin); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut voltage_dac1: u8 = 200; let mut voltage_dac2: u8 = 255; diff --git a/examples/src/bin/debug_assist.rs b/examples/src/bin/debug_assist.rs index 3a39b30cb7e..639037f5cfe 100644 --- a/examples/src/bin/debug_assist.rs +++ b/examples/src/bin/debug_assist.rs @@ -18,7 +18,7 @@ static DA: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut da = DebugAssist::new(peripherals.ASSIST_DEBUG); da.set_interrupt_handler(interrupt_handler); diff --git a/examples/src/bin/dma_extmem2mem.rs b/examples/src/bin/dma_extmem2mem.rs index fcc4832b93a..36afe71a825 100644 --- a/examples/src/bin/dma_extmem2mem.rs +++ b/examples/src/bin/dma_extmem2mem.rs @@ -62,10 +62,10 @@ fn init_heap(psram: impl esp_hal::peripheral::Peripheral

! { esp_println::logger::init_logger(log::LevelFilter::Info); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); init_heap(peripherals.PSRAM); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut extram_buffer: &mut [u8] = dma_alloc_buffer!(DATA_SIZE, 64); let mut intram_buffer = dma_buffer_aligned!(DATA_SIZE, A64); diff --git a/examples/src/bin/dma_mem2mem.rs b/examples/src/bin/dma_mem2mem.rs index 39f7a02f434..e830359e99e 100644 --- a/examples/src/bin/dma_mem2mem.rs +++ b/examples/src/bin/dma_mem2mem.rs @@ -21,9 +21,9 @@ const DATA_SIZE: usize = 1024 * 10; fn main() -> ! { esp_println::logger::init_logger(log::LevelFilter::Info); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let (tx_buffer, tx_descriptors, mut rx_buffer, rx_descriptors) = dma_buffers!(DATA_SIZE); diff --git a/examples/src/bin/embassy_hello_world.rs b/examples/src/bin/embassy_hello_world.rs index 9b47ccf416c..d4087d59b2c 100644 --- a/examples/src/bin/embassy_hello_world.rs +++ b/examples/src/bin/embassy_hello_world.rs @@ -25,12 +25,12 @@ async fn run() { #[esp_hal_embassy::main] async fn main(spawner: Spawner) { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); esp_println::println!("Init!"); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); spawner.spawn(run()).ok(); diff --git a/examples/src/bin/embassy_i2c.rs b/examples/src/bin/embassy_i2c.rs index b95a17b5b57..f9352e1fda5 100644 --- a/examples/src/bin/embassy_i2c.rs +++ b/examples/src/bin/embassy_i2c.rs @@ -24,20 +24,14 @@ use lis3dh_async::{Lis3dh, Range, SlaveAddr}; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let i2c0 = I2C::new_async( - peripherals.I2C0, - io.pins.gpio4, - io.pins.gpio5, - 400.kHz(), - &clocks, - ); + let i2c0 = I2C::new_async(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 400.kHz()); let mut lis3dh = Lis3dh::new_i2c(i2c0, SlaveAddr::Alternate).await.unwrap(); lis3dh.set_range(Range::G8).await.unwrap(); diff --git a/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs b/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs index 10c4279d873..f1e5299f171 100644 --- a/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs +++ b/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs @@ -1,4 +1,4 @@ -//! Embassy "async" vesrion of ead calibration data from BMP180 sensor +//! Embassy "async" version of ead calibration data from BMP180 sensor //! //! This example dumps the calibration data from a BMP180 sensor by reading by reading //! with the direct I2C API and the embedded-hal-async I2C API. @@ -24,20 +24,14 @@ use esp_hal::{gpio::Io, i2c::I2C, prelude::*, timer::timg::TimerGroup}; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let mut i2c = I2C::new_async( - peripherals.I2C0, - io.pins.gpio4, - io.pins.gpio5, - 400.kHz(), - &clocks, - ); + let mut i2c = I2C::new_async(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 400.kHz()); loop { let mut data = [0u8; 22]; diff --git a/examples/src/bin/embassy_i2s_read.rs b/examples/src/bin/embassy_i2s_read.rs index db5e9623dc3..3bb9dff298d 100644 --- a/examples/src/bin/embassy_i2s_read.rs +++ b/examples/src/bin/embassy_i2s_read.rs @@ -1,4 +1,4 @@ -//! This shows how to continously receive data via I2S. +//! This shows how to continuously receive data via I2S. //! //! Without an additional I2S source device you can connect 3V3 or GND to DIN //! to read 0 or 0xFF or connect DIN to WS to read two different values. @@ -32,10 +32,10 @@ use esp_println::println; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { println!("Init!"); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -55,7 +55,6 @@ async fn main(_spawner: Spawner) { dma_channel.configure_for_async(false, DmaPriority::Priority0), tx_descriptors, rx_descriptors, - &clocks, ); #[cfg(not(feature = "esp32"))] diff --git a/examples/src/bin/embassy_i2s_sound.rs b/examples/src/bin/embassy_i2s_sound.rs index 2781f787090..295215713b5 100644 --- a/examples/src/bin/embassy_i2s_sound.rs +++ b/examples/src/bin/embassy_i2s_sound.rs @@ -1,4 +1,4 @@ -//! This shows how to transmit data continously via I2S. +//! This shows how to transmit data continuously via I2S. //! //! Without an additional I2S sink device you can inspect the BCLK, WS //! and DOUT with a logic analyzer. @@ -54,10 +54,10 @@ const SINE: [i16; 64] = [ #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { println!("Init!"); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -77,7 +77,6 @@ async fn main(_spawner: Spawner) { dma_channel.configure_for_async(false, DmaPriority::Priority0), tx_descriptors, rx_descriptors, - &clocks, ); let i2s_tx = i2s diff --git a/examples/src/bin/embassy_multicore.rs b/examples/src/bin/embassy_multicore.rs index 872d0846e3d..ddebf657f27 100644 --- a/examples/src/bin/embassy_multicore.rs +++ b/examples/src/bin/embassy_multicore.rs @@ -51,14 +51,14 @@ async fn control_led( #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let timer0: ErasedTimer = timg0.timer0.into(); let timer1: ErasedTimer = timg0.timer1.into(); - esp_hal_embassy::init(&clocks, [timer0, timer1]); + esp_hal_embassy::init([timer0, timer1]); let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL); diff --git a/examples/src/bin/embassy_multicore_interrupt.rs b/examples/src/bin/embassy_multicore_interrupt.rs index 48c72e8e894..23fa2ee0d1c 100644 --- a/examples/src/bin/embassy_multicore_interrupt.rs +++ b/examples/src/bin/embassy_multicore_interrupt.rs @@ -71,16 +71,16 @@ async fn enable_disable_led(control: &'static Signal ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let timer0: ErasedTimer = timg0.timer0.into(); let timer1: ErasedTimer = timg0.timer1.into(); - esp_hal_embassy::init(&clocks, [timer0, timer1]); + esp_hal_embassy::init([timer0, timer1]); let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL); diff --git a/examples/src/bin/embassy_multiprio.rs b/examples/src/bin/embassy_multiprio.rs index d6f52df36d2..f664277b019 100644 --- a/examples/src/bin/embassy_multiprio.rs +++ b/examples/src/bin/embassy_multiprio.rs @@ -71,11 +71,11 @@ async fn main(low_prio_spawner: Spawner) { esp_println::logger::init_logger_from_env(); println!("Init!"); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let timer0: ErasedTimer = timg0.timer0.into(); cfg_if::cfg_if! { @@ -84,12 +84,12 @@ async fn main(low_prio_spawner: Spawner) { let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); let timer1: ErasedTimer = systimer.alarm0.into(); } else { - let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); + let timg1 = TimerGroup::new(peripherals.TIMG1); let timer1: ErasedTimer = timg1.timer0.into(); } } - esp_hal_embassy::init(&clocks, [timer0, timer1]); + esp_hal_embassy::init([timer0, timer1]); static EXECUTOR: StaticCell> = StaticCell::new(); let executor = InterruptExecutor::new(sw_ints.software_interrupt2); diff --git a/examples/src/bin/embassy_parl_io_rx.rs b/examples/src/bin/embassy_parl_io_rx.rs index 13bf5c4a69a..7293e8e0f8c 100644 --- a/examples/src/bin/embassy_parl_io_rx.rs +++ b/examples/src/bin/embassy_parl_io_rx.rs @@ -26,10 +26,10 @@ use esp_println::println; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -45,7 +45,6 @@ async fn main(_spawner: Spawner) { dma_channel.configure_for_async(false, DmaPriority::Priority0), rx_descriptors, 1.MHz(), - &clocks, ) .unwrap(); diff --git a/examples/src/bin/embassy_parl_io_tx.rs b/examples/src/bin/embassy_parl_io_tx.rs index 5fed54f90c3..a273032a8dd 100644 --- a/examples/src/bin/embassy_parl_io_tx.rs +++ b/examples/src/bin/embassy_parl_io_tx.rs @@ -37,10 +37,10 @@ use esp_println::println; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -58,7 +58,6 @@ async fn main(_spawner: Spawner) { dma_channel.configure_for_async(false, DmaPriority::Priority0), tx_descriptors, 1.MHz(), - &clocks, ) .unwrap(); diff --git a/examples/src/bin/embassy_rmt_rx.rs b/examples/src/bin/embassy_rmt_rx.rs index ef42cd4c108..176e9b4a135 100644 --- a/examples/src/bin/embassy_rmt_rx.rs +++ b/examples/src/bin/embassy_rmt_rx.rs @@ -39,10 +39,10 @@ async fn signal_task(mut pin: Output<'static, GpioPin<5>>) { #[esp_hal_embassy::main] async fn main(spawner: Spawner) { println!("Init!"); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -54,7 +54,7 @@ async fn main(spawner: Spawner) { } }; - let rmt = Rmt::new_async(peripherals.RMT, freq, &clocks).unwrap(); + let rmt = Rmt::new_async(peripherals.RMT, freq).unwrap(); let rx_config = RxChannelConfig { clk_divider: 255, idle_threshold: 10000, diff --git a/examples/src/bin/embassy_rmt_tx.rs b/examples/src/bin/embassy_rmt_tx.rs index f446527b0ea..04ddc45d5cf 100644 --- a/examples/src/bin/embassy_rmt_tx.rs +++ b/examples/src/bin/embassy_rmt_tx.rs @@ -25,10 +25,10 @@ use esp_println::println; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { println!("Init!"); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -40,7 +40,7 @@ async fn main(_spawner: Spawner) { } }; - let rmt = Rmt::new_async(peripherals.RMT, freq, &clocks).unwrap(); + let rmt = Rmt::new_async(peripherals.RMT, freq).unwrap(); let mut channel = rmt .channel0 diff --git a/examples/src/bin/embassy_serial.rs b/examples/src/bin/embassy_serial.rs index e2da6b3d377..4624009e22c 100644 --- a/examples/src/bin/embassy_serial.rs +++ b/examples/src/bin/embassy_serial.rs @@ -78,10 +78,10 @@ async fn reader( #[esp_hal_embassy::main] async fn main(spawner: Spawner) { esp_println::println!("Init!"); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -104,8 +104,7 @@ async fn main(spawner: Spawner) { let config = Config::default().rx_fifo_full_threshold(READ_BUF_SIZE as u16); - let mut uart0 = - Uart::new_async_with_config(peripherals.UART0, config, &clocks, tx_pin, rx_pin).unwrap(); + let mut uart0 = Uart::new_async_with_config(peripherals.UART0, config, tx_pin, rx_pin).unwrap(); uart0.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None)); let (tx, rx) = uart0.split(); diff --git a/examples/src/bin/embassy_spi.rs b/examples/src/bin/embassy_spi.rs index 90500980d8f..3e62ec5110c 100644 --- a/examples/src/bin/embassy_spi.rs +++ b/examples/src/bin/embassy_spi.rs @@ -33,10 +33,10 @@ use esp_hal::{ #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; @@ -58,7 +58,7 @@ async fn main(_spawner: Spawner) { let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap(); - let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks) + let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) .with_dma(dma_channel.configure_for_async(false, DmaPriority::Priority0)) .with_buffers(dma_tx_buf, dma_rx_buf); diff --git a/examples/src/bin/embassy_touch.rs b/examples/src/bin/embassy_touch.rs index d311aca68bc..808caf2a869 100644 --- a/examples/src/bin/embassy_touch.rs +++ b/examples/src/bin/embassy_touch.rs @@ -27,10 +27,10 @@ use esp_println::println; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(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 8655c936981..85ee61d8abf 100644 --- a/examples/src/bin/embassy_twai.rs +++ b/examples/src/bin/embassy_twai.rs @@ -82,10 +82,10 @@ async fn transmitter( #[esp_hal_embassy::main] async fn main(spawner: Spawner) { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -103,7 +103,6 @@ async fn main(spawner: Spawner) { peripherals.TWAI0, can_tx_pin, can_rx_pin, - &clocks, CAN_BAUDRATE, TwaiMode::Normal, ); diff --git a/examples/src/bin/embassy_usb_serial.rs b/examples/src/bin/embassy_usb_serial.rs index 0c9ecd950bd..e2054358dd3 100644 --- a/examples/src/bin/embassy_usb_serial.rs +++ b/examples/src/bin/embassy_usb_serial.rs @@ -32,10 +32,10 @@ use esp_hal::{ #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(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 7ca40e7a0dc..877318c11de 100644 --- a/examples/src/bin/embassy_usb_serial_jtag.rs +++ b/examples/src/bin/embassy_usb_serial_jtag.rs @@ -63,10 +63,10 @@ async fn reader( #[esp_hal_embassy::main] async fn main(spawner: Spawner) { esp_println::println!("Init!"); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(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 e2ee6d4552f..9f80b2dbc9d 100644 --- a/examples/src/bin/embassy_wait.rs +++ b/examples/src/bin/embassy_wait.rs @@ -19,10 +19,10 @@ use esp_hal::{ #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/etm_blinky_systimer.rs b/examples/src/bin/etm_blinky_systimer.rs index b0057d4cee5..0a295c14ab1 100644 --- a/examples/src/bin/etm_blinky_systimer.rs +++ b/examples/src/bin/etm_blinky_systimer.rs @@ -24,7 +24,7 @@ use fugit::ExtU32; #[entry] fn main() -> ! { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let syst = SystemTimer::new(peripherals.SYSTIMER); let syst_alarms = syst.split::(); diff --git a/examples/src/bin/etm_gpio.rs b/examples/src/bin/etm_gpio.rs index 36adfbdc393..25bcf9b9a92 100644 --- a/examples/src/bin/etm_gpio.rs +++ b/examples/src/bin/etm_gpio.rs @@ -22,7 +22,7 @@ use esp_hal::{ #[entry] fn main() -> ! { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let mut led = io.pins.gpio1; diff --git a/examples/src/bin/etm_timer.rs b/examples/src/bin/etm_timer.rs index 649e64590cc..d382c2755d3 100644 --- a/examples/src/bin/etm_timer.rs +++ b/examples/src/bin/etm_timer.rs @@ -28,9 +28,9 @@ static TIMER0: Mutex, esp_hal::Blocking>>>> = #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let timer0 = timg0.timer0; timer0.set_interrupt_handler(tg0_t0_level); @@ -55,7 +55,7 @@ fn main() -> ! { TIMER0.borrow_ref_mut(cs).replace(timer0); }); - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { delay.delay_millis(500u32); diff --git a/examples/src/bin/gpio_interrupt.rs b/examples/src/bin/gpio_interrupt.rs index b7675744a5c..0c1021833d5 100644 --- a/examples/src/bin/gpio_interrupt.rs +++ b/examples/src/bin/gpio_interrupt.rs @@ -34,7 +34,7 @@ static BUTTON: Mutex>>>> = Mutex::new(R #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); // Set GPIO2 as an output, and set its state high initially. let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -57,7 +57,7 @@ fn main() -> ! { }); led.set_high(); - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { led.toggle(); diff --git a/examples/src/bin/hello_rgb.rs b/examples/src/bin/hello_rgb.rs index d2afd555892..46c38dab930 100644 --- a/examples/src/bin/hello_rgb.rs +++ b/examples/src/bin/hello_rgb.rs @@ -36,7 +36,7 @@ use smart_leds::{ #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -65,14 +65,14 @@ fn main() -> ! { } } - let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap(); + let rmt = Rmt::new(peripherals.RMT, freq).unwrap(); // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can // be used directly with all `smart_led` implementations let rmt_buffer = smartLedBuffer!(1); - let mut led = SmartLedsAdapter::new(rmt.channel0, led_pin, rmt_buffer, &clocks); + let mut led = SmartLedsAdapter::new(rmt.channel0, led_pin, rmt_buffer); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut color = Hsv { hue: 0, diff --git a/examples/src/bin/hello_world.rs b/examples/src/bin/hello_world.rs index ebda656f449..479fe82da9c 100644 --- a/examples/src/bin/hello_world.rs +++ b/examples/src/bin/hello_world.rs @@ -19,9 +19,9 @@ use esp_hal::{delay::Delay, gpio::Io, prelude::*, uart::Uart}; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -43,7 +43,7 @@ fn main() -> ! { } let mut uart0 = - Uart::new_with_default_pins(peripherals.UART0, &clocks, &mut tx_pin, &mut rx_pin).unwrap(); + Uart::new_with_default_pins(peripherals.UART0, &mut tx_pin, &mut rx_pin).unwrap(); loop { writeln!(uart0, "Hello world!").unwrap(); diff --git a/examples/src/bin/hmac.rs b/examples/src/bin/hmac.rs index 0cd9bf634c2..87b5118c1bd 100644 --- a/examples/src/bin/hmac.rs +++ b/examples/src/bin/hmac.rs @@ -73,7 +73,7 @@ type HmacSha256 = HmacSw; #[entry] fn main() -> ! { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut rng = Rng::new(peripherals.RNG); diff --git a/examples/src/bin/i2c_bmp180_calibration_data.rs b/examples/src/bin/i2c_bmp180_calibration_data.rs index e3f61626a01..0f703abe1c4 100644 --- a/examples/src/bin/i2c_bmp180_calibration_data.rs +++ b/examples/src/bin/i2c_bmp180_calibration_data.rs @@ -17,19 +17,13 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); // Create a new peripheral object with the described wiring and standard // I2C clock speed: - let mut i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio4, - io.pins.gpio5, - 100.kHz(), - &clocks, - ); + let mut i2c = I2C::new(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 100.kHz()); loop { let mut data = [0u8; 22]; diff --git a/examples/src/bin/i2c_display.rs b/examples/src/bin/i2c_display.rs index ef9b44ac439..05a950ae850 100644 --- a/examples/src/bin/i2c_display.rs +++ b/examples/src/bin/i2c_display.rs @@ -27,20 +27,14 @@ use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); // Create a new peripheral object with the described wiring // and standard I2C clock speed - let i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio4, - io.pins.gpio5, - 100.kHz(), - &clocks, - ); + let i2c = I2C::new(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 100.kHz()); // Initialize display let interface = I2CDisplayInterface::new(i2c); diff --git a/examples/src/bin/i2s_read.rs b/examples/src/bin/i2s_read.rs index 5a1616eef38..3c6b18ee3e4 100644 --- a/examples/src/bin/i2s_read.rs +++ b/examples/src/bin/i2s_read.rs @@ -28,7 +28,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -52,7 +52,6 @@ fn main() -> ! { dma_channel.configure(false, DmaPriority::Priority0), tx_descriptors, rx_descriptors, - &clocks, ); #[cfg(not(feature = "esp32"))] diff --git a/examples/src/bin/i2s_sound.rs b/examples/src/bin/i2s_sound.rs index 998bb127cdf..e73b833b050 100644 --- a/examples/src/bin/i2s_sound.rs +++ b/examples/src/bin/i2s_sound.rs @@ -49,7 +49,7 @@ const SINE: [i16; 64] = [ #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -69,7 +69,6 @@ fn main() -> ! { dma_channel.configure(false, DmaPriority::Priority0), tx_descriptors, rx_descriptors, - &clocks, ); let mut i2s_tx = i2s diff --git a/examples/src/bin/ieee802154_receive_all_frames.rs b/examples/src/bin/ieee802154_receive_all_frames.rs index ce078a0223d..02a46286552 100644 --- a/examples/src/bin/ieee802154_receive_all_frames.rs +++ b/examples/src/bin/ieee802154_receive_all_frames.rs @@ -10,7 +10,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (mut peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let mut peripherals = esp_hal::init(esp_hal::Config::default()); let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); ieee802154.set_config(Config { diff --git a/examples/src/bin/ieee802154_receive_frame.rs b/examples/src/bin/ieee802154_receive_frame.rs index 5fa678a3a52..53b6f5c9a65 100644 --- a/examples/src/bin/ieee802154_receive_frame.rs +++ b/examples/src/bin/ieee802154_receive_frame.rs @@ -10,7 +10,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (mut peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let mut peripherals = esp_hal::init(esp_hal::Config::default()); let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); ieee802154.set_config(Config { diff --git a/examples/src/bin/ieee802154_send_broadcast_frame.rs b/examples/src/bin/ieee802154_send_broadcast_frame.rs index 1053a934e16..7c8de3c34e4 100644 --- a/examples/src/bin/ieee802154_send_broadcast_frame.rs +++ b/examples/src/bin/ieee802154_send_broadcast_frame.rs @@ -19,9 +19,9 @@ use ieee802154::mac::{ #[entry] fn main() -> ! { - let (mut peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let mut peripherals = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); diff --git a/examples/src/bin/ieee802154_send_frame.rs b/examples/src/bin/ieee802154_send_frame.rs index 9cf2e72ba9e..851ce007997 100644 --- a/examples/src/bin/ieee802154_send_frame.rs +++ b/examples/src/bin/ieee802154_send_frame.rs @@ -19,9 +19,9 @@ use ieee802154::mac::{ #[entry] fn main() -> ! { - let (mut peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let mut peripherals = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); diff --git a/examples/src/bin/ieee802154_sniffer.rs b/examples/src/bin/ieee802154_sniffer.rs index c78a7166a1e..687b749a76c 100644 --- a/examples/src/bin/ieee802154_sniffer.rs +++ b/examples/src/bin/ieee802154_sniffer.rs @@ -14,7 +14,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (mut peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let mut peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -28,7 +28,7 @@ fn main() -> ! { } let mut uart0 = - Uart::new_with_default_pins(peripherals.UART0, &clocks, &mut tx_pin, &mut rx_pin).unwrap(); + Uart::new_with_default_pins(peripherals.UART0, &mut tx_pin, &mut rx_pin).unwrap(); // read two characters which get parsed as the channel let mut cnt = 0; diff --git a/examples/src/bin/lcd_cam_ov2640.rs b/examples/src/bin/lcd_cam_ov2640.rs index caa62eeb383..e62d2e27ed3 100644 --- a/examples/src/bin/lcd_cam_ov2640.rs +++ b/examples/src/bin/lcd_cam_ov2640.rs @@ -42,7 +42,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -77,20 +77,19 @@ fn main() -> ! { rx_descriptors, cam_data_pins, 20u32.MHz(), - &clocks, ) .with_master_clock(cam_xclk) .with_pixel_clock(cam_pclk) .with_ctrl_pins(cam_vsync, cam_href); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut buffer = rx_buffer; buffer.fill(0u8); delay.delay_millis(500u32); - let i2c = I2C::new(peripherals.I2C0, cam_siod, cam_sioc, 100u32.kHz(), &clocks); + let i2c = I2C::new(peripherals.I2C0, cam_siod, cam_sioc, 100u32.kHz()); let mut sccb = Sccb::new(i2c); diff --git a/examples/src/bin/lcd_i8080.rs b/examples/src/bin/lcd_i8080.rs index 20597d7babb..880d8e7e3a8 100644 --- a/examples/src/bin/lcd_i8080.rs +++ b/examples/src/bin/lcd_i8080.rs @@ -37,7 +37,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -54,7 +54,7 @@ fn main() -> ! { let channel = channel.configure(false, DmaPriority::Priority0); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut backlight = Output::new(lcd_backlight, Level::Low); let mut reset = Output::new(lcd_reset, Level::Low); @@ -78,7 +78,6 @@ fn main() -> ! { tx_pins, 20.MHz(), Config::default(), - &clocks, ) .with_ctrl_pins(lcd_rs, lcd_wr); diff --git a/examples/src/bin/ledc.rs b/examples/src/bin/ledc.rs index b7dd70e6c20..a9e8225a290 100644 --- a/examples/src/bin/ledc.rs +++ b/examples/src/bin/ledc.rs @@ -24,12 +24,12 @@ use esp_hal::{ #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let led = io.pins.gpio0; - let mut ledc = Ledc::new(peripherals.LEDC, &clocks); + let mut ledc = Ledc::new(peripherals.LEDC); ledc.set_global_slow_clock(LSGlobalClkSource::APBClk); diff --git a/examples/src/bin/lp_core_basic.rs b/examples/src/bin/lp_core_basic.rs index 9b35e8c0eba..d0f38c45e14 100644 --- a/examples/src/bin/lp_core_basic.rs +++ b/examples/src/bin/lp_core_basic.rs @@ -23,7 +23,7 @@ use esp_println::{print, println}; #[entry] fn main() -> ! { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); // configure GPIO 1 as LP output pin let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/lp_core_i2c.rs b/examples/src/bin/lp_core_i2c.rs index c4a817fd9f4..55aa731c1bd 100644 --- a/examples/src/bin/lp_core_i2c.rs +++ b/examples/src/bin/lp_core_i2c.rs @@ -25,7 +25,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/lp_core_uart.rs b/examples/src/bin/lp_core_uart.rs index 79e5962e946..4ebe0ff1560 100644 --- a/examples/src/bin/lp_core_uart.rs +++ b/examples/src/bin/lp_core_uart.rs @@ -28,7 +28,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -37,7 +37,6 @@ fn main() -> ! { let mut uart1 = Uart::new_with_config( peripherals.UART1, Config::default(), - &clocks, io.pins.gpio6, io.pins.gpio7, ) diff --git a/examples/src/bin/mcpwm.rs b/examples/src/bin/mcpwm.rs index 783046ae783..17e08e8c801 100644 --- a/examples/src/bin/mcpwm.rs +++ b/examples/src/bin/mcpwm.rs @@ -18,7 +18,7 @@ use esp_hal::{ #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let pin = io.pins.gpio0; @@ -32,7 +32,7 @@ fn main() -> ! { } } - let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, freq).unwrap(); + let clock_cfg = PeripheralClockConfig::with_frequency(freq).unwrap(); let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg); diff --git a/examples/src/bin/multicore.rs b/examples/src/bin/multicore.rs index 28297e91733..89a5a8bce0a 100644 --- a/examples/src/bin/multicore.rs +++ b/examples/src/bin/multicore.rs @@ -23,9 +23,9 @@ static mut APP_CORE_STACK: Stack<8192> = Stack::new(); #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let counter = Mutex::new(RefCell::new(0u32)); diff --git a/examples/src/bin/parl_io_rx.rs b/examples/src/bin/parl_io_rx.rs index 04d31ce6302..e1899cda5e7 100644 --- a/examples/src/bin/parl_io_rx.rs +++ b/examples/src/bin/parl_io_rx.rs @@ -22,7 +22,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -38,7 +38,6 @@ fn main() -> ! { dma_channel.configure(false, DmaPriority::Priority0), rx_descriptors, 1.MHz(), - &clocks, ) .unwrap(); @@ -50,7 +49,7 @@ fn main() -> ! { let mut buffer = rx_buffer; buffer.fill(0u8); - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { let transfer = parl_io_rx.read_dma(&mut buffer).unwrap(); diff --git a/examples/src/bin/parl_io_tx.rs b/examples/src/bin/parl_io_tx.rs index 8fc1b9eac6d..1b89715cfa1 100644 --- a/examples/src/bin/parl_io_tx.rs +++ b/examples/src/bin/parl_io_tx.rs @@ -33,7 +33,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -51,7 +51,6 @@ fn main() -> ! { dma_channel.configure(false, DmaPriority::Priority0), tx_descriptors, 1.MHz(), - &clocks, ) .unwrap(); @@ -73,7 +72,7 @@ fn main() -> ! { buffer[i] = (i % 255) as u8; } - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { let transfer = parl_io_tx.write_dma(&buffer).unwrap(); diff --git a/examples/src/bin/pcnt_encoder.rs b/examples/src/bin/pcnt_encoder.rs index 5cba71d117a..f02c0ddbddd 100644 --- a/examples/src/bin/pcnt_encoder.rs +++ b/examples/src/bin/pcnt_encoder.rs @@ -37,7 +37,7 @@ static VALUE: AtomicI32 = AtomicI32::new(0); #[entry] fn main() -> ! { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/psram_octal.rs b/examples/src/bin/psram_octal.rs index a1c46c7d80f..4664d0932c7 100644 --- a/examples/src/bin/psram_octal.rs +++ b/examples/src/bin/psram_octal.rs @@ -30,7 +30,7 @@ fn main() -> ! { #[cfg(debug_assertions)] compile_error!("This example MUST be built in release mode!"); - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); psram::init_psram(peripherals.PSRAM); init_psram_heap(); diff --git a/examples/src/bin/psram_quad.rs b/examples/src/bin/psram_quad.rs index 93c0d9747ac..6a70b436d84 100644 --- a/examples/src/bin/psram_quad.rs +++ b/examples/src/bin/psram_quad.rs @@ -30,7 +30,7 @@ fn main() -> ! { #[cfg(debug_assertions)] compile_error!("PSRAM example must be built in release mode!"); - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); psram::init_psram(peripherals.PSRAM); init_psram_heap(); diff --git a/examples/src/bin/qspi_flash.rs b/examples/src/bin/qspi_flash.rs index 65ee4ef5732..c6efd37ae4f 100644 --- a/examples/src/bin/qspi_flash.rs +++ b/examples/src/bin/qspi_flash.rs @@ -44,7 +44,7 @@ use esp_println::{print, println}; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); cfg_if::cfg_if! { @@ -79,7 +79,7 @@ fn main() -> ! { let mut dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let mut dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap(); - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks) + let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) .with_pins( Some(sclk), Some(mosi), @@ -90,7 +90,7 @@ fn main() -> ! { ) .with_dma(dma_channel.configure(false, DmaPriority::Priority0)); - let delay = Delay::new(&clocks); + let delay = Delay::new(); // write enable dma_tx_buf.set_length(0); diff --git a/examples/src/bin/ram.rs b/examples/src/bin/ram.rs index bece3c8a998..c8c802fcc9b 100644 --- a/examples/src/bin/ram.rs +++ b/examples/src/bin/ram.rs @@ -31,9 +31,9 @@ static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8]; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); // The RWDT flash boot protection must be enabled, as it is triggered as part of // the example. diff --git a/examples/src/bin/rmt_rx.rs b/examples/src/bin/rmt_rx.rs index 9ad6803f979..16fffe80b77 100644 --- a/examples/src/bin/rmt_rx.rs +++ b/examples/src/bin/rmt_rx.rs @@ -24,7 +24,7 @@ const WIDTH: usize = 80; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let mut out = io.pins.gpio5; @@ -37,7 +37,7 @@ fn main() -> ! { } }; - let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap(); + let rmt = Rmt::new(peripherals.RMT, freq).unwrap(); let rx_config = RxChannelConfig { clk_divider: 1, @@ -55,7 +55,7 @@ fn main() -> ! { } } - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut data = [PulseCode { level1: true, diff --git a/examples/src/bin/rmt_tx.rs b/examples/src/bin/rmt_tx.rs index fd5dbc8807d..6d16c26298f 100644 --- a/examples/src/bin/rmt_tx.rs +++ b/examples/src/bin/rmt_tx.rs @@ -20,7 +20,7 @@ use esp_hal::{ #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -32,7 +32,7 @@ fn main() -> ! { } }; - let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap(); + let rmt = Rmt::new(peripherals.RMT, freq).unwrap(); let tx_config = TxChannelConfig { clk_divider: 255, @@ -41,7 +41,7 @@ fn main() -> ! { let mut channel = rmt.channel0.configure(io.pins.gpio4, tx_config).unwrap(); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut data = [PulseCode { level1: true, diff --git a/examples/src/bin/rng.rs b/examples/src/bin/rng.rs index e981faac46a..36e84f69e0f 100644 --- a/examples/src/bin/rng.rs +++ b/examples/src/bin/rng.rs @@ -11,7 +11,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut rng = Rng::new(peripherals.RNG); // Generate a random word (u32): diff --git a/examples/src/bin/rtc_time.rs b/examples/src/bin/rtc_time.rs index 4c0e9c4d189..e0c809da0ba 100644 --- a/examples/src/bin/rtc_time.rs +++ b/examples/src/bin/rtc_time.rs @@ -10,10 +10,10 @@ use esp_hal::{delay::Delay, prelude::*, rtc_cntl::Rtc}; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let rtc = Rtc::new(peripherals.LPWR); - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { esp_println::println!("rtc time in milliseconds is {}", rtc.get_time_ms()); diff --git a/examples/src/bin/rtc_watchdog.rs b/examples/src/bin/rtc_watchdog.rs index e197bd13038..255f0bf1225 100644 --- a/examples/src/bin/rtc_watchdog.rs +++ b/examples/src/bin/rtc_watchdog.rs @@ -24,7 +24,7 @@ static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut rtc = Rtc::new(peripherals.LPWR); rtc.set_interrupt_handler(interrupt_handler); diff --git a/examples/src/bin/serial_interrupts.rs b/examples/src/bin/serial_interrupts.rs index 729f5a3d3a9..34f01add849 100644 --- a/examples/src/bin/serial_interrupts.rs +++ b/examples/src/bin/serial_interrupts.rs @@ -27,9 +27,9 @@ static SERIAL: Mutex>>> = Mutex::new(RefCel #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -51,8 +51,7 @@ fn main() -> ! { } let config = Config::default().rx_fifo_full_threshold(30); - let mut uart0 = - Uart::new_with_config(peripherals.UART0, config, &clocks, tx_pin, rx_pin).unwrap(); + let mut uart0 = Uart::new_with_config(peripherals.UART0, config, tx_pin, rx_pin).unwrap(); uart0.set_interrupt_handler(interrupt_handler); critical_section::with(|cs| { diff --git a/examples/src/bin/sleep_timer.rs b/examples/src/bin/sleep_timer.rs index 1a0db0116ef..b1e70cad1c3 100644 --- a/examples/src/bin/sleep_timer.rs +++ b/examples/src/bin/sleep_timer.rs @@ -18,9 +18,9 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut rtc = Rtc::new(peripherals.LPWR); println!("up and runnning!"); diff --git a/examples/src/bin/sleep_timer_ext0.rs b/examples/src/bin/sleep_timer_ext0.rs index 4fef91badb2..c7dd2418eca 100644 --- a/examples/src/bin/sleep_timer_ext0.rs +++ b/examples/src/bin/sleep_timer_ext0.rs @@ -28,7 +28,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut rtc = Rtc::new(peripherals.LPWR); @@ -41,7 +41,7 @@ fn main() -> ! { let wake_reason = get_wakeup_cause(); println!("wake reason: {:?}", wake_reason); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let timer = TimerWakeupSource::new(Duration::from_secs(30)); let ext0 = Ext0WakeupSource::new(&mut ext0_pin, WakeupLevel::High); diff --git a/examples/src/bin/sleep_timer_ext1.rs b/examples/src/bin/sleep_timer_ext1.rs index bf1c0f881bf..b9b7ba2a295 100644 --- a/examples/src/bin/sleep_timer_ext1.rs +++ b/examples/src/bin/sleep_timer_ext1.rs @@ -28,7 +28,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut rtc = Rtc::new(peripherals.LPWR); @@ -42,7 +42,7 @@ fn main() -> ! { let wake_reason = get_wakeup_cause(); println!("wake reason: {:?}", wake_reason); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let timer = TimerWakeupSource::new(Duration::from_secs(30)); let mut wakeup_pins: [&mut dyn RtcPin; 2] = [&mut pin_0, &mut pin_2]; diff --git a/examples/src/bin/sleep_timer_lpio.rs b/examples/src/bin/sleep_timer_lpio.rs index 05f8a8e04f7..cfb2690efd2 100644 --- a/examples/src/bin/sleep_timer_lpio.rs +++ b/examples/src/bin/sleep_timer_lpio.rs @@ -29,7 +29,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut rtc = Rtc::new(peripherals.LPWR); @@ -43,7 +43,7 @@ fn main() -> ! { let wake_reason = get_wakeup_cause(); println!("wake reason: {:?}", wake_reason); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let timer = TimerWakeupSource::new(Duration::from_secs(10)); let wakeup_pins: &mut [(&mut dyn RtcPinWithResistors, WakeupLevel)] = &mut [ diff --git a/examples/src/bin/sleep_timer_rtcio.rs b/examples/src/bin/sleep_timer_rtcio.rs index 6b33624beaa..f75bb83dabe 100644 --- a/examples/src/bin/sleep_timer_rtcio.rs +++ b/examples/src/bin/sleep_timer_rtcio.rs @@ -33,7 +33,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let mut rtc = Rtc::new(peripherals.LPWR); @@ -44,7 +44,7 @@ fn main() -> ! { let wake_reason = get_wakeup_cause(); println!("wake reason: {:?}", wake_reason); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let timer = TimerWakeupSource::new(Duration::from_secs(10)); cfg_if::cfg_if! { diff --git a/examples/src/bin/software_interrupts.rs b/examples/src/bin/software_interrupts.rs index 48c1a88bc74..98fc3d96947 100644 --- a/examples/src/bin/software_interrupts.rs +++ b/examples/src/bin/software_interrupts.rs @@ -26,7 +26,7 @@ static SWINT3: Mutex>>> = Mutex::new(RefCell #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); @@ -60,7 +60,7 @@ fn main() -> ! { .replace(sw_ints.software_interrupt3); }); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut counter = 0; loop { diff --git a/examples/src/bin/spi_halfduplex_read_manufacturer_id.rs b/examples/src/bin/spi_halfduplex_read_manufacturer_id.rs index cd10f9a0cd4..b6f20d7897e 100644 --- a/examples/src/bin/spi_halfduplex_read_manufacturer_id.rs +++ b/examples/src/bin/spi_halfduplex_read_manufacturer_id.rs @@ -42,7 +42,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); cfg_if::cfg_if! { @@ -63,17 +63,16 @@ fn main() -> ! { } } - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ); + let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100.kHz(), SpiMode::Mode0).with_pins( + Some(sclk), + Some(mosi), + Some(miso), + Some(sio2), + Some(sio3), + Some(cs), + ); - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { // READ MANUFACTURER ID FROM FLASH CHIP diff --git a/examples/src/bin/spi_loopback.rs b/examples/src/bin/spi_loopback.rs index 17248269422..fca0d8b2f91 100644 --- a/examples/src/bin/spi_loopback.rs +++ b/examples/src/bin/spi_loopback.rs @@ -29,7 +29,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; @@ -40,14 +40,14 @@ fn main() -> ! { let miso = AnyPin::new(miso); let mosi = AnyPin::new(mosi); - let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks).with_pins( + let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0).with_pins( Some(sclk), Some(mosi), Some(miso), Some(cs), ); - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { let mut data = [0xde, 0xca, 0xfb, 0xad]; diff --git a/examples/src/bin/spi_loopback_dma.rs b/examples/src/bin/spi_loopback_dma.rs index b13dd875bb4..50223fc0e8b 100644 --- a/examples/src/bin/spi_loopback_dma.rs +++ b/examples/src/bin/spi_loopback_dma.rs @@ -31,7 +31,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; @@ -53,11 +53,11 @@ fn main() -> ! { let mut dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let mut dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap(); - let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks) + let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) .with_dma(dma_channel.configure(false, DmaPriority::Priority0)); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut i = 0; diff --git a/examples/src/bin/spi_slave_dma.rs b/examples/src/bin/spi_slave_dma.rs index 8bc10a458fa..8996ce6f375 100644 --- a/examples/src/bin/spi_slave_dma.rs +++ b/examples/src/bin/spi_slave_dma.rs @@ -45,7 +45,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let slave_sclk = io.pins.gpio0; @@ -85,7 +85,7 @@ fn main() -> ! { rx_descriptors, ); - let delay = Delay::new(&clocks); + let delay = Delay::new(); // DMA buffer require a static life-time let master_send = &mut [0u8; 32000]; diff --git a/examples/src/bin/systimer.rs b/examples/src/bin/systimer.rs index 72d1931ef9c..e648e98d897 100644 --- a/examples/src/bin/systimer.rs +++ b/examples/src/bin/systimer.rs @@ -47,7 +47,7 @@ static ALARM2: Mutex< #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let systimer = SystemTimer::new(peripherals.SYSTIMER); println!("SYSTIMER Current value = {}", SystemTimer::now()); @@ -81,7 +81,7 @@ fn main() -> ! { ALARM2.borrow_ref_mut(cs).replace(alarm2); }); - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { delay.delay_millis(500); diff --git a/examples/src/bin/timer_interrupt.rs b/examples/src/bin/timer_interrupt.rs index aec50184183..11a1f3c8796 100644 --- a/examples/src/bin/timer_interrupt.rs +++ b/examples/src/bin/timer_interrupt.rs @@ -23,9 +23,9 @@ static TIMER0: Mutex, esp_hal::Blocking>>>> = #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let timer0 = timg0.timer0; timer0.set_interrupt_handler(tg0_t0_level); diff --git a/examples/src/bin/touch.rs b/examples/src/bin/touch.rs index 0e7b6ae8db3..0f34e6d74ce 100644 --- a/examples/src/bin/touch.rs +++ b/examples/src/bin/touch.rs @@ -47,7 +47,7 @@ fn interrupt_handler() { #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -66,7 +66,7 @@ fn main() -> ! { let mut touch0 = TouchPad::new(touch_pin0, &touch); let mut touch1 = TouchPad::new(touch_pin1, &touch); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let touch1_baseline = touch1.read(); diff --git a/examples/src/bin/twai.rs b/examples/src/bin/twai.rs index 9620ae508dc..f3ea708abb6 100644 --- a/examples/src/bin/twai.rs +++ b/examples/src/bin/twai.rs @@ -35,7 +35,7 @@ use nb::block; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -55,7 +55,6 @@ fn main() -> ! { peripherals.TWAI0, can_tx_pin, can_rx_pin, - &clocks, CAN_BAUDRATE, TwaiMode::Normal, ); diff --git a/examples/src/bin/ulp_riscv_core_basic.rs b/examples/src/bin/ulp_riscv_core_basic.rs index dcdac147257..d89eda74521 100644 --- a/examples/src/bin/ulp_riscv_core_basic.rs +++ b/examples/src/bin/ulp_riscv_core_basic.rs @@ -21,7 +21,7 @@ use esp_println::{print, println}; #[entry] fn main() -> ! { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let pin = LowPowerOutput::new(io.pins.gpio1); diff --git a/examples/src/bin/usb_serial.rs b/examples/src/bin/usb_serial.rs index 236d5a10bb2..aee87614333 100644 --- a/examples/src/bin/usb_serial.rs +++ b/examples/src/bin/usb_serial.rs @@ -26,7 +26,7 @@ static mut EP_MEMORY: [u32; 1024] = [0; 1024]; #[entry] fn main() -> ! { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/usb_serial_jtag.rs b/examples/src/bin/usb_serial_jtag.rs index a75d0dd486b..b6caa22bcf8 100644 --- a/examples/src/bin/usb_serial_jtag.rs +++ b/examples/src/bin/usb_serial_jtag.rs @@ -23,9 +23,9 @@ static USB_SERIAL: Mutex>>> = #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let mut usb_serial = UsbSerialJtag::new(peripherals.USB_DEVICE); usb_serial.set_interrupt_handler(usb_device); diff --git a/examples/src/bin/watchdog.rs b/examples/src/bin/watchdog.rs index 220e9ad4abf..ee01618c217 100644 --- a/examples/src/bin/watchdog.rs +++ b/examples/src/bin/watchdog.rs @@ -14,11 +14,11 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); - let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new_async(peripherals.TIMG0); let mut wdt0 = timg0.wdt; wdt0.enable(); wdt0.set_timeout(2u64.secs()); diff --git a/examples/src/bin/wifi_80211_tx.rs b/examples/src/bin/wifi_80211_tx.rs index 90c95060055..2a61ba2c38f 100644 --- a/examples/src/bin/wifi_80211_tx.rs +++ b/examples/src/bin/wifi_80211_tx.rs @@ -34,15 +34,15 @@ const MAC_ADDRESS: [u8; 6] = [0x00, 0x80, 0x41, 0x13, 0x37, 0x42]; #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let delay = Delay::new(&clocks); + let delay = Delay::new(); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let timer0: ErasedTimer = timg0.timer0.into(); let timer = PeriodicTimer::new(timer0); @@ -51,7 +51,6 @@ fn main() -> ! { timer, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); diff --git a/examples/src/bin/wifi_access_point.rs b/examples/src/bin/wifi_access_point.rs index e1e01ec525d..2673feecff0 100644 --- a/examples/src/bin/wifi_access_point.rs +++ b/examples/src/bin/wifi_access_point.rs @@ -34,20 +34,19 @@ use smoltcp::iface::SocketStorage; #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); diff --git a/examples/src/bin/wifi_access_point_with_sta.rs b/examples/src/bin/wifi_access_point_with_sta.rs index f58349849e6..ece68d13a1a 100644 --- a/examples/src/bin/wifi_access_point_with_sta.rs +++ b/examples/src/bin/wifi_access_point_with_sta.rs @@ -41,20 +41,19 @@ const PASSWORD: &str = env!("PASSWORD"); #[entry] fn main() -> ! { esp_println::logger::init_logger(log::LevelFilter::Info); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); diff --git a/examples/src/bin/wifi_bench.rs b/examples/src/bin/wifi_bench.rs index 844f291a066..f93e24f518d 100644 --- a/examples/src/bin/wifi_bench.rs +++ b/examples/src/bin/wifi_bench.rs @@ -51,7 +51,7 @@ const UPLOAD_DOWNLOAD_PORT: u16 = 4323; #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config @@ -59,14 +59,13 @@ fn main() -> ! { let server_address: Ipv4Address = HOST_IP.parse().expect("Invalid HOST_IP address"); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); @@ -131,7 +130,7 @@ fn main() -> ! { let mut tx_buffer = [0u8; TX_BUFFER_SIZE]; let mut socket = wifi_stack.get_socket(&mut rx_buffer, &mut tx_buffer); - let delay = Delay::new(&clocks); + let delay = Delay::new(); loop { test_download(server_address, &mut socket); diff --git a/examples/src/bin/wifi_ble.rs b/examples/src/bin/wifi_ble.rs index c71bdb0ec6f..11a9a55644f 100644 --- a/examples/src/bin/wifi_ble.rs +++ b/examples/src/bin/wifi_ble.rs @@ -35,20 +35,19 @@ use esp_wifi::{ble::controller::BleConnector, initialize, EspWifiInitFor}; #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Ble, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); diff --git a/examples/src/bin/wifi_coex.rs b/examples/src/bin/wifi_coex.rs index 0bd4a4549f7..ee4097949ce 100644 --- a/examples/src/bin/wifi_coex.rs +++ b/examples/src/bin/wifi_coex.rs @@ -47,20 +47,19 @@ const PASSWORD: &str = env!("PASSWORD"); #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::WifiBle, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); diff --git a/examples/src/bin/wifi_dhcp.rs b/examples/src/bin/wifi_dhcp.rs index a02b52dd2b7..b2e8d0f665e 100644 --- a/examples/src/bin/wifi_dhcp.rs +++ b/examples/src/bin/wifi_dhcp.rs @@ -40,20 +40,19 @@ const PASSWORD: &str = env!("PASSWORD"); #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); diff --git a/examples/src/bin/wifi_embassy_access_point.rs b/examples/src/bin/wifi_embassy_access_point.rs index e91754b591e..a47be1507f3 100644 --- a/examples/src/bin/wifi_embassy_access_point.rs +++ b/examples/src/bin/wifi_embassy_access_point.rs @@ -55,20 +55,19 @@ macro_rules! mk_static { #[esp_hal_embassy::main] async fn main(spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); @@ -78,12 +77,12 @@ async fn main(spawner: Spawner) -> ! { cfg_if::cfg_if! { if #[cfg(feature = "esp32")] { - let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - esp_hal_embassy::init(&clocks, timg1.timer0); + let timg1 = TimerGroup::new(peripherals.TIMG1); + esp_hal_embassy::init(timg1.timer0); } else { use esp_hal::timer::systimer::{SystemTimer, Target}; let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); } } 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 3907ace1299..3db855649ac 100644 --- a/examples/src/bin/wifi_embassy_access_point_with_sta.rs +++ b/examples/src/bin/wifi_embassy_access_point_with_sta.rs @@ -63,20 +63,19 @@ macro_rules! mk_static { #[esp_hal_embassy::main] async fn main(spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); @@ -86,12 +85,12 @@ async fn main(spawner: Spawner) -> ! { cfg_if::cfg_if! { if #[cfg(feature = "esp32")] { - let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - esp_hal_embassy::init(&clocks, timg1.timer0); + let timg1 = TimerGroup::new(peripherals.TIMG1); + esp_hal_embassy::init(timg1.timer0); } else { use esp_hal::timer::systimer::{SystemTimer, Target}; let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); } } diff --git a/examples/src/bin/wifi_embassy_bench.rs b/examples/src/bin/wifi_embassy_bench.rs index eb27084a943..8ea9e44f2f0 100644 --- a/examples/src/bin/wifi_embassy_bench.rs +++ b/examples/src/bin/wifi_embassy_bench.rs @@ -66,7 +66,7 @@ static mut TX_BUFFER: [u8; TX_BUFFER_SIZE] = [0; TX_BUFFER_SIZE]; #[esp_hal_embassy::main] async fn main(spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config @@ -74,14 +74,13 @@ 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 timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); @@ -91,12 +90,12 @@ async fn main(spawner: Spawner) -> ! { cfg_if::cfg_if! { if #[cfg(feature = "esp32")] { - let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - esp_hal_embassy::init(&clocks, timg1.timer0); + let timg1 = TimerGroup::new(peripherals.TIMG1); + esp_hal_embassy::init(timg1.timer0); } else { use esp_hal::timer::systimer::{SystemTimer, Target}; let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); } } diff --git a/examples/src/bin/wifi_embassy_ble.rs b/examples/src/bin/wifi_embassy_ble.rs index 184e0f66641..c8e7b0c04a8 100644 --- a/examples/src/bin/wifi_embassy_ble.rs +++ b/examples/src/bin/wifi_embassy_ble.rs @@ -38,20 +38,19 @@ use esp_wifi::{ble::controller::asynch::BleConnector, initialize, EspWifiInitFor #[esp_hal_embassy::main] async fn main(_spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Ble, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); @@ -66,12 +65,12 @@ async fn main(_spawner: Spawner) -> ! { cfg_if::cfg_if! { if #[cfg(feature = "esp32")] { - let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - esp_hal_embassy::init(&clocks, timg1.timer0); + let timg1 = TimerGroup::new(peripherals.TIMG1); + esp_hal_embassy::init(timg1.timer0); } else { use esp_hal::timer::systimer::{SystemTimer, Target}; let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); } } diff --git a/examples/src/bin/wifi_embassy_dhcp.rs b/examples/src/bin/wifi_embassy_dhcp.rs index cb3108b3e61..7e668f726a8 100644 --- a/examples/src/bin/wifi_embassy_dhcp.rs +++ b/examples/src/bin/wifi_embassy_dhcp.rs @@ -49,20 +49,19 @@ const PASSWORD: &str = env!("PASSWORD"); #[esp_hal_embassy::main] async fn main(spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); @@ -72,12 +71,12 @@ async fn main(spawner: Spawner) -> ! { cfg_if::cfg_if! { if #[cfg(feature = "esp32")] { - let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - esp_hal_embassy::init(&clocks, timg1.timer0); + let timg1 = TimerGroup::new(peripherals.TIMG1); + esp_hal_embassy::init(timg1.timer0); } else { use esp_hal::timer::systimer::{SystemTimer, Target}; let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); } } diff --git a/examples/src/bin/wifi_embassy_esp_now.rs b/examples/src/bin/wifi_embassy_esp_now.rs index 39def6fd7ed..03ea884b087 100644 --- a/examples/src/bin/wifi_embassy_esp_now.rs +++ b/examples/src/bin/wifi_embassy_esp_now.rs @@ -25,20 +25,19 @@ use esp_wifi::{ #[esp_hal_embassy::main] async fn main(_spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); @@ -48,12 +47,12 @@ async fn main(_spawner: Spawner) -> ! { cfg_if::cfg_if! { if #[cfg(feature = "esp32")] { - let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - esp_hal_embassy::init(&clocks, timg1.timer0); + let timg1 = TimerGroup::new(peripherals.TIMG1); + esp_hal_embassy::init(timg1.timer0); } else { use esp_hal::timer::systimer::{SystemTimer, Target}; let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); } } diff --git a/examples/src/bin/wifi_embassy_esp_now_duplex.rs b/examples/src/bin/wifi_embassy_esp_now_duplex.rs index 946caac837a..66b241af1ad 100644 --- a/examples/src/bin/wifi_embassy_esp_now_duplex.rs +++ b/examples/src/bin/wifi_embassy_esp_now_duplex.rs @@ -35,20 +35,19 @@ macro_rules! mk_static { #[esp_hal_embassy::main] async fn main(spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); @@ -58,12 +57,12 @@ async fn main(spawner: Spawner) -> ! { cfg_if::cfg_if! { if #[cfg(feature = "esp32")] { - let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - esp_hal_embassy::init(&clocks, timg1.timer0); + let timg1 = TimerGroup::new(peripherals.TIMG1); + esp_hal_embassy::init(timg1.timer0); } else { use esp_hal::timer::systimer::{SystemTimer, Target}; let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); } } diff --git a/examples/src/bin/wifi_esp_now.rs b/examples/src/bin/wifi_esp_now.rs index 938068aaf95..83ebd654716 100644 --- a/examples/src/bin/wifi_esp_now.rs +++ b/examples/src/bin/wifi_esp_now.rs @@ -21,20 +21,19 @@ use esp_wifi::{ #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); diff --git a/examples/src/bin/wifi_sniffer.rs b/examples/src/bin/wifi_sniffer.rs index 2f277af11a0..49746548f59 100644 --- a/examples/src/bin/wifi_sniffer.rs +++ b/examples/src/bin/wifi_sniffer.rs @@ -33,7 +33,7 @@ static KNOWN_SSIDS: Mutex>> = Mutex::new(RefCell::new(B #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config @@ -42,7 +42,7 @@ fn main() -> ! { // Create a heap allocator, with 32kB of space. heap_allocator!(32_168); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let timer0: ErasedTimer = timg0.timer0.into(); let timer = PeriodicTimer::new(timer0); @@ -51,7 +51,6 @@ fn main() -> ! { timer, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); diff --git a/examples/src/bin/wifi_static_ip.rs b/examples/src/bin/wifi_static_ip.rs index 2c82dcea886..bd546d388ef 100644 --- a/examples/src/bin/wifi_static_ip.rs +++ b/examples/src/bin/wifi_static_ip.rs @@ -40,20 +40,19 @@ const GATEWAY_IP: &str = env!("GATEWAY_IP"); #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = initialize( EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); diff --git a/hil-test/tests/aes.rs b/hil-test/tests/aes.rs index 7e9c694884e..cbf90e8efc1 100644 --- a/hil-test/tests/aes.rs +++ b/hil-test/tests/aes.rs @@ -24,7 +24,7 @@ mod tests { #[init] fn init() -> Context<'static> { - let (peripherals, _clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config diff --git a/hil-test/tests/aes_dma.rs b/hil-test/tests/aes_dma.rs index d3dccfe0ac5..f86e95bc42c 100644 --- a/hil-test/tests/aes_dma.rs +++ b/hil-test/tests/aes_dma.rs @@ -29,8 +29,7 @@ mod tests { #[init] fn init() -> Peripherals { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); - peripherals + esp_hal::init(esp_hal::Config::default()) } #[test] diff --git a/hil-test/tests/clock_monitor.rs b/hil-test/tests/clock_monitor.rs index 724d9165459..31ac0715e63 100644 --- a/hil-test/tests/clock_monitor.rs +++ b/hil-test/tests/clock_monitor.rs @@ -19,7 +19,7 @@ mod tests { #[init] fn init() -> Context<'static> { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let rtc = Rtc::new(peripherals.LPWR); Context { rtc } diff --git a/hil-test/tests/delay.rs b/hil-test/tests/delay.rs index f171263dc6b..4dbb24c677c 100644 --- a/hil-test/tests/delay.rs +++ b/hil-test/tests/delay.rs @@ -20,7 +20,7 @@ mod tests { #[init] fn init() -> Context { - let (_peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(&clocks); Context { delay } diff --git a/hil-test/tests/dma_mem2mem.rs b/hil-test/tests/dma_mem2mem.rs index 45e9c9ebcae..3de0215445e 100644 --- a/hil-test/tests/dma_mem2mem.rs +++ b/hil-test/tests/dma_mem2mem.rs @@ -38,7 +38,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let dma = Dma::new(peripherals.DMA); let channel = dma.channel0.configure(false, DmaPriority::Priority0); diff --git a/hil-test/tests/ecc.rs b/hil-test/tests/ecc.rs index 5400ba84147..13e97740cfc 100644 --- a/hil-test/tests/ecc.rs +++ b/hil-test/tests/ecc.rs @@ -56,7 +56,7 @@ mod tests { #[init] fn init() -> Context<'static> { - let (peripherals, _clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config diff --git a/hil-test/tests/embassy_interrupt_executor.rs b/hil-test/tests/embassy_interrupt_executor.rs index 67e4f8107ee..863c81942b0 100644 --- a/hil-test/tests/embassy_interrupt_executor.rs +++ b/hil-test/tests/embassy_interrupt_executor.rs @@ -44,10 +44,10 @@ mod test { #[init] fn init() -> SoftwareInterrupt<1> { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); sw_ints.software_interrupt1 diff --git a/hil-test/tests/embassy_interrupt_spi_dma.rs b/hil-test/tests/embassy_interrupt_spi_dma.rs index 13412f5768a..a74155af556 100644 --- a/hil-test/tests/embassy_interrupt_spi_dma.rs +++ b/hil-test/tests/embassy_interrupt_spi_dma.rs @@ -72,16 +72,13 @@ mod test { #[test] #[timeout(3)] async fn run_interrupt_executor_test() { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); - - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init( - &clocks, - [ - ErasedTimer::from(timg0.timer0), - ErasedTimer::from(timg0.timer1), - ], - ); + let peripherals = esp_hal::init(esp_hal::Config::default()); + + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init([ + ErasedTimer::from(timg0.timer0), + ErasedTimer::from(timg0.timer1), + ]); let dma = Dma::new(peripherals.DMA); @@ -99,11 +96,11 @@ mod test { let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap(); - let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks) + let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) .with_dma(dma_channel1.configure_for_async(false, DmaPriority::Priority0)) .with_buffers(dma_tx_buf, dma_rx_buf); - let spi2 = Spi::new(peripherals.SPI3, 100.kHz(), SpiMode::Mode0, &clocks) + let spi2 = Spi::new(peripherals.SPI3, 100.kHz(), SpiMode::Mode0) .with_dma(dma_channel2.configure_for_async(false, DmaPriority::Priority0)); let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); diff --git a/hil-test/tests/embassy_timers_executors.rs b/hil-test/tests/embassy_timers_executors.rs index 7627b15a4f2..648719cf77f 100644 --- a/hil-test/tests/embassy_timers_executors.rs +++ b/hil-test/tests/embassy_timers_executors.rs @@ -9,7 +9,6 @@ use embassy_time::{Duration, Ticker, Timer}; use esp_hal::{ - clock::Clocks, interrupt::software::SoftwareInterruptControl, peripherals::Peripherals, prelude::*, @@ -109,15 +108,15 @@ mod test_cases { } } -fn set_up_embassy_with_timg0(peripherals: Peripherals, clocks: Clocks<'static>) { - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); +fn set_up_embassy_with_timg0(peripherals: Peripherals) { + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); } #[cfg(not(feature = "esp32"))] -fn set_up_embassy_with_systimer(peripherals: Peripherals, clocks: Clocks<'static>) { +fn set_up_embassy_with_systimer(peripherals: Peripherals) { let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); } #[cfg(test)] @@ -127,14 +126,14 @@ mod test { use crate::{test_cases::*, test_helpers::*}; #[init] - fn init() -> (Peripherals, Clocks<'static>) { + fn init() -> Peripherals { esp_hal::init(esp_hal::Config::default()) } #[test] #[timeout(3)] - async fn test_one_shot_timg((peripherals, clocks): (Peripherals, Clocks<'static>)) { - set_up_embassy_with_timg0(peripherals, clocks); + async fn test_one_shot_timg(peripherals: Peripherals) { + set_up_embassy_with_timg0(peripherals); run_test_one_shot_async().await; } @@ -142,16 +141,16 @@ mod test { #[test] #[timeout(3)] #[cfg(not(feature = "esp32"))] - async fn test_one_shot_systimer((peripherals, clocks): (Peripherals, Clocks<'static>)) { - set_up_embassy_with_systimer(peripherals, clocks); + async fn test_one_shot_systimer(peripherals: Peripherals) { + set_up_embassy_with_systimer(peripherals); run_test_one_shot_async().await; } #[test] #[timeout(3)] - fn test_periodic_timg((peripherals, clocks): (Peripherals, Clocks<'static>)) { - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + fn test_periodic_timg(peripherals: Peripherals) { + let timg0 = TimerGroup::new(peripherals.TIMG0); run_test_periodic_timer(timg0.timer0); } @@ -159,7 +158,7 @@ mod test { #[test] #[timeout(3)] #[cfg(not(feature = "esp32"))] - fn test_periodic_systimer((peripherals, _clocks): (Peripherals, Clocks<'static>)) { + fn test_periodic_systimer(peripherals: Peripherals) { let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); run_test_periodic_timer(systimer.alarm0); @@ -167,18 +166,18 @@ mod test { #[test] #[timeout(3)] - fn test_periodic_oneshot_timg((mut peripherals, clocks): (Peripherals, Clocks<'static>)) { - let mut timg0 = TimerGroup::new(&mut peripherals.TIMG0, &clocks); + fn test_periodic_oneshot_timg(mut peripherals: Peripherals) { + let mut timg0 = TimerGroup::new(&mut peripherals.TIMG0); run_test_periodic_timer(&mut timg0.timer0); - let mut timg0 = TimerGroup::new(&mut peripherals.TIMG0, &clocks); + let mut timg0 = TimerGroup::new(&mut peripherals.TIMG0); run_test_oneshot_timer(&mut timg0.timer0); } #[test] #[timeout(3)] #[cfg(not(feature = "esp32"))] - fn test_periodic_oneshot_systimer((mut peripherals, _clocks): (Peripherals, Clocks<'static>)) { + fn test_periodic_oneshot_systimer(mut peripherals: Peripherals) { let mut systimer = SystemTimer::new(&mut peripherals.SYSTIMER); let unit = FrozenUnit::new(&mut systimer.unit0); let mut alarm: Alarm<'_, Periodic, _, _, _> = Alarm::new(systimer.comparator0, &unit); @@ -192,8 +191,8 @@ mod test { #[test] #[timeout(3)] - async fn test_join_timg((peripherals, clocks): (Peripherals, Clocks<'static>)) { - set_up_embassy_with_timg0(peripherals, clocks); + async fn test_join_timg(peripherals: Peripherals) { + set_up_embassy_with_timg0(peripherals); run_join_test().await; } @@ -201,8 +200,8 @@ mod test { #[test] #[timeout(3)] #[cfg(not(feature = "esp32"))] - async fn test_join_systimer((peripherals, clocks): (Peripherals, Clocks<'static>)) { - set_up_embassy_with_systimer(peripherals, clocks); + async fn test_join_systimer(peripherals: Peripherals) { + set_up_embassy_with_systimer(peripherals); run_join_test().await; } @@ -211,17 +210,14 @@ mod test { #[test] #[timeout(3)] #[cfg(not(feature = "esp32"))] - async fn test_interrupt_executor((peripherals, clocks): (Peripherals, Clocks<'static>)) { - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + async fn test_interrupt_executor(peripherals: Peripherals) { + let timg0 = TimerGroup::new(peripherals.TIMG0); let timer0: ErasedTimer = timg0.timer0.into(); - let timer0 = OneShotTimer::new(timer0); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); let alarm0: ErasedTimer = systimer.alarm0.into(); - let timer1 = OneShotTimer::new(alarm0); - let timers = mk_static!([OneShotTimer; 2], [timer0, timer1]); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init([timer0, alarm0]); let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); @@ -266,8 +262,8 @@ mod test { /// Test that timg0 and systimer don't have vastly different tick rates. #[test] #[timeout(3)] - async fn tick_test_timer_tick_rates((peripherals, clocks): (Peripherals, Clocks<'static>)) { - set_up_embassy_with_timg0(peripherals, clocks); + async fn tick_test_timer_tick_rates(peripherals: Peripherals) { + set_up_embassy_with_timg0(peripherals); // We are retrying 5 times because probe-rs polling RTT may introduce some // jitter. diff --git a/hil-test/tests/get_time.rs b/hil-test/tests/get_time.rs index 6f34c6dd6eb..3e3e826f07f 100644 --- a/hil-test/tests/get_time.rs +++ b/hil-test/tests/get_time.rs @@ -5,15 +5,11 @@ #![no_std] #![no_main] -#[cfg(esp32)] -use esp_hal::clock::Clocks; -use esp_hal::delay::Delay; +use esp_hal::{delay::Delay, prelude::*}; use hil_test as _; struct Context { delay: Delay, - #[cfg(esp32)] - clocks: Clocks<'static>, } fn time_moves_forward_during(ctx: Context, f: F) { @@ -31,15 +27,11 @@ mod tests { #[init] fn init() -> Context { - let (_peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let _ = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); - Context { - delay, - #[cfg(esp32)] - clocks, - } + Context { delay } } #[test] @@ -71,10 +63,9 @@ mod tests { fn test_current_time_construct_timg0(ctx: Context) { time_moves_forward_during(ctx, |ctx| { // construct the timer in between calls to current_time - let _ = esp_hal::timer::timg::TimerGroup::new( - unsafe { esp_hal::peripherals::TIMG0::steal() }, - &ctx.clocks, - ); + let _ = esp_hal::timer::timg::TimerGroup::new(unsafe { + esp_hal::peripherals::TIMG0::steal() + }); }) } } diff --git a/hil-test/tests/gpio.rs b/hil-test/tests/gpio.rs index a85b5557591..c98dd3b428c 100644 --- a/hil-test/tests/gpio.rs +++ b/hil-test/tests/gpio.rs @@ -65,17 +65,17 @@ mod tests { #[init] fn init() -> Context<'static> { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); io.set_interrupt_handler(interrupt_handler); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let (gpio1, gpio2) = hil_test::common_test_pins!(io); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + esp_hal_embassy::init(timg0.timer0); Context { test_gpio1: Input::new(gpio1, Pull::Down), diff --git a/hil-test/tests/i2s.rs b/hil-test/tests/i2s.rs index 64a47d35d53..1e0c7fbece4 100644 --- a/hil-test/tests/i2s.rs +++ b/hil-test/tests/i2s.rs @@ -54,14 +54,11 @@ mod tests { #[test] fn test_i2s_loopback() { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); - - let peripherals = peripherals; - let clocks = clocks; + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let dma = Dma::new(peripherals.DMA); let dma_channel = dma.channel0; @@ -76,7 +73,6 @@ mod tests { dma_channel.configure(false, DmaPriority::Priority0), tx_descriptors, rx_descriptors, - &clocks, ); let (dout, din) = hil_test::common_test_pins!(io); diff --git a/hil-test/tests/i2s_async.rs b/hil-test/tests/i2s_async.rs index 06604272d22..0f93b032f64 100644 --- a/hil-test/tests/i2s_async.rs +++ b/hil-test/tests/i2s_async.rs @@ -86,10 +86,7 @@ mod tests { async fn test_i2s_loopback() { let spawner = embassy_executor::Spawner::for_current_executor().await; - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); - - let peripherals = peripherals; - let clocks = clocks; + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -107,7 +104,6 @@ mod tests { dma_channel.configure_for_async(false, DmaPriority::Priority0), tx_descriptors, rx_descriptors, - &clocks, ); let (dout, din) = hil_test::common_test_pins!(io); diff --git a/hil-test/tests/interrupt.rs b/hil-test/tests/interrupt.rs index 8f6d63ea618..7388bf75ccb 100644 --- a/hil-test/tests/interrupt.rs +++ b/hil-test/tests/interrupt.rs @@ -64,7 +64,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, _clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config diff --git a/hil-test/tests/lcd_cam_i8080.rs b/hil-test/tests/lcd_cam_i8080.rs index 4237335deb1..6f122cc19d5 100644 --- a/hil-test/tests/lcd_cam_i8080.rs +++ b/hil-test/tests/lcd_cam_i8080.rs @@ -6,7 +6,6 @@ #![no_main] use esp_hal::{ - clock::Clocks, dma::{Dma, DmaDescriptor, DmaPriority}, dma_buffers, gpio::DummyPin, @@ -22,7 +21,6 @@ const DATA_SIZE: usize = 1024 * 10; struct Context<'d> { lcd_cam: LcdCam<'d, esp_hal::Blocking>, - clocks: Clocks<'d>, dma: Dma<'d>, tx_buffer: &'static [u8], tx_descriptors: &'static mut [DmaDescriptor], @@ -35,14 +33,13 @@ mod tests { #[init] fn init() -> Context<'static> { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let dma = Dma::new(peripherals.DMA); let lcd_cam = LcdCam::new(peripherals.LCD_CAM); let (tx_buffer, tx_descriptors, _, _) = dma_buffers!(DATA_SIZE, 0); Context { lcd_cam, - clocks, dma, tx_buffer, tx_descriptors, @@ -71,7 +68,6 @@ mod tests { pins, 20.MHz(), Config::default(), - &ctx.clocks, ); let xfer = i8080 @@ -104,7 +100,6 @@ mod tests { pins, 20.MHz(), Config::default(), - &ctx.clocks, ); let xfer = i8080 diff --git a/hil-test/tests/lcd_cam_i8080_async.rs b/hil-test/tests/lcd_cam_i8080_async.rs index a5b2c9ef487..5a62ac60da3 100644 --- a/hil-test/tests/lcd_cam_i8080_async.rs +++ b/hil-test/tests/lcd_cam_i8080_async.rs @@ -7,7 +7,6 @@ #![no_main] use esp_hal::{ - clock::Clocks, dma::{Dma, DmaDescriptor, DmaPriority}, dma_buffers, gpio::DummyPin, @@ -23,7 +22,6 @@ const DATA_SIZE: usize = 1024 * 10; struct Context<'d> { lcd_cam: LcdCam<'d, esp_hal::Async>, - clocks: Clocks<'d>, dma: Dma<'d>, tx_buffer: &'static [u8], tx_descriptors: &'static mut [DmaDescriptor], @@ -36,7 +34,7 @@ mod tests { #[init] async fn init() -> Context<'static> { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let dma = Dma::new(peripherals.DMA); let lcd_cam = LcdCam::new_async(peripherals.LCD_CAM); @@ -44,7 +42,6 @@ mod tests { Context { lcd_cam, - clocks, dma, tx_buffer, tx_descriptors, @@ -72,7 +69,6 @@ mod tests { pins, 20.MHz(), Config::default(), - &ctx.clocks, ); i8080 @@ -105,7 +101,6 @@ mod tests { pins, 20.MHz(), Config::default(), - &ctx.clocks, ); i8080 diff --git a/hil-test/tests/pcnt.rs b/hil-test/tests/pcnt.rs index f0ca372ed91..f7cdf259fdf 100644 --- a/hil-test/tests/pcnt.rs +++ b/hil-test/tests/pcnt.rs @@ -32,7 +32,7 @@ mod tests { #[init] fn init() -> Context<'static> { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -45,7 +45,7 @@ mod tests { pcnt: Pcnt::new(peripherals.PCNT), input: din, output: dout, - delay: Delay::new(&clocks), + delay: Delay::new(), } } diff --git a/hil-test/tests/qspi_read.rs b/hil-test/tests/qspi_read.rs index a58455d4515..7aeb77064a3 100644 --- a/hil-test/tests/qspi_read.rs +++ b/hil-test/tests/qspi_read.rs @@ -13,7 +13,6 @@ #![no_main] use esp_hal::{ - clock::Clocks, dma::{Channel, Dma, DmaPriority, DmaRxBuf}, dma_buffers, gpio::{AnyOutput, AnyPin, Io, Level}, @@ -44,7 +43,6 @@ struct Context { dma_channel: Channel<'static, DmaChannel0, Blocking>, miso: AnyPin<'static>, miso_mirror: AnyOutput<'static>, - clocks: Clocks<'static>, } fn execute( @@ -99,7 +97,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -125,14 +123,13 @@ mod tests { dma_channel, miso, miso_mirror, - clocks, } } #[test] #[timeout(3)] fn test_spi_reads_correctly_from_gpio_pin_0(ctx: Context) { - let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0, &ctx.clocks) + let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0) .with_pins( esp_hal::gpio::NO_PIN, Some(ctx.miso), @@ -150,7 +147,7 @@ mod tests { #[test] #[timeout(3)] fn test_spi_reads_correctly_from_gpio_pin_1(ctx: Context) { - let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0, &ctx.clocks) + let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0) .with_pins( esp_hal::gpio::NO_PIN, esp_hal::gpio::NO_PIN, @@ -168,7 +165,7 @@ mod tests { #[test] #[timeout(3)] fn test_spi_reads_correctly_from_gpio_pin_2(ctx: Context) { - let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0, &ctx.clocks) + let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0) .with_pins( esp_hal::gpio::NO_PIN, esp_hal::gpio::NO_PIN, @@ -186,7 +183,7 @@ mod tests { #[test] #[timeout(3)] fn test_spi_reads_correctly_from_gpio_pin_3(ctx: Context) { - let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0, &ctx.clocks) + let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0) .with_pins( esp_hal::gpio::NO_PIN, esp_hal::gpio::NO_PIN, diff --git a/hil-test/tests/qspi_write.rs b/hil-test/tests/qspi_write.rs index 0e5ab14c229..6f690c8cea2 100644 --- a/hil-test/tests/qspi_write.rs +++ b/hil-test/tests/qspi_write.rs @@ -15,7 +15,6 @@ #![no_main] use esp_hal::{ - clock::Clocks, dma::{Channel, Dma, DmaPriority, DmaTxBuf}, dma_buffers, gpio::{AnyPin, Io, Pull}, @@ -52,7 +51,6 @@ struct Context { dma_channel: Channel<'static, DmaChannel0, Blocking>, mosi: AnyPin<'static>, mosi_mirror: AnyPin<'static>, - clocks: Clocks<'static>, } fn execute( @@ -137,14 +135,13 @@ mod tests { dma_channel, mosi, mosi_mirror, - clocks, } } #[test] #[timeout(3)] fn test_spi_writes_correctly_to_pin_0(ctx: Context) { - let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0, &ctx.clocks) + let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0) .with_pins( esp_hal::gpio::NO_PIN, Some(ctx.mosi), @@ -171,7 +168,7 @@ mod tests { #[test] #[timeout(3)] fn test_spi_writes_correctly_to_pin_1(ctx: Context) { - let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0, &ctx.clocks) + let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0) .with_pins( esp_hal::gpio::NO_PIN, esp_hal::gpio::NO_PIN, @@ -198,7 +195,7 @@ mod tests { #[test] #[timeout(3)] fn test_spi_writes_correctly_to_pin_2(ctx: Context) { - let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0, &ctx.clocks) + let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0) .with_pins( esp_hal::gpio::NO_PIN, esp_hal::gpio::NO_PIN, @@ -225,7 +222,7 @@ mod tests { #[test] #[timeout(3)] fn test_spi_writes_correctly_to_pin_3(ctx: Context) { - let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0, &ctx.clocks) + let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0) .with_pins( esp_hal::gpio::NO_PIN, esp_hal::gpio::NO_PIN, diff --git a/hil-test/tests/qspi_write_read.rs b/hil-test/tests/qspi_write_read.rs index c4a8c6fb640..5c39b5c370e 100644 --- a/hil-test/tests/qspi_write_read.rs +++ b/hil-test/tests/qspi_write_read.rs @@ -15,7 +15,6 @@ #![no_main] use esp_hal::{ - clock::Clocks, dma::{Channel, Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{AnyOutput, AnyPin, Io, Level}, @@ -46,7 +45,6 @@ struct Context { dma_channel: Channel<'static, DmaChannel0, Blocking>, mosi: AnyPin<'static>, mosi_mirror: AnyOutput<'static>, - clocks: Clocks<'static>, } fn execute( @@ -101,7 +99,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -127,14 +125,13 @@ mod tests { dma_channel, mosi, mosi_mirror, - clocks, } } #[test] #[timeout(3)] fn test_spi_writes_correctly_to_pin_0(ctx: Context) { - let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0, &ctx.clocks) + let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0) .with_pins( esp_hal::gpio::NO_PIN, Some(ctx.mosi), @@ -151,7 +148,7 @@ mod tests { #[test] #[timeout(3)] fn test_spi_writes_correctly_to_pin_1(ctx: Context) { - let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0, &ctx.clocks) + let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0) .with_pins( esp_hal::gpio::NO_PIN, esp_hal::gpio::NO_PIN, @@ -168,7 +165,7 @@ mod tests { #[test] #[timeout(3)] fn test_spi_writes_correctly_to_pin_2(ctx: Context) { - let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0, &ctx.clocks) + let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0) .with_pins( esp_hal::gpio::NO_PIN, esp_hal::gpio::NO_PIN, @@ -185,7 +182,7 @@ mod tests { #[test] #[timeout(3)] fn test_spi_writes_correctly_to_pin_3(ctx: Context) { - let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0, &ctx.clocks) + let spi = Spi::new_half_duplex(ctx.spi, 100.kHz(), SpiMode::Mode0) .with_pins( esp_hal::gpio::NO_PIN, esp_hal::gpio::NO_PIN, diff --git a/hil-test/tests/rmt.rs b/hil-test/tests/rmt.rs index 460e82b0de8..a9696a51e09 100644 --- a/hil-test/tests/rmt.rs +++ b/hil-test/tests/rmt.rs @@ -26,7 +26,7 @@ mod tests { #[test] #[timeout(1)] fn rmt_loopback() { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -38,7 +38,7 @@ mod tests { } }; - let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap(); + let rmt = Rmt::new(peripherals.RMT, freq).unwrap(); let (tx, rx) = hil_test::common_test_pins!(io); diff --git a/hil-test/tests/rsa.rs b/hil-test/tests/rsa.rs index 389fc01df31..6651caea2ca 100644 --- a/hil-test/tests/rsa.rs +++ b/hil-test/tests/rsa.rs @@ -57,7 +57,7 @@ mod tests { #[init] fn init() -> Context<'static> { - let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut rsa = Rsa::new(peripherals.RSA); nb::block!(rsa.ready()).unwrap(); diff --git a/hil-test/tests/rsa_async.rs b/hil-test/tests/rsa_async.rs index 5730ea13c57..45c57a7d08c 100644 --- a/hil-test/tests/rsa_async.rs +++ b/hil-test/tests/rsa_async.rs @@ -7,7 +7,6 @@ use crypto_bigint::{Uint, U1024, U512}; use esp_hal::{ - peripherals::Peripherals, prelude::*, rsa::{ operand_sizes::*, @@ -58,7 +57,7 @@ mod tests { #[init] fn init() -> Context<'static> { - let peripherals = Peripherals::take(); + let peripherals = esp_hal::init(esp_hal::Config::default()); let mut rsa = Rsa::new_async(peripherals.RSA); nb::block!(rsa.ready()).unwrap(); diff --git a/hil-test/tests/sha.rs b/hil-test/tests/sha.rs index adc7acc9190..18cbf2080c6 100644 --- a/hil-test/tests/sha.rs +++ b/hil-test/tests/sha.rs @@ -173,7 +173,7 @@ mod tests { } } - let (peripherals, _clocks) = esp_hal::init(config); + let peripherals = esp_hal::init(config); Rng::new(peripherals.RNG) } diff --git a/hil-test/tests/spi_full_duplex.rs b/hil-test/tests/spi_full_duplex.rs index 19b9cae76cd..87e82a6849d 100644 --- a/hil-test/tests/spi_full_duplex.rs +++ b/hil-test/tests/spi_full_duplex.rs @@ -34,14 +34,14 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; let (miso, mosi) = hil_test::common_test_pins!(io); let cs = io.pins.gpio8; - let spi = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( + let spi = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0).with_pins( Some(sclk), Some(mosi), Some(miso), diff --git a/hil-test/tests/spi_full_duplex_dma.rs b/hil-test/tests/spi_full_duplex_dma.rs index 6e62694bc1a..b89e91addb2 100644 --- a/hil-test/tests/spi_full_duplex_dma.rs +++ b/hil-test/tests/spi_full_duplex_dma.rs @@ -52,7 +52,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; @@ -69,7 +69,7 @@ mod tests { } } - let spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks) + let spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) .with_dma(dma_channel.configure(false, DmaPriority::Priority0)); diff --git a/hil-test/tests/spi_full_duplex_dma_async.rs b/hil-test/tests/spi_full_duplex_dma_async.rs index 74dbfda85d1..d8052e5bf2d 100644 --- a/hil-test/tests/spi_full_duplex_dma_async.rs +++ b/hil-test/tests/spi_full_duplex_dma_async.rs @@ -70,7 +70,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let pcnt = Pcnt::new(peripherals.PCNT); @@ -99,7 +99,7 @@ mod tests { let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap(); - let spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks) + let spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) .with_dma(dma_channel.configure_for_async(false, DmaPriority::Priority0)) .with_buffers(dma_tx_buf, dma_rx_buf); diff --git a/hil-test/tests/spi_full_duplex_dma_pcnt.rs b/hil-test/tests/spi_full_duplex_dma_pcnt.rs index 541cca6b859..6a839e2903d 100644 --- a/hil-test/tests/spi_full_duplex_dma_pcnt.rs +++ b/hil-test/tests/spi_full_duplex_dma_pcnt.rs @@ -64,7 +64,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; @@ -82,7 +82,7 @@ mod tests { } } - let spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks) + let spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) .with_dma(dma_channel.configure(false, DmaPriority::Priority0)); diff --git a/hil-test/tests/spi_half_duplex_read.rs b/hil-test/tests/spi_half_duplex_read.rs index e7b2f821444..59a4be9453f 100644 --- a/hil-test/tests/spi_half_duplex_read.rs +++ b/hil-test/tests/spi_half_duplex_read.rs @@ -54,7 +54,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; @@ -72,7 +72,7 @@ mod tests { } } - let spi = Spi::new_half_duplex(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks) + let spi = Spi::new_half_duplex(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) .with_sck(sclk) .with_miso(miso) .with_dma(dma_channel.configure(false, DmaPriority::Priority0)); diff --git a/hil-test/tests/spi_half_duplex_write.rs b/hil-test/tests/spi_half_duplex_write.rs index 9adfb508881..3779ad7aa64 100644 --- a/hil-test/tests/spi_half_duplex_write.rs +++ b/hil-test/tests/spi_half_duplex_write.rs @@ -63,7 +63,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; @@ -82,7 +82,7 @@ mod tests { } } - let spi = Spi::new_half_duplex(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks) + let spi = Spi::new_half_duplex(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) .with_sck(sclk) .with_mosi(mosi) .with_dma(dma_channel.configure(false, DmaPriority::Priority0)); diff --git a/hil-test/tests/systimer.rs b/hil-test/tests/systimer.rs index ffaf473814f..cd2d53f14da 100644 --- a/hil-test/tests/systimer.rs +++ b/hil-test/tests/systimer.rs @@ -11,7 +11,6 @@ use core::cell::RefCell; use critical_section::Mutex; use embedded_hal::delay::DelayNs; use esp_hal::{ - clock::Clocks, delay::Delay, prelude::*, timer::systimer::{ @@ -41,7 +40,6 @@ struct Context { unit: FrozenUnit<'static, SpecificUnit<'static, 0>>, comparator0: SpecificComparator<'static, 0>, comparator1: SpecificComparator<'static, 1>, - clocks: Clocks<'static>, } #[handler(priority = esp_hal::interrupt::Priority::min())] @@ -104,7 +102,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let systimer = SystemTimer::new(peripherals.SYSTIMER); static UNIT0: StaticCell> = StaticCell::new(); @@ -113,7 +111,6 @@ mod tests { let frozen_unit = FrozenUnit::new(unit0); Context { - clocks, unit: frozen_unit, comparator0: systimer.comparator0, comparator1: systimer.comparator1, @@ -159,7 +156,7 @@ mod tests { ALARM_PERIODIC.borrow_ref_mut(cs).replace(alarm1); }); - let mut delay = Delay::new(&ctx.clocks); + let mut delay = Delay::new(); delay.delay_ms(300); } diff --git a/hil-test/tests/twai.rs b/hil-test/tests/twai.rs index 218160b54b9..ef3bf84eba0 100644 --- a/hil-test/tests/twai.rs +++ b/hil-test/tests/twai.rs @@ -35,7 +35,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -45,7 +45,6 @@ mod tests { peripherals.TWAI0, can_tx_pin, can_rx_pin, - &clocks, twai::BaudRate::B1000K, TwaiMode::SelfTest, ); diff --git a/hil-test/tests/uart.rs b/hil-test/tests/uart.rs index 21c0812f31e..aa17f08e827 100644 --- a/hil-test/tests/uart.rs +++ b/hil-test/tests/uart.rs @@ -13,7 +13,6 @@ use embedded_hal_02::serial::{Read, Write}; use esp_hal::{ - clock::Clocks, gpio::Io, peripherals::UART1, prelude::*, @@ -24,7 +23,6 @@ use hil_test as _; use nb::block; struct Context { - clocks: Clocks<'static>, uart: Uart<'static, UART1, Blocking>, } @@ -37,15 +35,15 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let (tx, rx) = hil_test::common_test_pins!(io); - let uart = Uart::new(peripherals.UART1, &clocks, tx, rx).unwrap(); + let uart = Uart::new(peripherals.UART1, tx, rx).unwrap(); - Context { clocks, uart } + Context { uart } } #[test] @@ -95,7 +93,7 @@ mod tests { #[cfg(not(any(feature = "esp32", feature = "esp32c3", feature = "esp32c2")))] { // 9600 baud, RC FAST clock source: - ctx.uart.change_baud(9600, ClockSource::RcFast, &ctx.clocks); + ctx.uart.change_baud(9600, ClockSource::RcFast); ctx.uart.write(7).ok(); let read = block!(ctx.uart.read()); assert_eq!(read, Ok(7)); @@ -104,14 +102,14 @@ mod tests { // 19,200 baud, XTAL clock source: #[cfg(not(feature = "esp32"))] { - ctx.uart.change_baud(19_200, ClockSource::Xtal, &ctx.clocks); + ctx.uart.change_baud(19_200, ClockSource::Xtal); ctx.uart.write(55).ok(); let read = block!(ctx.uart.read()); assert_eq!(read, Ok(55)); } // 921,600 baud, APB clock source: - ctx.uart.change_baud(921_600, ClockSource::Apb, &ctx.clocks); + ctx.uart.change_baud(921_600, ClockSource::Apb); ctx.uart.write(253).ok(); let read = block!(ctx.uart.read()); assert_eq!(read, Ok(253)); @@ -120,14 +118,13 @@ mod tests { #[cfg(feature = "esp32s2")] { // 9600 baud, REF TICK clock source: - ctx.uart - .change_baud(9600, ClockSource::RefTick, &ctx.clocks); + ctx.uart.change_baud(9600, ClockSource::RefTick); ctx.uart.write(7).ok(); let read = block!(ctx.uart.read()); assert_eq!(read, Ok(7)); // 921,600 baud, APB clock source: - ctx.uart.change_baud(921_600, ClockSource::Apb, &ctx.clocks); + ctx.uart.change_baud(921_600, ClockSource::Apb); ctx.uart.write(253).ok(); let read = block!(ctx.uart.read()); assert_eq!(read, Ok(253)); diff --git a/hil-test/tests/uart_async.rs b/hil-test/tests/uart_async.rs index 940231710d5..357962d90e9 100644 --- a/hil-test/tests/uart_async.rs +++ b/hil-test/tests/uart_async.rs @@ -28,13 +28,13 @@ mod tests { #[init] async fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let (tx, rx) = hil_test::common_test_pins!(io); - let uart = Uart::new_async(peripherals.UART0, &clocks, tx, rx).unwrap(); + let uart = Uart::new_async(peripherals.UART0, tx, rx).unwrap(); Context { uart } } diff --git a/hil-test/tests/uart_tx_rx.rs b/hil-test/tests/uart_tx_rx.rs index c661e5e167d..e5750e8718a 100644 --- a/hil-test/tests/uart_tx_rx.rs +++ b/hil-test/tests/uart_tx_rx.rs @@ -35,14 +35,14 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let (tx, rx) = hil_test::common_test_pins!(io); - let tx = UartTx::new(peripherals.UART0, &clocks, tx).unwrap(); - let rx = UartRx::new(peripherals.UART1, &clocks, rx).unwrap(); + let tx = UartTx::new(peripherals.UART0, tx).unwrap(); + let rx = UartRx::new(peripherals.UART1, rx).unwrap(); Context { tx, rx } } diff --git a/hil-test/tests/uart_tx_rx_async.rs b/hil-test/tests/uart_tx_rx_async.rs index 5997908fe27..b16bb1d1871 100644 --- a/hil-test/tests/uart_tx_rx_async.rs +++ b/hil-test/tests/uart_tx_rx_async.rs @@ -34,14 +34,14 @@ mod tests { #[init] async fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let (tx, rx) = hil_test::common_test_pins!(io); - let tx = UartTx::new_async(peripherals.UART0, &clocks, tx).unwrap(); - let rx = UartRx::new_async(peripherals.UART1, &clocks, rx).unwrap(); + let tx = UartTx::new_async(peripherals.UART0, tx).unwrap(); + let rx = UartRx::new_async(peripherals.UART1, rx).unwrap(); Context { tx, rx } } diff --git a/hil-test/tests/usb_serial_jtag.rs b/hil-test/tests/usb_serial_jtag.rs index 7e2216221a0..c5e5bf44556 100644 --- a/hil-test/tests/usb_serial_jtag.rs +++ b/hil-test/tests/usb_serial_jtag.rs @@ -13,10 +13,10 @@ mod tests { #[test] fn creating_peripheral_does_not_break_debug_connection() { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); _ = UsbSerialJtag::new_async(peripherals.USB_DEVICE).split(); } From c586fc1d34561dba1a7d714a6a7c65a478e0dfba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Wed, 4 Sep 2024 15:05:55 +0200 Subject: [PATCH 2/8] Update changelog --- esp-hal-embassy/CHANGELOG.md | 2 ++ esp-hal-embassy/MIGRATING-0.3.md | 30 +++++++++++++++++++++++ esp-hal-smartled/CHANGELOG.md | 2 ++ esp-hal/CHANGELOG.md | 6 +++-- esp-hal/src/delay.rs | 5 ++-- esp-hal/src/lcd_cam/lcd/i8080.rs | 2 +- esp-hal/src/uart.rs | 2 +- esp-wifi/CHANGELOG.md | 2 ++ esp-wifi/MIGRATING-0.8.md | 41 ++++++++++++++++++++++++++++++++ 9 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 esp-hal-embassy/MIGRATING-0.3.md create mode 100644 esp-wifi/MIGRATING-0.8.md diff --git a/esp-hal-embassy/CHANGELOG.md b/esp-hal-embassy/CHANGELOG.md index 3a8887dbc6c..741ba7a3d30 100644 --- a/esp-hal-embassy/CHANGELOG.md +++ b/esp-hal-embassy/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed +- Removed the `clocks` parameter from `esp_hal_embassy::init`. (#1999) + ## 0.3.0 - 2024-08-29 ### Added diff --git a/esp-hal-embassy/MIGRATING-0.3.md b/esp-hal-embassy/MIGRATING-0.3.md new file mode 100644 index 00000000000..be65c5db9b7 --- /dev/null +++ b/esp-hal-embassy/MIGRATING-0.3.md @@ -0,0 +1,30 @@ +Migration Guide from 0.3.x to vNext +==================================== + +Initialsation +------------- + +You no longer have to set up clocks and pass them to `esp_hal_embassy::init`. + +```diff + use esp_hal::{ +- clock::ClockControl, +- peripherals::Peripherals, + prelude::*, +- system::SystemControl, + }; + + #[esp_hal_embassy::main] + async fn main(_spawner: Spawner) -> ! { +- let peripherals = Peripherals::take(); +- let system = SystemControl::new(peripherals.SYSTEM); +- let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); ++ let peripherals = esp_hal::init(esp_hal::Config::default()); + + let timg0 = TimerGroup::new(peripherals.TIMG0); +- esp_hal_embassy::init(&clocks, timg0); ++ esp_hal_embassy::init(timg0); + + // ... + } +``` diff --git a/esp-hal-smartled/CHANGELOG.md b/esp-hal-smartled/CHANGELOG.md index 74ff2c3486a..b56517e9cb3 100644 --- a/esp-hal-smartled/CHANGELOG.md +++ b/esp-hal-smartled/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed +- Removed the `clocks` parameter from `SmartLedsAdapter::new` (#1999) + ## 0.13.0 - 2024-08-29 ## 0.12.0 - 2024-07-15 diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 903f03ecf44..3da5f9506f2 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -10,10 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Implement `embedded-hal` output pin traits for `DummyPin` (#2019) -- Added `esp_hal::init` to simplify HAL initialisation (#1970) +- Added `esp_hal::init` to simplify HAL initialisation (#1970, #1999) ### Changed +- `Delay::new()` is now a `const` function (#1999) + ### Fixed - Fixed an issue with DMA transfers potentially not waking up the correct async task (#2065) @@ -23,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed `NoPinType` in favour of `DummyPin`. (#2068) - Removed the `async`, `embedded-hal-02`, `embedded-hal`, `embedded-io`, `embedded-io-async`, and `ufmt` features (#2070) - Removed the `GpioN` type aliasses. Use `GpioPin` instead. (#2073) +- Removed `Peripherals::take`. Use `esp_hal::init` to obtain `Peripherals` (#1999) ## [0.20.1] - 2024-08-30 @@ -80,7 +83,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed `FlashSafeDma` (#1856) - Remove redundant WithDmaSpi traits (#1975) - `IsFullDuplex` and `IsHalfDuplex` traits (#1985) -- `Peripherals::take` (#1999) ## [0.19.0] - 2024-07-15 diff --git a/esp-hal/src/delay.rs b/esp-hal/src/delay.rs index 4de0bcf19d8..244310111b6 100644 --- a/esp-hal/src/delay.rs +++ b/esp-hal/src/delay.rs @@ -39,7 +39,7 @@ pub use fugit::MicrosDurationU64; /// /// Uses the `SYSTIMER` peripheral internally for RISC-V devices, and the /// built-in Xtensa timer for Xtensa devices. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Default)] #[non_exhaustive] pub struct Delay; @@ -69,8 +69,7 @@ impl embedded_hal::delay::DelayNs for Delay { impl Delay { /// Creates a new `Delay` instance. - // Do not remove the argument, it makes sure that the clocks are initialized. - pub fn new() -> Self { + pub const fn new() -> Self { Self {} } diff --git a/esp-hal/src/lcd_cam/lcd/i8080.rs b/esp-hal/src/lcd_cam/lcd/i8080.rs index 4f8a7c8f7a7..1700fa534be 100644 --- a/esp-hal/src/lcd_cam/lcd/i8080.rs +++ b/esp-hal/src/lcd_cam/lcd/i8080.rs @@ -122,7 +122,7 @@ where // the LCD_PCLK divider must be at least 2. To make up for this the user // provided frequency is doubled to match. let (i, divider) = calculate_clkm( - (frequency.to_Hz() * 2 ) as _, + (frequency.to_Hz() * 2) as _, &[ clocks.xtal_clock.to_Hz() as _, clocks.cpu_clock.to_Hz() as _, diff --git a/esp-hal/src/uart.rs b/esp-hal/src/uart.rs index c7b11fd3054..a9c64c6f841 100644 --- a/esp-hal/src/uart.rs +++ b/esp-hal/src/uart.rs @@ -1256,7 +1256,7 @@ where let clk = match clock_source { ClockSource::Apb => clocks.apb_clock.to_Hz(), ClockSource::RefTick => REF_TICK.to_Hz(), /* ESP32(/-S2) TRM, section 3.2.4.2 - * (6.2.4.2 for S2) */ + * (6.2.4.2 for S2) */ }; T::register_block().conf0().modify(|_, w| { diff --git a/esp-wifi/CHANGELOG.md b/esp-wifi/CHANGELOG.md index 41162b1cc9c..f57e350d5a3 100644 --- a/esp-wifi/CHANGELOG.md +++ b/esp-wifi/CHANGELOG.md @@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed +- Removed the `clocks` parameter from `esp_wifi::initialize` (#1999) + ## 0.8.0 - 2024-08-29 ### Added diff --git a/esp-wifi/MIGRATING-0.8.md b/esp-wifi/MIGRATING-0.8.md new file mode 100644 index 00000000000..89aa5787d8c --- /dev/null +++ b/esp-wifi/MIGRATING-0.8.md @@ -0,0 +1,41 @@ +Migration Guide from 0.3.x to vNext +==================================== + +Initialsation +------------- + +You no longer have to set up clocks and pass them to `esp_wifi::initialize`. + +```diff + use esp_hal::{ +- clock::ClockControl, +- peripherals::Peripherals, + prelude::*, +- system::SystemControl, + }; + use esp_wifi::{ + initialize, + // ... + }; + + #[entry] + fn main() -> ! { +- let peripherals = Peripherals::take(); +- let system = SystemControl::new(peripherals.SYSTEM); +- let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); ++ let peripherals = esp_hal::init(esp_hal::Config::default()); + + let timg0 = TimerGroup::new(peripherals.TIMG0); + + let init = initialize( + EspWifiInitFor::Wifi, + timg0.timer0, + Rng::new(peripherals.RNG), + peripherals.RADIO_CLK, +- &clocks, + ) + .unwrap(); + + // ... + } +``` From 3cd517777a703a676d515173d9d6afdf521d4784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 2 Sep 2024 19:28:07 +0200 Subject: [PATCH 3/8] Initialise Clocks in a critical section --- esp-hal/src/clock/mod.rs | 10 +++------- esp-hal/src/lib.rs | 2 +- hil-test/tests/delay.rs | 2 +- hil-test/tests/get_time.rs | 2 +- hil-test/tests/qspi_write.rs | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/esp-hal/src/clock/mod.rs b/esp-hal/src/clock/mod.rs index 26fcebbb01c..006237dbaf6 100644 --- a/esp-hal/src/clock/mod.rs +++ b/esp-hal/src/clock/mod.rs @@ -314,17 +314,13 @@ static mut ACTIVE_CLOCKS: Option = None; impl Clocks { pub(crate) fn init(cpu_clock_speed: CpuClock) { - unsafe { ACTIVE_CLOCKS = Some(Self::configure(cpu_clock_speed)) }; + critical_section::with(|_| { + unsafe { ACTIVE_CLOCKS = Some(Self::configure(cpu_clock_speed)) }; + }) } /// Get the active clock configuration. // This should be fine since we only allow reading after initialization. - // - // FIXME: technically, this needs to be unsafe to avoid requiring a critical - // section - we need the user to promise not to poll `Clocks::get` at the - // same time as `esp_hal::init` is running (e.g. initializing in an interrupt - // handler). Alternatively, we can require a peripheral reference (any) to be - // passed as those can only be returned by `esp_hal::init`. pub fn get() -> &'static Clocks { unwrap!(unsafe { ACTIVE_CLOCKS.as_ref() }) } diff --git a/esp-hal/src/lib.rs b/esp-hal/src/lib.rs index 0e5ef65b2bd..f5890a16ec7 100644 --- a/esp-hal/src/lib.rs +++ b/esp-hal/src/lib.rs @@ -712,7 +712,7 @@ macro_rules! before_snippet { # loop {} # } # fn main() { -# let peripherals = esp_hal::init(esp_hal::Config::default()); +# let mut peripherals = esp_hal::init(esp_hal::Config::default()); "# }; } diff --git a/hil-test/tests/delay.rs b/hil-test/tests/delay.rs index 4dbb24c677c..82296ed94f7 100644 --- a/hil-test/tests/delay.rs +++ b/hil-test/tests/delay.rs @@ -21,7 +21,7 @@ mod tests { #[init] fn init() -> Context { let peripherals = esp_hal::init(esp_hal::Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); Context { delay } } diff --git a/hil-test/tests/get_time.rs b/hil-test/tests/get_time.rs index 3e3e826f07f..6c7eadecd62 100644 --- a/hil-test/tests/get_time.rs +++ b/hil-test/tests/get_time.rs @@ -5,7 +5,7 @@ #![no_std] #![no_main] -use esp_hal::{delay::Delay, prelude::*}; +use esp_hal::delay::Delay; use hil_test as _; struct Context { diff --git a/hil-test/tests/qspi_write.rs b/hil-test/tests/qspi_write.rs index 6f690c8cea2..441aa315c30 100644 --- a/hil-test/tests/qspi_write.rs +++ b/hil-test/tests/qspi_write.rs @@ -108,7 +108,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); From a221caba43516f22cdd2b114b60a9cec72481319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Tue, 3 Sep 2024 13:02:14 +0200 Subject: [PATCH 4/8] Fix calling now() before init --- esp-hal/src/clock/mod.rs | 77 ++++++++++++++++++++++++++++------- esp-hal/src/timer/systimer.rs | 2 +- 2 files changed, 63 insertions(+), 16 deletions(-) diff --git a/esp-hal/src/clock/mod.rs b/esp-hal/src/clock/mod.rs index 006237dbaf6..8e07a116043 100644 --- a/esp-hal/src/clock/mod.rs +++ b/esp-hal/src/clock/mod.rs @@ -319,22 +319,41 @@ impl Clocks { }) } + fn try_get() -> Option<&'static Clocks> { + unsafe { ACTIVE_CLOCKS.as_ref() } + } + /// Get the active clock configuration. - // This should be fine since we only allow reading after initialization. pub fn get() -> &'static Clocks { - unwrap!(unsafe { ACTIVE_CLOCKS.as_ref() }) + unwrap!(Self::try_get()) + } + + /// Returns the xtal frequency. + /// + /// This function will run the frequency estimation if called before + /// [`esp_hal::init()`]. + pub fn xtal_freq() -> HertzU32 { + if let Some(clocks) = Self::try_get() { + clocks.xtal_clock + } else { + Self::measure_xtal_frequency().frequency() + } } } #[cfg(esp32)] impl Clocks { - /// Configure the CPU clock speed. - pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { - let xtal_freq = if RtcClock::estimate_xtal_frequency() > 33 { + fn measure_xtal_frequency() -> XtalClock { + if RtcClock::estimate_xtal_frequency() > 33 { XtalClock::RtcXtalFreq40M } else { XtalClock::RtcXtalFreq26M - }; + } + } + + /// Configure the CPU clock speed. + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { + let xtal_freq = Self::measure_xtal_frequency(); if cpu_clock_speed != CpuClock::default() { let pll_freq = match cpu_clock_speed { @@ -364,13 +383,17 @@ impl Clocks { #[cfg(esp32c2)] impl Clocks { - /// Configure the CPU clock speed. - pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { - let xtal_freq = if RtcClock::estimate_xtal_frequency() > 33 { + fn measure_xtal_frequency() -> XtalClock { + if RtcClock::estimate_xtal_frequency() > 33 { XtalClock::RtcXtalFreq40M } else { XtalClock::RtcXtalFreq26M - }; + } + } + + /// Configure the CPU clock speed. + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { + let xtal_freq = Self::measure_xtal_frequency(); let apb_freq; if cpu_clock_speed != CpuClock::default() { @@ -401,9 +424,13 @@ impl Clocks { #[cfg(esp32c3)] impl Clocks { + fn measure_xtal_frequency() -> XtalClock { + XtalClock::RtcXtalFreq40M + } + /// Configure the CPU clock speed. pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { - let xtal_freq = XtalClock::RtcXtalFreq40M; + let xtal_freq = Self::measure_xtal_frequency(); let apb_freq; if cpu_clock_speed != CpuClock::default() { @@ -433,9 +460,13 @@ impl Clocks { #[cfg(esp32c6)] impl Clocks { + fn measure_xtal_frequency() -> XtalClock { + XtalClock::RtcXtalFreq40M + } + /// Configure the CPU clock speed. pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { - let xtal_freq = XtalClock::RtcXtalFreq40M; + let xtal_freq = Self::measure_xtal_frequency(); let apb_freq; if cpu_clock_speed != CpuClock::default() { @@ -466,9 +497,13 @@ impl Clocks { #[cfg(esp32h2)] impl Clocks { + fn measure_xtal_frequency() -> XtalClock { + XtalClock::RtcXtalFreq32M + } + /// Configure the CPU clock speed. pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { - let xtal_freq = XtalClock::RtcXtalFreq32M; + let xtal_freq = Self::measure_xtal_frequency(); let apb_freq; if cpu_clock_speed != CpuClock::default() { @@ -501,8 +536,14 @@ impl Clocks { #[cfg(esp32s2)] impl Clocks { + fn measure_xtal_frequency() -> XtalClock { + XtalClock::RtcXtalFreq40M + } + /// Configure the CPU clock speed. pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { + let xtal_freq = Self::measure_xtal_frequency(); + if cpu_clock_speed != CpuClock::default() { clocks_ll::set_cpu_clock(cpu_clock_speed); } @@ -510,15 +551,21 @@ impl Clocks { Self { cpu_clock: cpu_clock_speed.frequency(), apb_clock: HertzU32::MHz(80), - xtal_clock: HertzU32::MHz(40), + xtal_clock: xtal_freq.frequency(), } } } #[cfg(esp32s3)] impl Clocks { + fn measure_xtal_frequency() -> XtalClock { + XtalClock::RtcXtalFreq40M + } + /// Configure the CPU clock speed. pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self { + let xtal_freq = Self::measure_xtal_frequency(); + if cpu_clock_speed != CpuClock::default() { clocks_ll::set_cpu_clock(cpu_clock_speed); } @@ -526,7 +573,7 @@ impl Clocks { Self { cpu_clock: cpu_clock_speed.frequency(), apb_clock: HertzU32::MHz(80), - xtal_clock: HertzU32::MHz(40), + xtal_clock: xtal_freq.frequency(), crypto_pwm_clock: HertzU32::MHz(160), } } diff --git a/esp-hal/src/timer/systimer.rs b/esp-hal/src/timer/systimer.rs index 149c05d26ac..d482ee0c67b 100644 --- a/esp-hal/src/timer/systimer.rs +++ b/esp-hal/src/timer/systimer.rs @@ -142,7 +142,7 @@ impl<'d> SystemTimer<'d> { const MULTIPLIER: u64 = 10_000_000 / 25; } } - let xtal_freq_mhz = crate::clock::Clocks::get().xtal_clock.to_MHz(); + let xtal_freq_mhz = crate::clock::Clocks::xtal_freq().to_MHz(); xtal_freq_mhz as u64 * MULTIPLIER } From 5c2018ef19b47a583bb7855b14d8cb68e67f654d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Tue, 3 Sep 2024 13:23:27 +0200 Subject: [PATCH 5/8] Fix doc --- esp-hal/src/clock/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-hal/src/clock/mod.rs b/esp-hal/src/clock/mod.rs index 8e07a116043..9a0eeb84f09 100644 --- a/esp-hal/src/clock/mod.rs +++ b/esp-hal/src/clock/mod.rs @@ -331,7 +331,7 @@ impl Clocks { /// Returns the xtal frequency. /// /// This function will run the frequency estimation if called before - /// [`esp_hal::init()`]. + /// [`crate::init()`]. pub fn xtal_freq() -> HertzU32 { if let Some(clocks) = Self::try_get() { clocks.xtal_clock From 4eea75e0a11d51e08391d26639d8ecad99fc58d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Tue, 3 Sep 2024 18:11:09 +0200 Subject: [PATCH 6/8] Fix esp-wifi migration guide --- esp-wifi/{MIGRATING-0.8.md => MIGRATING-0.9.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename esp-wifi/{MIGRATING-0.8.md => MIGRATING-0.9.md} (96%) diff --git a/esp-wifi/MIGRATING-0.8.md b/esp-wifi/MIGRATING-0.9.md similarity index 96% rename from esp-wifi/MIGRATING-0.8.md rename to esp-wifi/MIGRATING-0.9.md index 89aa5787d8c..3763b185f8e 100644 --- a/esp-wifi/MIGRATING-0.8.md +++ b/esp-wifi/MIGRATING-0.9.md @@ -1,4 +1,4 @@ -Migration Guide from 0.3.x to vNext +Migration Guide from 0.9.x to vNext ==================================== Initialsation From 87c4cdb944352cfafb86e86ab63193d1f1393634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Wed, 4 Sep 2024 12:16:31 +0200 Subject: [PATCH 7/8] Add safety comment --- esp-hal/src/clock/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/esp-hal/src/clock/mod.rs b/esp-hal/src/clock/mod.rs index 9a0eeb84f09..1ad30294322 100644 --- a/esp-hal/src/clock/mod.rs +++ b/esp-hal/src/clock/mod.rs @@ -320,7 +320,10 @@ impl Clocks { } fn try_get() -> Option<&'static Clocks> { - unsafe { ACTIVE_CLOCKS.as_ref() } + unsafe { + // Safety: ACTIVE_CLOCKS is only set in `init` and never modified after that. + ACTIVE_CLOCKS.as_ref() + } } /// Get the active clock configuration. From f21f08d32cc7aed67b0c6194af450f8cbbdb7761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Wed, 4 Sep 2024 15:10:02 +0200 Subject: [PATCH 8/8] Update tests --- hil-test/tests/gpio.rs | 2 +- hil-test/tests/i2c.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hil-test/tests/gpio.rs b/hil-test/tests/gpio.rs index c98dd3b428c..2b395de0cd1 100644 --- a/hil-test/tests/gpio.rs +++ b/hil-test/tests/gpio.rs @@ -74,7 +74,7 @@ mod tests { let (gpio1, gpio2) = hil_test::common_test_pins!(io); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); esp_hal_embassy::init(timg0.timer0); Context { diff --git a/hil-test/tests/i2c.rs b/hil-test/tests/i2c.rs index 3cf18e43191..3e8e1ef4d5d 100644 --- a/hil-test/tests/i2c.rs +++ b/hil-test/tests/i2c.rs @@ -31,14 +31,14 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let (sda, scl) = hil_test::i2c_pins!(io); // Create a new peripheral object with the described wiring and standard // I2C clock speed: - let i2c = I2C::new(peripherals.I2C0, sda, scl, 100.kHz(), &clocks); + let i2c = I2C::new(peripherals.I2C0, sda, scl, 100.kHz()); Context { i2c } }