From 94f418ebcfd4b4d758b6a3f387d2e6f662b78490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 26 Aug 2024 14:07:41 +0200 Subject: [PATCH] Clean up passing clocks to drivers --- esp-hal-embassy/src/lib.rs | 8 +- esp-hal-embassy/src/time_driver.rs | 2 +- esp-hal-smartled/src/lib.rs | 10 +- esp-hal/doc-helper/before | 2 +- esp-hal/src/analog/adc/mod.rs | 2 +- esp-hal/src/analog/dac.rs | 2 +- esp-hal/src/clock/mod.rs | 191 +++++++----------- esp-hal/src/delay.rs | 6 +- esp-hal/src/dma/mod.rs | 1 - esp-hal/src/i2c.rs | 39 ++-- esp-hal/src/i2s.rs | 10 - esp-hal/src/lcd_cam/cam.rs | 13 +- esp-hal/src/lcd_cam/lcd/i8080.rs | 20 +- esp-hal/src/ledc/mod.rs | 17 +- esp-hal/src/ledc/timer.rs | 26 +-- esp-hal/src/lib.rs | 13 +- esp-hal/src/mcpwm/mod.rs | 71 ++++--- esp-hal/src/mcpwm/operator.rs | 6 +- esp-hal/src/mcpwm/timer.rs | 18 +- esp-hal/src/parl_io.rs | 4 - esp-hal/src/rmt.rs | 25 +-- 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 | 47 ++--- esp-hal/src/timer/mod.rs | 4 +- esp-hal/src/timer/timg.rs | 75 +++---- esp-hal/src/twai/mod.rs | 24 +-- esp-hal/src/uart.rs | 108 +++++----- esp-wifi/src/lib.rs | 11 +- 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/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 | 7 +- .../embassy_i2c_bmp180_calibration_data.rs | 7 +- examples/src/bin/embassy_i2s_read.rs | 7 +- examples/src/bin/embassy_i2s_sound.rs | 7 +- 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 | 8 +- 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_timer.rs | 6 +- examples/src/bin/gpio_interrupt.rs | 4 +- examples/src/bin/hello_rgb.rs | 10 +- examples/src/bin/hello_world.rs | 6 +- .../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 +- .../bin/ieee802154_send_broadcast_frame.rs | 2 +- examples/src/bin/ieee802154_send_frame.rs | 2 +- examples/src/bin/ieee802154_sniffer.rs | 2 +- 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_uart.rs | 3 +- examples/src/bin/mcpwm.rs | 6 +- 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/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/rtc_time.rs | 4 +- 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/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_dma.rs | 2 +- hil-test/tests/clock_monitor.rs | 2 +- hil-test/tests/delay.rs | 4 +- hil-test/tests/dma_mem2mem.rs | 2 +- hil-test/tests/embassy_interrupt_executor.rs | 6 +- hil-test/tests/embassy_timers_executors.rs | 12 +- hil-test/tests/get_time.rs | 2 +- hil-test/tests/gpio.rs | 8 +- hil-test/tests/i2s.rs | 5 +- hil-test/tests/i2s_async.rs | 3 +- hil-test/tests/lcd_cam_i8080.rs | 2 +- hil-test/tests/lcd_cam_i8080_async.rs | 2 +- hil-test/tests/pcnt.rs | 4 +- hil-test/tests/rmt.rs | 2 +- hil-test/tests/spi_full_duplex.rs | 2 +- hil-test/tests/spi_half_duplex_read.rs | 2 +- hil-test/tests/spi_half_duplex_write.rs | 2 +- hil-test/tests/systimer.rs | 2 +- hil-test/tests/twai.rs | 3 +- hil-test/tests/uart.rs | 4 +- 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 +- 147 files changed, 622 insertions(+), 760 deletions(-) diff --git a/esp-hal-embassy/src/lib.rs b/esp-hal-embassy/src/lib.rs index fe6fbfb563a..1de4092d70a 100644 --- a/esp-hal-embassy/src/lib.rs +++ b/esp-hal-embassy/src/lib.rs @@ -140,12 +140,12 @@ impl TimerCollection for &'static mut [Timer; N] { #[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..58aa7146c5b 100644 --- a/esp-hal-embassy/src/time_driver.rs +++ b/esp-hal-embassy/src/time_driver.rs @@ -45,7 +45,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..b23b231c5cf 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,7 +106,10 @@ where let channel = channel.configure(pin, config).unwrap(); // Assume the RMT peripheral is set up to use the APB clock - let src_clock = clocks.apb_clock.to_MHz(); + let src_clock = critical_section::with(|cs| { + let clocks = Clocks::get(cs); + clocks.apb_clock.to_MHz(); + }); Self { channel: Some(channel), diff --git a/esp-hal/doc-helper/before b/esp-hal/doc-helper/before index 877ecda6559..bc8c1375376 100644 --- a/esp-hal/doc-helper/before +++ b/esp-hal/doc-helper/before @@ -7,4 +7,4 @@ # loop {} # } # fn main() { -# let (peripherals, clocks) = esp_hal::init(Config::default()); \ No newline at end of file +# let peripherals = esp_hal::init(Config::default()); \ No newline at end of file diff --git a/esp-hal/src/analog/adc/mod.rs b/esp-hal/src/analog/adc/mod.rs index 7a1aa62413f..d24e159bbc5 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 d0244c4ba9a..e98ade2e4ea 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 ccafb466bd8..ea21406276a 100644 --- a/esp-hal/src/clock/mod.rs +++ b/esp-hal/src/clock/mod.rs @@ -48,7 +48,7 @@ //! # } //! # 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 = Config::default(); //! config.cpu_clock = CpuClock::max(); //! config @@ -63,12 +63,10 @@ #![cfg_attr(esp32h2, doc = "// let system = esp_hal::init(CpuClock::Clock96MHz);")] //! // //! // Initialize with default clock frequency for this chip -//! // let (peripherals, clocks) = esp_hal::init(Config::default()); +//! // let peripherals = esp_hal::init(Config::default()); //! # } //! ``` -use core::marker::PhantomData; - use fugit::HertzU32; #[cfg(esp32c2)] use portable_atomic::{AtomicU32, Ordering}; @@ -271,38 +269,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, @@ -357,31 +328,33 @@ cfg_if::cfg_if! { } } -/// 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, -} +use core::cell::{Ref, RefCell}; + +use critical_section::{CriticalSection, Mutex}; -impl ClockControl { - pub(crate) fn new(clock: CpuClock) -> Self { - Self::configure(clock) +static ACTIVE_CLOCKS: Mutex>> = Mutex::new(RefCell::new(None)); + +impl Clocks { + pub(crate) fn init(cpu_clock_speed: CpuClock) { + critical_section::with(|cs| { + ACTIVE_CLOCKS + .borrow(cs) + .replace(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. + pub fn get<'a>(cs: CriticalSection<'a>) -> Ref<'a, Self> { + Ref::map(ACTIVE_CLOCKS.borrow_ref(cs), |active_clocks| { + unwrap!(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 { @@ -401,25 +374,23 @@ 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 { @@ -446,20 +417,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; @@ -480,20 +449,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; @@ -514,21 +481,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; @@ -550,51 +515,45 @@ impl ClockControl { } 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), - }, + 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 c15c6e66ae6..7372e41e300 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 @@ -75,7 +73,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 570ec15df6d..e0bd0cacb27 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 e6a2edc9b5e..2875ca6a86b 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 { @@ -310,7 +309,6 @@ where sda: impl Peripheral

+ 'd, scl: impl Peripheral

+ 'd, frequency: HertzU32, - clocks: &Clocks<'d>, timeout: Option, ) -> Self { crate::into_ref!(i2c, sda, scl); @@ -362,7 +360,7 @@ where crate::private::Internal, ); - i2c.peripheral.setup(frequency, clocks, timeout); + i2c.peripheral.setup(frequency, timeout); i2c } @@ -386,9 +384,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. @@ -399,10 +396,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) } } @@ -430,9 +426,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. @@ -443,10 +438,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, @@ -1020,7 +1014,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) @@ -1051,13 +1045,20 @@ pub trait Instance: crate::private::Sealed { // FIXME if we ever change this we need to adapt `set_frequency` for ESP32 self.set_filter(Some(7), Some(7)); - // Configure frequency - #[cfg(esp32)] - self.set_frequency(clocks.i2c_clock.convert(), frequency, timeout); - #[cfg(esp32s2)] - self.set_frequency(clocks.apb_clock.convert(), frequency, timeout); - #[cfg(not(any(esp32, esp32s2)))] - self.set_frequency(clocks.xtal_clock.convert(), frequency, timeout); + critical_section::with(|cs| { + let clocks = Clocks::get(cs); + + // Configure frequency + cfg_if::cfg_if! { + if #[cfg(esp32)] { + self.set_frequency(clocks.i2c_clock.convert(), frequency, timeout); + } else if #[cfg(esp32s2)] { + self.set_frequency(clocks.apb_clock.convert(), frequency, timeout); + } else { + self.set_frequency(clocks.xtal_clock.convert(), frequency, timeout); + } + } + }); self.update_config(); diff --git a/esp-hal/src/i2s.rs b/esp-hal/src/i2s.rs index ac390c9fde0..c8e273eae5a 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 @@ -363,7 +360,6 @@ where sample_rate, 2, data_format.channel_bits(), - clocks, )); I::configure(&standard, &data_format); I::set_master(); @@ -457,7 +453,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 +467,6 @@ where channel, tx_descriptors, rx_descriptors, - clocks, ) } @@ -488,7 +482,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 +495,6 @@ where channel, tx_descriptors, rx_descriptors, - clocks, ) } @@ -901,7 +893,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 +2105,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..ef5249c82aa 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,18 +145,18 @@ where descriptors: &'static mut [DmaDescriptor], _pins: P, frequency: HertzU32, - clocks: &Clocks<'d>, ) -> Self { let lcd_cam = cam.lcd_cam; - let (i, divider) = calculate_clkm( - frequency.to_Hz() as _, - &[ + let clocks = critical_section::with(|cs| { + let clocks = Clocks::get(cs); + [ clocks.xtal_clock.to_Hz() as _, clocks.cpu_clock.to_Hz() as _, clocks.crypto_pwm_clock.to_Hz() as _, - ], - ); + ] + }); + let (i, divider) = calculate_clkm(frequency.to_Hz() as _, &clocks); lcd_cam.cam_ctrl().write(|w| { // Force enable the clock for all configuration registers. diff --git a/esp-hal/src/lcd_cam/lcd/i8080.rs b/esp-hal/src/lcd_cam/lcd/i8080.rs index 694d73b723c..ebba27513ab 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(), //! i8080::Config::default(), -//! &clocks, //! ) //! .with_ctrl_pins(io.pins.gpio0, io.pins.gpio47); //! @@ -114,23 +113,26 @@ 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 = critical_section::with(|cs| { + let clocks = Clocks::get(cs); + [ + clocks.xtal_clock.to_Hz() as _, + clocks.cpu_clock.to_Hz() as _, + clocks.crypto_pwm_clock.to_Hz() as _, + ] + }); + // 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 _, - &[ - clocks.xtal_clock.to_Hz() as _, - clocks.cpu_clock.to_Hz() as _, - clocks.crypto_pwm_clock.to_Hz() as _, - ], + (frequency.to_Hz() * 2 ) as _, + &clocks, ); lcd_cam.lcd_clock().write(|w| unsafe { 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..d6a9c3e4159 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 => critical_section::with(|cs| { + let clocks = Clocks::get(cs); + clocks.apb_clock + }), }) } @@ -336,8 +333,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 { + LSClockSource::APBClk => critical_section::with(|cs| { + let clocks = Clocks::get(cs); + clocks.apb_clock + }), }) } diff --git a/esp-hal/src/lib.rs b/esp-hal/src/lib.rs index 66aa635124a..a7fb013de1c 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(Config::default()); +//! let peripherals = esp_hal::init(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(); @@ -637,7 +637,7 @@ macro_rules! before_snippet { } use crate::{ - clock::{ClockControl, Clocks, CpuClock}, + clock::{Clocks, CpuClock}, peripherals::Peripherals, }; @@ -652,9 +652,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 e0e89f6f995..7863079209c 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,20 +203,25 @@ 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 { - #[cfg(esp32)] - let source_clock = clocks.pwm_clock; - #[cfg(esp32c6)] - let source_clock = clocks.crypto_clock; - #[cfg(esp32s3)] - let source_clock = clocks.crypto_pwm_clock; - #[cfg(esp32h2)] - let source_clock = clocks.xtal_clock; + pub fn with_prescaler(prescaler: u8) -> Self { + let source_clock = critical_section::with(|cs| { + let clocks = Clocks::get(cs); + cfg_if::cfg_if! { + if #[cfg(esp32)] { + clocks.pwm_clock + } else if #[cfg(esp32c6)] { + clocks.crypto_clock + } else if #[cfg(esp32s3)] { + clocks.crypto_pwm_clock + } else if #[cfg(esp32h2)] { + clocks.xtal_clock + } + } + }); Self { frequency: source_clock / (prescaler as u32 + 1), prescaler, - phantom: PhantomData, } } @@ -235,18 +239,21 @@ 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 { - #[cfg(esp32)] - let source_clock = clocks.pwm_clock; - #[cfg(esp32c6)] - let source_clock = clocks.crypto_clock; - #[cfg(esp32s3)] - let source_clock = clocks.crypto_pwm_clock; - #[cfg(esp32h2)] - let source_clock = clocks.xtal_clock; + pub fn with_frequency(target_freq: HertzU32) -> Result { + let source_clock = critical_section::with(|cs| { + let clocks = Clocks::get(cs); + cfg_if::cfg_if! { + if #[cfg(esp32)] { + clocks.pwm_clock + } else if #[cfg(esp32c6)] { + clocks.crypto_clock + } else if #[cfg(esp32s3)] { + clocks.crypto_pwm_clock + } else if #[cfg(esp32h2)] { + clocks.xtal_clock + } + } + }); if target_freq.raw() == 0 || target_freq > source_clock { return Err(FrequencyError); @@ -257,7 +264,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. @@ -282,7 +289,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) } @@ -300,7 +307,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 2f7043a5819..388540faa4a 100644 --- a/esp-hal/src/mcpwm/operator.rs +++ b/esp-hal/src/mcpwm/operator.rs @@ -486,7 +486,7 @@ impl<'d, Pin: OutputPin, PWM: PwmPeripheral, const OP: u8, const IS_A: bool> /// # use esp_hal::mcpwm::{McPwm, PeripheralClockConfig}; /// # use esp_hal::mcpwm::operator::{DeadTimeCfg, PwmPinConfig, PWMStream}; /// # use esp_hal::gpio::Io; -/// let (peripherals, clocks) = esp_hal::init(Config::default()); +/// let peripherals = esp_hal::init(Config::default()); /// # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); /// // active high complementary using PWMA input /// let bridge_active = DeadTimeCfg::new_ahc(); @@ -495,11 +495,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 72cfdd3ddc8..e1efafb0e3d 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/rmt.rs b/esp-hal/src/rmt.rs index 4e485958eca..8d49b712757 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, @@ -218,7 +216,6 @@ where pub(crate) fn new_internal( peripheral: impl Peripheral

+ 'd, frequency: HertzU32, - _clocks: &Clocks<'d>, ) -> Result { let me = Rmt::create(peripheral); @@ -230,11 +227,13 @@ where PeripheralClockControl::reset(crate::system::Peripheral::Rmt); PeripheralClockControl::enable(crate::system::Peripheral::Rmt); - #[cfg(not(any(esp32, esp32s2)))] - me.configure_clock(frequency, _clocks)?; - - #[cfg(any(esp32, esp32s2))] - self::chip_specific::configure_clock(); + cfg_if::cfg_if! { + if #[cfg(any(esp32, esp32s2))] { + self::chip_specific::configure_clock(); + } else { + me.configure_clock(frequency)?; + } + } Ok(me) } @@ -248,7 +247,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 { @@ -272,9 +271,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 +290,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/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 c379228c923..6f0d26b0a10 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 909ef5e505a..119b84aa9c5 100644 --- a/esp-hal/src/spi/master.rs +++ b/esp-hal/src/spi/master.rs @@ -51,7 +51,6 @@ //! peripherals.SPI2, //! 100.kHz(), //! SpiMode::Mode0, -//! &clocks, //! ) //! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)); //! # } @@ -514,10 +513,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. @@ -617,7 +615,6 @@ where spi: PeripheralRef<'d, T>, frequency: HertzU32, mode: SpiMode, - clocks: &Clocks<'d>, ) -> Spi<'d, T, FullDuplexMode> { spi.reset_peripheral(); spi.enable_peripheral(); @@ -626,7 +623,7 @@ where spi, _mode: PhantomData, }; - spi.spi.setup(frequency, clocks); + spi.spi.setup(frequency); spi.spi.init(); spi.spi.set_data_mode(mode); @@ -637,8 +634,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); } } @@ -654,10 +651,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. @@ -825,7 +821,6 @@ where spi: PeripheralRef<'d, T>, frequency: HertzU32, mode: SpiMode, - clocks: &Clocks<'d>, ) -> Spi<'d, T, HalfDuplexMode> { spi.reset_peripheral(); spi.enable_peripheral(); @@ -834,7 +829,7 @@ where spi, _mode: PhantomData, }; - spi.spi.setup(frequency, clocks); + spi.spi.setup(frequency); spi.spi.init(); spi.spi.set_data_mode(mode); @@ -845,8 +840,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. @@ -1136,8 +1131,8 @@ pub mod dma { DmaMode: 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); } } @@ -2743,12 +2738,18 @@ 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<'_>) { - #[cfg(not(esp32h2))] - let apb_clk_freq: HertzU32 = HertzU32::Hz(clocks.apb_clock.to_Hz()); - // ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK - #[cfg(esp32h2)] - let apb_clk_freq: HertzU32 = HertzU32::Hz(clocks.pll_48m_clock.to_Hz()); + fn setup(&mut self, frequency: HertzU32) { + let apb_clk_freq = critical_section::with(|cs| { + let clocks = Clocks::get(cs); + cfg_if::cfg_if! { + if #[cfg(esp32h2)] { + // ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK + HertzU32::Hz(clocks.pll_48m_clock.to_Hz()) + } else { + HertzU32::Hz(clocks.apb_clock.to_Hz()) + } + } + }); let reg_val: u32; let duty_cycle = 128; @@ -2942,7 +2943,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| { @@ -2955,7 +2956,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 2e2552684a5..7f2fa28a7ec 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/timg.rs b/esp-hal/src/timer/timg.rs index a4701f440de..1a62518b4d0 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()); @@ -246,12 +246,13 @@ impl TimerGroupInstance for TIMG1 { } } -impl<'d, T> TimerGroup<'d, T, Blocking> +impl<'d, T, DM> TimerGroup<'d, T, DM> where T: TimerGroupInstance, + DM: crate::Mode, { /// Construct a new instance of [`TimerGroup`] in blocking mode - pub fn new(_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(); @@ -259,15 +260,23 @@ where T::configure_src_clk(); - // ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK + let apb_clk_freq = critical_section::with(|cs| { + let clocks = Clocks::get(cs); + cfg_if::cfg_if! { + if #[cfg(esp32h2)] { + // ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK + clocks.pll_48m_clock + } else { + clocks.apb_clock + } + } + }); + let timer0 = Timer::new( Timer0 { phantom: PhantomData, }, - #[cfg(not(esp32h2))] - clocks.apb_clock, - #[cfg(esp32h2)] - clocks.pll_48m_clock, + apb_clk_freq, ); #[cfg(timg_timer1)] @@ -275,7 +284,7 @@ where Timer1 { phantom: PhantomData, }, - clocks.apb_clock, + apb_clk_freq, ); Self { @@ -288,45 +297,23 @@ where } } +impl<'d, T> TimerGroup<'d, T, Blocking> +where + T: TimerGroupInstance, +{ + /// Construct a new instance of [`TimerGroup`] in blocking mode + pub fn new(_timer_group: impl Peripheral

+ 'd) -> Self { + Self::new_inner(_timer_group) + } +} + impl<'d, T> TimerGroup<'d, T, Async> 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 { - crate::into_ref!(_timer_group); - - T::reset_peripheral(); - T::enable_peripheral(); - - T::configure_src_clk(); - - // ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK - let timer0 = Timer::new( - Timer0 { - phantom: PhantomData, - }, - #[cfg(not(esp32h2))] - clocks.apb_clock, - #[cfg(esp32h2)] - clocks.pll_48m_clock, - ); - - #[cfg(timg_timer1)] - let timer1 = Timer::new( - Timer1 { - phantom: PhantomData, - }, - clocks.apb_clock, - ); - - Self { - _timer_group, - timer0, - #[cfg(timg_timer1)] - timer1, - wdt: Wdt::new(), - } + 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 562b1b9b851..ab0ca0bd659 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 //! ); @@ -741,7 +739,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, @@ -805,7 +802,7 @@ where phantom: PhantomData, }; - cfg.set_baud_rate(baud_rate, clocks); + cfg.set_baud_rate(baud_rate); cfg } @@ -819,11 +816,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)); + critical_section::with(|cs| { + let apb_clock = Clocks::get(cs).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 @@ -926,11 +926,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 @@ -942,11 +941,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) } } @@ -973,12 +971,11 @@ 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); + Self::new_internal(peripheral, tx_pin, rx_pin, baud_rate, false, mode); this.internal_set_interrupt_handler(T::async_handler()); this } @@ -992,12 +989,11 @@ 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); + 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 f6c4d2e3a80..743cd5b076e 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, //! # uart::config::Config::default(), -//! # &clocks, //! # io.pins.gpio1, //! # io.pins.gpio2, //! # ).unwrap(); @@ -80,7 +78,6 @@ //! # let mut uart1 = Uart::new_with_config( //! # peripherals.UART1, //! # uart::config::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(); //! # } //! ``` //! @@ -588,10 +582,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 @@ -599,7 +592,6 @@ where pub fn new_with_config( uart: impl Peripheral

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

+ 'd, ) -> Result { crate::into_ref!(tx); @@ -607,7 +599,7 @@ where tx.connect_peripheral_to_output(T::tx_signal(), Internal); let (uart_tx, _) = - Uart::<'d, T, Blocking>::new_with_config_inner(uart, config, clocks)?.split(); + Uart::<'d, T, Blocking>::new_with_config_inner(uart, config)?.split(); Ok(uart_tx) } @@ -796,10 +788,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 @@ -807,7 +798,6 @@ where pub fn new_with_config( uart: impl Peripheral

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

+ 'd, ) -> Result { crate::into_ref!(rx); @@ -815,7 +805,7 @@ where rx.connect_input_to_peripheral(T::rx_signal(), Internal); let (_, uart_rx) = - Uart::<'d, T, Blocking>::new_with_config_inner(uart, config, clocks)?.split(); + Uart::<'d, T, Blocking>::new_with_config_inner(uart, config)?.split(); Ok(uart_rx) } @@ -830,7 +820,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 { @@ -841,13 +830,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 { @@ -858,14 +846,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 { @@ -874,7 +861,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) } } @@ -886,7 +873,6 @@ where pub(crate) fn new_with_config_inner( _uart: impl Peripheral

+ 'd, config: Config, - clocks: &Clocks<'d>, ) -> Result { Self::init(); @@ -902,7 +888,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); @@ -934,8 +920,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 @@ -1166,12 +1152,15 @@ where } #[cfg(any(esp32c2, esp32c3, esp32s3))] - fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource, clocks: &Clocks<'d>) { - let clk = match clock_source { - ClockSource::Apb => clocks.apb_clock.to_Hz(), - ClockSource::Xtal => clocks.xtal_clock.to_Hz(), - ClockSource::RcFast => RC_FAST_CLK.to_Hz(), - }; + fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource) { + let clk = critical_section::with(|cs| { + let clocks = Clocks::get(cs); + match clock_source { + ClockSource::Apb => clocks.apb_clock.to_Hz(), + ClockSource::Xtal => clocks.xtal_clock.to_Hz(), + ClockSource::RcFast => RC_FAST_CLK.to_Hz(), + } + }); let max_div = 0b1111_1111_1111 - 1; let clk_div = ((clk) + (max_div * baudrate) - 1) / (max_div * baudrate); @@ -1203,12 +1192,15 @@ where } #[cfg(any(esp32c6, esp32h2))] - fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource, clocks: &Clocks<'d>) { - let clk = match clock_source { - ClockSource::Apb => clocks.apb_clock.to_Hz(), - ClockSource::Xtal => clocks.xtal_clock.to_Hz(), - ClockSource::RcFast => RC_FAST_CLK.to_Hz(), - }; + fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource) { + let clk = critical_section::with(|cs| { + let clocks = Clocks::get(cs); + match clock_source { + ClockSource::Apb => clocks.apb_clock.to_Hz(), + ClockSource::Xtal => clocks.xtal_clock.to_Hz(), + ClockSource::RcFast => RC_FAST_CLK.to_Hz(), + } + }); let max_div = 0b1111_1111_1111 - 1; let clk_div = ((clk) + (max_div * baudrate) - 1) / (max_div * baudrate); @@ -1274,12 +1266,15 @@ where } #[cfg(any(esp32, esp32s2))] - fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource, clocks: &Clocks<'d>) { - 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) */ - }; + fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource) { + let clk = critical_section::with(|cs| { + let clocks = Clocks::get(cs); + 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) */ + } + }); T::register_block().conf0().modify(|_, w| { w.tick_ref_always_on().bit(match clock_source { @@ -1313,8 +1308,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(); } @@ -2176,7 +2171,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 { @@ -2187,7 +2181,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)] @@ -2205,21 +2199,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) } } @@ -2251,10 +2243,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 @@ -2262,14 +2253,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)] @@ -2338,10 +2328,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 @@ -2349,14 +2338,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 094a6e2785b..0a31d965aa6 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -287,13 +287,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(); /// # } @@ -303,11 +302,15 @@ 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. + let cpu_clock = critical_section::with(|cs| { + let clocks = Clocks::get(cs); + clocks.cpu_clock + }); + const MIN_CLOCK: u32 = 80; - if clocks.cpu_clock < MegahertzU32::MHz(MIN_CLOCK) { + if 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 ab11bb5e89e..082a052b954 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(Config::default()); + let peripherals = esp_hal::init(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 d1d667a4c35..b8af4b0411f 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(Config::default()); + let peripherals = esp_hal::init(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 d41bf15d288..efbf71efb76 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(Config::default()); + let peripherals = esp_hal::init(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 fc592c4f535..36777c308f1 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(Config::default()); + let peripherals = esp_hal::init(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 435601cbc2c..013aa8f3585 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(Config::default()); + let peripherals = esp_hal::init(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 b379a9b3bd9..b208dbf453a 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(Config::default()); + let peripherals = esp_hal::init(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/dma_extmem2mem.rs b/examples/src/bin/dma_extmem2mem.rs index a6ff9a09963..bf11590f8b2 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(Config::default()); + let peripherals = esp_hal::init(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 5c153ecbfb4..5a54381cc98 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(Config::default()); + let peripherals = esp_hal::init(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 6e2b4a10079..97e80e7237b 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(Config::default()); + let peripherals = esp_hal::init(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 f5ff82fa146..d2a827ffaf9 100644 --- a/examples/src/bin/embassy_i2c.rs +++ b/examples/src/bin/embassy_i2c.rs @@ -24,10 +24,10 @@ use lis3dh_async::{Lis3dh, Range, SlaveAddr}; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(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); @@ -36,7 +36,6 @@ async fn main(_spawner: Spawner) { io.pins.gpio4, io.pins.gpio5, 400.kHz(), - &clocks, ); let mut lis3dh = Lis3dh::new_i2c(i2c0, SlaveAddr::Alternate).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 e30d08eec9e..20a2106ee69 100644 --- a/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs +++ b/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs @@ -24,10 +24,10 @@ 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(Config::default()); + let peripherals = esp_hal::init(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); @@ -36,7 +36,6 @@ async fn main(_spawner: Spawner) { io.pins.gpio4, io.pins.gpio5, 400.kHz(), - &clocks, ); loop { diff --git a/examples/src/bin/embassy_i2s_read.rs b/examples/src/bin/embassy_i2s_read.rs index ac2f549840e..c7f6b2f788c 100644 --- a/examples/src/bin/embassy_i2s_read.rs +++ b/examples/src/bin/embassy_i2s_read.rs @@ -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(Config::default()); + let peripherals = esp_hal::init(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 29320016823..8884107bc41 100644 --- a/examples/src/bin/embassy_i2s_sound.rs +++ b/examples/src/bin/embassy_i2s_sound.rs @@ -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(Config::default()); + let peripherals = esp_hal::init(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 aca554f8254..d1c81bcec8a 100644 --- a/examples/src/bin/embassy_multicore.rs +++ b/examples/src/bin/embassy_multicore.rs @@ -61,16 +61,16 @@ async fn control_led( #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(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(); let timers = [OneShotTimer::new(timer0), OneShotTimer::new(timer1)]; let timers = mk_static!([OneShotTimer; 2], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(timers); 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 f9679b41516..d13bb1f9ba0 100644 --- a/examples/src/bin/embassy_multicore_interrupt.rs +++ b/examples/src/bin/embassy_multicore_interrupt.rs @@ -82,18 +82,18 @@ async fn enable_disable_led(control: &'static Signal ! { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(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(); let timers = [OneShotTimer::new(timer0), OneShotTimer::new(timer1)]; let timers = mk_static!([OneShotTimer; 2], timers); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(timers); 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 f5b267f4ed1..275654784ba 100644 --- a/examples/src/bin/embassy_multiprio.rs +++ b/examples/src/bin/embassy_multiprio.rs @@ -82,11 +82,11 @@ async fn main(low_prio_spawner: Spawner) { esp_println::logger::init_logger_from_env(); println!("Init!"); - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(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(); let timer0 = OneShotTimer::new(timer0); @@ -97,14 +97,14 @@ async fn main(low_prio_spawner: Spawner) { let alarm0: ErasedTimer = systimer.alarm0.into(); let timer1 = OneShotTimer::new(alarm0); } else { - let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); + let timg1 = TimerGroup::new(peripherals.TIMG1); let timer0: ErasedTimer = timg1.timer0.into(); let timer1 = OneShotTimer::new(timer0); } } let timers = mk_static!([OneShotTimer; 2], [timer0, timer1]); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(timers); 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 240605be205..4f7f4011ac3 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(Config::default()); + let peripherals = esp_hal::init(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 ba88313e9f7..bb4650405ca 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(Config::default()); + let peripherals = esp_hal::init(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 06c82453713..6d508831d70 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, Gpio5>) { #[esp_hal_embassy::main] async fn main(spawner: Spawner) { println!("Init!"); - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(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 8eed5f6c971..09cd0320012 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(Config::default()); + let peripherals = esp_hal::init(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 bf0cd15016a..17fe60da6de 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(Config::default()); + let peripherals = esp_hal::init(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); @@ -107,7 +107,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(); + 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 ee06bbb7ab3..96e5e088182 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(Config::default()); + let peripherals = esp_hal::init(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 25e28169a54..2830ae585d4 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(Config::default()); + let peripherals = esp_hal::init(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 4740af9a861..388fec5aa0a 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(Config::default()); + let peripherals = esp_hal::init(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 0e1734b4e0f..ac20e825c55 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(Config::default()); + let peripherals = esp_hal::init(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 3d14451b9ea..1b34c08ac06 100644 --- a/examples/src/bin/embassy_usb_serial_jtag.rs +++ b/examples/src/bin/embassy_usb_serial_jtag.rs @@ -62,10 +62,10 @@ async fn reader( #[esp_hal_embassy::main] async fn main(spawner: Spawner) -> () { esp_println::println!("Init!"); - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(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 f8667a38392..320b1579410 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(Config::default()); + let peripherals = esp_hal::init(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); #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] diff --git a/examples/src/bin/etm_timer.rs b/examples/src/bin/etm_timer.rs index 07b3ef571f9..6f4db040620 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(Config::default()); + let peripherals = esp_hal::init(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 358bd3935b7..1e4c4dba374 100644 --- a/examples/src/bin/gpio_interrupt.rs +++ b/examples/src/bin/gpio_interrupt.rs @@ -29,7 +29,7 @@ static BUTTON: Mutex>>> = Mutex::new(RefCell:: #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); // Set GPIO2 as an output, and set its state high initially. let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -49,7 +49,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 8b61d91c483..39facb97523 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(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -58,16 +58,16 @@ fn main() -> ! { // Configure RMT peripheral globally #[cfg(not(feature = "esp32h2"))] - let rmt = Rmt::new(peripherals.RMT, 80.MHz(), &clocks).unwrap(); + let rmt = Rmt::new(peripherals.RMT, 80.MHz()).unwrap(); #[cfg(feature = "esp32h2")] - let rmt = Rmt::new(peripherals.RMT, 32.MHz(), &clocks).unwrap(); + let rmt = Rmt::new(peripherals.RMT, 32.MHz()).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 bbbe7f1cf83..a7d5f18809c 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(Config::default()); + let peripherals = esp_hal::init(Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -45,7 +45,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/i2c_bmp180_calibration_data.rs b/examples/src/bin/i2c_bmp180_calibration_data.rs index cd6fd36ee15..f8e1a2c7afc 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(Config::default()); + let peripherals = esp_hal::init(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 48caa04f6fc..c2c2893ef4c 100644 --- a/examples/src/bin/i2c_display.rs +++ b/examples/src/bin/i2c_display.rs @@ -28,20 +28,14 @@ use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(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 e4b926f2191..83fd6cb0795 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(Config::default()); + let peripherals = esp_hal::init(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 4fe2b5894c0..fb14b13e896 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(Config::default()); + let peripherals = esp_hal::init(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_send_broadcast_frame.rs b/examples/src/bin/ieee802154_send_broadcast_frame.rs index 9b04f678391..d6d70a8f879 100644 --- a/examples/src/bin/ieee802154_send_broadcast_frame.rs +++ b/examples/src/bin/ieee802154_send_broadcast_frame.rs @@ -21,7 +21,7 @@ use ieee802154::mac::{ fn main() -> ! { let (mut peripherals, clocks) = esp_hal::init(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 15297085d15..e785a334215 100644 --- a/examples/src/bin/ieee802154_send_frame.rs +++ b/examples/src/bin/ieee802154_send_frame.rs @@ -21,7 +21,7 @@ use ieee802154::mac::{ fn main() -> ! { let (mut peripherals, clocks) = esp_hal::init(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 ae1102fdcac..0458a60c9a8 100644 --- a/examples/src/bin/ieee802154_sniffer.rs +++ b/examples/src/bin/ieee802154_sniffer.rs @@ -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 1ff4d9486b0..17956dceead 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(Config::default()); + let peripherals = esp_hal::init(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 19262cc3586..0c503fe21c9 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(Config::default()); + let peripherals = esp_hal::init(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 4b1a2d43702..b009488376f 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(Config::default()); + let peripherals = esp_hal::init(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_uart.rs b/examples/src/bin/lp_core_uart.rs index 4a8431e2447..ba5bebc5cee 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(Config::default()); + let peripherals = esp_hal::init(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 4cff42a9d6f..ac9371701b7 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(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let pin = io.pins.gpio0; @@ -26,9 +26,9 @@ fn main() -> ! { // initialize peripheral cfg_if::cfg_if! { if #[cfg(feature = "esp32h2")] { - let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40.MHz()).unwrap(); + let clock_cfg = PeripheralClockConfig::with_frequency(40.MHz()).unwrap(); } else { - let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32.MHz()).unwrap(); + let clock_cfg = PeripheralClockConfig::with_frequency(32.MHz()).unwrap(); } } diff --git a/examples/src/bin/multicore.rs b/examples/src/bin/multicore.rs index aeb57e05075..dd02fa92d9b 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(Config::default()); + let peripherals = esp_hal::init(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 ea3f163bcd2..2a9459b4b44 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(Config::default()); + let peripherals = esp_hal::init(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 8f0bc12bbdc..b29e9a358ca 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(Config::default()); + let peripherals = esp_hal::init(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/qspi_flash.rs b/examples/src/bin/qspi_flash.rs index 169d7853dc0..8575bba8baf 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(Config::default()); + let peripherals = esp_hal::init(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 91af1b6f168..60b24b9b76d 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(Config::default()); + let peripherals = esp_hal::init(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 3592a39564c..dbf281f004a 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(Config::default()); + let peripherals = esp_hal::init(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 d7df0f7d7a5..06ad4b70cfa 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(Config::default()); + let peripherals = esp_hal::init(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/rtc_time.rs b/examples/src/bin/rtc_time.rs index 662531c9a0b..74a9e75cba0 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(Config::default()); + let peripherals = esp_hal::init(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/serial_interrupts.rs b/examples/src/bin/serial_interrupts.rs index d4138d0a9f4..2f83257576d 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(Config::default()); + let peripherals = esp_hal::init(Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -54,8 +54,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 9296fd7df52..bbe99774c46 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(Config::default()); + let peripherals = esp_hal::init(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 bd6576fc83d..92b52ac31a9 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(Config::default()); + let peripherals = esp_hal::init(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 7aacd563372..f081c7709b3 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(Config::default()); + let peripherals = esp_hal::init(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 cba6153aaa7..eee77fc0dc4 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(Config::default()); + let peripherals = esp_hal::init(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 cb1eb26bd05..19505444df9 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(Config::default()); + let peripherals = esp_hal::init(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 44c655ec9db..45ab95923a1 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(Config::default()); + let peripherals = esp_hal::init(Config::default()); let mut sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); @@ -60,7 +60,7 @@ fn main() -> ! { .replace(sw_int.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 3eba959f865..c031cd703e0 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(Config::default()); + let peripherals = esp_hal::init(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 9d09c957f81..aba39b2c232 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(Config::default()); + let peripherals = esp_hal::init(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 3737936cd96..5bedf51fe2e 100644 --- a/examples/src/bin/spi_loopback_dma.rs +++ b/examples/src/bin/spi_loopback_dma.rs @@ -34,7 +34,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; @@ -56,11 +56,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 da583f91cd4..a154d60505d 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(Config::default()); + let peripherals = esp_hal::init(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 508ea7e98e6..1cc99ac45b2 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(Config::default()); + let peripherals = esp_hal::init(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 1126ba58a4e..b5c473a8154 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(Config::default()); + let peripherals = esp_hal::init(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 88c15097ded..ca6190c6fec 100644 --- a/examples/src/bin/touch.rs +++ b/examples/src/bin/touch.rs @@ -48,7 +48,7 @@ fn interrupt_handler() { #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -67,7 +67,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 380cbf63192..2d09ac86d10 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(Config::default()); + let peripherals = esp_hal::init(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/usb_serial_jtag.rs b/examples/src/bin/usb_serial_jtag.rs index 2b81ba5492c..acfda527fe4 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(Config::default()); + let peripherals = esp_hal::init(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 78cd2c252c6..2ab494a50f0 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(Config::default()); + let peripherals = esp_hal::init(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 b129f288641..69a7504fbd2 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 = 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 b79f2dcf54b..a6c26d972cd 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 = 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 69005fd16eb..814e43ca9ba 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 = 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 b2ebbad932b..86ddc24784c 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 = 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 13558d6697b..a11d240f3bc 100644 --- a/examples/src/bin/wifi_ble.rs +++ b/examples/src/bin/wifi_ble.rs @@ -36,20 +36,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 = 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 a62eec72c79..47484418cc5 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 = 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 1819d551048..e8fbe962852 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 = 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 1208244f0bf..3eeb8f2d616 100644 --- a/examples/src/bin/wifi_embassy_access_point.rs +++ b/examples/src/bin/wifi_embassy_access_point.rs @@ -56,20 +56,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 = 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(); @@ -79,12 +78,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 733a035093f..bed7dc3b485 100644 --- a/examples/src/bin/wifi_embassy_access_point_with_sta.rs +++ b/examples/src/bin/wifi_embassy_access_point_with_sta.rs @@ -70,20 +70,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 = 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(); @@ -93,12 +92,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 2db24497831..f4d35b1b090 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 = 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 559cf1ed490..85a0a6771bd 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 = 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 789ac88964a..6112a70994d 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 = 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 cf23adf050b..46d7be04e31 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 = 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 027fc3d5db7..d5081b6c63d 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 = 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 ae3f8b8c12a..d758054193c 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 = 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 f9d81b19e21..35ee46d1fb4 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 = 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 917043e915d..5803652dbcd 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 = 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_dma.rs b/hil-test/tests/aes_dma.rs index 436c853b374..1162213c5b6 100644 --- a/hil-test/tests/aes_dma.rs +++ b/hil-test/tests/aes_dma.rs @@ -29,7 +29,7 @@ mod tests { #[init] fn init() -> Peripherals { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); peripherals } diff --git a/hil-test/tests/clock_monitor.rs b/hil-test/tests/clock_monitor.rs index f1ecc9de08f..03d2d22abfa 100644 --- a/hil-test/tests/clock_monitor.rs +++ b/hil-test/tests/clock_monitor.rs @@ -14,7 +14,7 @@ struct Context<'a> { impl Context<'_> { pub fn init() -> Self { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(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 2ce0448d98e..0418b9a45f9 100644 --- a/hil-test/tests/delay.rs +++ b/hil-test/tests/delay.rs @@ -15,8 +15,8 @@ struct Context { impl Context { pub fn init() -> Self { - let (peripherals, clocks) = esp_hal::init(Config::default()); - let delay = Delay::new(&clocks); + let peripherals = esp_hal::init(Config::default()); + let delay = Delay::new(); Context { delay } } diff --git a/hil-test/tests/dma_mem2mem.rs b/hil-test/tests/dma_mem2mem.rs index 22d41234f73..1602963d467 100644 --- a/hil-test/tests/dma_mem2mem.rs +++ b/hil-test/tests/dma_mem2mem.rs @@ -39,7 +39,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let dma = Dma::new(peripherals.DMA); let channel = dma.channel0.configure(false, DmaPriority::Priority0); diff --git a/hil-test/tests/embassy_interrupt_executor.rs b/hil-test/tests/embassy_interrupt_executor.rs index 32a53a07705..dce491e59c0 100644 --- a/hil-test/tests/embassy_interrupt_executor.rs +++ b/hil-test/tests/embassy_interrupt_executor.rs @@ -46,14 +46,14 @@ mod test { #[init] fn init() -> SoftwareInterrupt<1> { - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = Config::default(); config.cpu_clock = CpuClock::max(); config }); - 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_timers_executors.rs b/hil-test/tests/embassy_timers_executors.rs index 589a52a174e..80c18a3b57d 100644 --- a/hil-test/tests/embassy_timers_executors.rs +++ b/hil-test/tests/embassy_timers_executors.rs @@ -110,14 +110,14 @@ 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); + 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>) { let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); } #[cfg(test)] @@ -151,7 +151,7 @@ mod test { #[test] #[timeout(3)] fn test_periodic_timg((peripherals, clocks): (Peripherals, Clocks<'static>)) { - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); run_test_periodic_timer(timg0.timer0); } @@ -212,7 +212,7 @@ mod test { #[timeout(3)] #[cfg(not(feature = "esp32"))] async fn test_interrupt_executor((peripherals, clocks): (Peripherals, Clocks<'static>)) { - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timg0 = TimerGroup::new(peripherals.TIMG0); let timer0: ErasedTimer = timg0.timer0.into(); let timer0 = OneShotTimer::new(timer0); @@ -221,7 +221,7 @@ mod test { let timer1 = OneShotTimer::new(alarm0); let timers = mk_static!([OneShotTimer; 2], [timer0, timer1]); - esp_hal_embassy::init(&clocks, timers); + esp_hal_embassy::init(timers); let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); diff --git a/hil-test/tests/get_time.rs b/hil-test/tests/get_time.rs index ed71ea17c0a..f25ca375ff5 100644 --- a/hil-test/tests/get_time.rs +++ b/hil-test/tests/get_time.rs @@ -33,7 +33,7 @@ mod tests { fn init() -> Context { let (_peripherals, clocks) = esp_hal::init(Config::default()); - let delay = Delay::new(&clocks); + let delay = Delay::new(); Context { delay, diff --git a/hil-test/tests/gpio.rs b/hil-test/tests/gpio.rs index f9ae0616c95..8bd1d0c1919 100644 --- a/hil-test/tests/gpio.rs +++ b/hil-test/tests/gpio.rs @@ -34,15 +34,15 @@ struct Context<'d> { impl<'d> Context<'d> { pub fn init() -> Self { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(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 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); Context { io2: Input::new(io.pins.gpio2, Pull::Down), diff --git a/hil-test/tests/i2s.rs b/hil-test/tests/i2s.rs index 97a74e80e05..d4ff786ca3a 100644 --- a/hil-test/tests/i2s.rs +++ b/hil-test/tests/i2s.rs @@ -53,14 +53,14 @@ mod tests { #[test] fn test_i2s_loopback() { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let peripherals = peripherals; let clocks = clocks; 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; @@ -75,7 +75,6 @@ mod tests { dma_channel.configure(false, DmaPriority::Priority0), tx_descriptors, rx_descriptors, - &clocks, ); let mut i2s_tx = i2s diff --git a/hil-test/tests/i2s_async.rs b/hil-test/tests/i2s_async.rs index 811214252a9..e2040b2c4b9 100644 --- a/hil-test/tests/i2s_async.rs +++ b/hil-test/tests/i2s_async.rs @@ -80,7 +80,7 @@ mod tests { async fn test_i2s_loopback() { let spawner = embassy_executor::Spawner::for_current_executor().await; - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let peripherals = peripherals; let clocks = clocks; @@ -101,7 +101,6 @@ mod tests { dma_channel.configure_for_async(false, DmaPriority::Priority0), tx_descriptors, rx_descriptors, - &clocks, ); let i2s_tx = i2s diff --git a/hil-test/tests/lcd_cam_i8080.rs b/hil-test/tests/lcd_cam_i8080.rs index bd320f61f7d..e0f1516781a 100644 --- a/hil-test/tests/lcd_cam_i8080.rs +++ b/hil-test/tests/lcd_cam_i8080.rs @@ -35,7 +35,7 @@ mod tests { #[init] fn init() -> Context<'static> { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(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); diff --git a/hil-test/tests/lcd_cam_i8080_async.rs b/hil-test/tests/lcd_cam_i8080_async.rs index 50e886dfd25..e1af08e47fe 100644 --- a/hil-test/tests/lcd_cam_i8080_async.rs +++ b/hil-test/tests/lcd_cam_i8080_async.rs @@ -39,7 +39,7 @@ mod tests { #[init] async fn init() -> Context<'static> { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let dma = Dma::new(peripherals.DMA); let lcd_cam = LcdCam::new_async(peripherals.LCD_CAM); diff --git a/hil-test/tests/pcnt.rs b/hil-test/tests/pcnt.rs index 8c07f5ca3d4..d7c8324462f 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(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -40,7 +40,7 @@ mod tests { pcnt: Pcnt::new(peripherals.PCNT), gpio2: io.pins.gpio2, gpio3: io.pins.gpio3, - delay: Delay::new(&clocks), + delay: Delay::new(), } } diff --git a/hil-test/tests/rmt.rs b/hil-test/tests/rmt.rs index 5948a253214..59ae9a02642 100644 --- a/hil-test/tests/rmt.rs +++ b/hil-test/tests/rmt.rs @@ -25,7 +25,7 @@ mod tests { #[test] #[timeout(1)] fn rmt_loopback() { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/hil-test/tests/spi_full_duplex.rs b/hil-test/tests/spi_full_duplex.rs index fa14ea2b926..2bffc0e6cd2 100644 --- a/hil-test/tests/spi_full_duplex.rs +++ b/hil-test/tests/spi_full_duplex.rs @@ -34,7 +34,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; diff --git a/hil-test/tests/spi_half_duplex_read.rs b/hil-test/tests/spi_half_duplex_read.rs index ade2837e886..0017c1b25cd 100644 --- a/hil-test/tests/spi_half_duplex_read.rs +++ b/hil-test/tests/spi_half_duplex_read.rs @@ -38,7 +38,7 @@ mod tests { fn test_spi_reads_correctly_from_gpio_pin() { const DMA_BUFFER_SIZE: usize = 4; - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; diff --git a/hil-test/tests/spi_half_duplex_write.rs b/hil-test/tests/spi_half_duplex_write.rs index bf1fd5e6596..8270f9cbfaa 100644 --- a/hil-test/tests/spi_half_duplex_write.rs +++ b/hil-test/tests/spi_half_duplex_write.rs @@ -39,7 +39,7 @@ mod tests { fn test_spi_writes_are_correctly_by_pcnt() { const DMA_BUFFER_SIZE: usize = 4; - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let pcnt = Pcnt::new(peripherals.PCNT); diff --git a/hil-test/tests/systimer.rs b/hil-test/tests/systimer.rs index 6dd3b95d1c0..c3ed71abba2 100644 --- a/hil-test/tests/systimer.rs +++ b/hil-test/tests/systimer.rs @@ -104,7 +104,7 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let systimer = SystemTimer::new(peripherals.SYSTIMER); static UNIT0: StaticCell> = StaticCell::new(); diff --git a/hil-test/tests/twai.rs b/hil-test/tests/twai.rs index 79b1aa9ac11..b262562e8b0 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(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -46,7 +46,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 ce54367bda8..62034ec571f 100644 --- a/hil-test/tests/uart.rs +++ b/hil-test/tests/uart.rs @@ -37,11 +37,11 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let uart = Uart::new(peripherals.UART1, &clocks, io.pins.gpio2, io.pins.gpio3).unwrap(); + let uart = Uart::new(peripherals.UART1, io.pins.gpio2, io.pins.gpio3).unwrap(); Context { clocks, uart } } diff --git a/hil-test/tests/uart_async.rs b/hil-test/tests/uart_async.rs index e7fd7f12073..00f9d9cbe44 100644 --- a/hil-test/tests/uart_async.rs +++ b/hil-test/tests/uart_async.rs @@ -28,12 +28,12 @@ mod tests { #[init] async fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let uart = - Uart::new_async(peripherals.UART0, &clocks, io.pins.gpio2, io.pins.gpio3).unwrap(); + Uart::new_async(peripherals.UART0, io.pins.gpio2, io.pins.gpio3).unwrap(); Context { uart } } diff --git a/hil-test/tests/uart_tx_rx.rs b/hil-test/tests/uart_tx_rx.rs index ff0c599d173..64d3119a4c3 100644 --- a/hil-test/tests/uart_tx_rx.rs +++ b/hil-test/tests/uart_tx_rx.rs @@ -35,12 +35,12 @@ mod tests { #[init] fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let tx = UartTx::new(peripherals.UART0, &clocks, io.pins.gpio2).unwrap(); - let rx = UartRx::new(peripherals.UART1, &clocks, io.pins.gpio3).unwrap(); + let tx = UartTx::new(peripherals.UART0, io.pins.gpio2).unwrap(); + let rx = UartRx::new(peripherals.UART1, io.pins.gpio3).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 c92fa8090ef..60a37c53582 100644 --- a/hil-test/tests/uart_tx_rx_async.rs +++ b/hil-test/tests/uart_tx_rx_async.rs @@ -35,12 +35,12 @@ mod tests { #[init] async fn init() -> Context { - let (peripherals, clocks) = esp_hal::init(Config::default()); + let peripherals = esp_hal::init(Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let tx = UartTx::new_async(peripherals.UART0, &clocks, io.pins.gpio2).unwrap(); - let rx = UartRx::new_async(peripherals.UART1, &clocks, io.pins.gpio3).unwrap(); + let tx = UartTx::new_async(peripherals.UART0, io.pins.gpio2).unwrap(); + let rx = UartRx::new_async(peripherals.UART1, io.pins.gpio3).unwrap(); Context { tx, rx } } diff --git a/hil-test/tests/usb_serial_jtag.rs b/hil-test/tests/usb_serial_jtag.rs index 854e65e4cb0..93b94ad8790 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(Config::default()); + let peripherals = esp_hal::init(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(); }