diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 601f5094dcc..8ddc5827c73 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -7,6 +7,7 @@ To help us review it efficiently, please ensure you've gone through the followin - [ ] I have updated existing examples or added new ones (if applicable). - [ ] I have used `cargo xtask fmt-packages` command to ensure that all changed code is formatted correctly. - [ ] My changes were added to the [`CHANGELOG.md`](https://github.com/esp-rs/esp-hal/blob/main/esp-hal/CHANGELOG.md) in the **_proper_** section. +- [ ] I have added necessary changes to user code to the [Migration Guide](https://github.com/esp-rs/esp-hal/blob/main/esp-hal/MIGRATING-0.21.md). - [ ] My changes are in accordance to the [esp-rs API guidelines](https://github.com/esp-rs/esp-hal/blob/main/documentation/API-GUIDELINES.md) #### Extra: diff --git a/documentation/CONTRIBUTING.md b/documentation/CONTRIBUTING.md index e0abb806e07..0ce91dd0dcf 100644 --- a/documentation/CONTRIBUTING.md +++ b/documentation/CONTRIBUTING.md @@ -84,11 +84,11 @@ By taking these extra steps to test your contributions, you help maintain the hi Ensuring the quality and reliability of `esp-hal` is a shared responsibility, and testing plays a critical role in this process. Our GitHub CI automatically checks the buildability of all examples and drivers within the project. However, automated tests can't catch everything, especially when it comes to the nuanced behavior of hardware interactions. So make sure that the example affected by your change works as expected. -Further steps that can (or should) be taken in testing: +Further steps that can (or should) be taken in testing: -* Using [xtask], build examples for the specified chip. +* Using [xtask], build examples for the specified chip. * Build the documentation and run the doctests if they have been modified using the `build-documentation` and `run-doc-test` commands in [xtask]. -* Run the [HIL] tests locally if changes have been made to them. +* Run the [HIL] tests locally if changes have been made to them. [xtask]: https://github.com/esp-rs/esp-hal/tree/main/xtask @@ -122,6 +122,7 @@ This will use `rustfmt` to ensure that all source code is formatted correctly pr * [Link your PR] to any relevant issues it addresses. * [Allow edits from maintainers] so the branch can be updated for a merge. Once you submit your PR, a Docs team member will review your proposal. We may ask questions or request additional information. * Make sure you add an entry with your changes to the [Changelog]. Also make sure that it is in the appropriate section of the document. +* Make sure you add your changes to the current [migration guide]. * We may ask for changes to be made before a PR can be merged, either using [suggested changes] or pull request comments. You can apply suggested changes directly through the UI. You can make any other changes in your fork, then commit them to your branch. * As you update your PR and apply changes, mark each conversation as [resolved]. * Resolve merge conflicts if they arise, using resources like [this git tutorial] for help. @@ -129,6 +130,7 @@ This will use `rustfmt` to ensure that all source code is formatted correctly pr [Link your PR]: https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue [Allow edits from maintainers]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-forkmember [Changelog]: esp-hal/CHANGELOG.md +[migration guide]: esp-hal/MIGRATING-0.20.md [suggested changes]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/incorporating-feedback-in-your-pull-request [resolved]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request#resolving-conversations [this git tutorial]: https://github.com/skills/resolve-merge-conflicts diff --git a/esp-hal-embassy/src/executor/interrupt.rs b/esp-hal-embassy/src/executor/interrupt.rs index 89369a81c8a..8dcc343e9fd 100644 --- a/esp-hal-embassy/src/executor/interrupt.rs +++ b/esp-hal-embassy/src/executor/interrupt.rs @@ -5,8 +5,7 @@ use core::{cell::UnsafeCell, mem::MaybeUninit}; use embassy_executor::{raw, SendSpawner}; use esp_hal::{ get_core, - interrupt::{self, InterruptHandler}, - system::SoftwareInterrupt, + interrupt::{self, software::SoftwareInterrupt, InterruptHandler}, }; use portable_atomic::{AtomicUsize, Ordering}; diff --git a/esp-hal-embassy/src/executor/mod.rs b/esp-hal-embassy/src/executor/mod.rs index f82bf3f6c43..51e43f34e79 100644 --- a/esp-hal-embassy/src/executor/mod.rs +++ b/esp-hal-embassy/src/executor/mod.rs @@ -5,7 +5,7 @@ mod thread; #[export_name = "__pender"] fn __pender(context: *mut ()) { - use esp_hal::system::SoftwareInterrupt; + use esp_hal::interrupt::software::SoftwareInterrupt; let context = (context as usize).to_le_bytes(); diff --git a/esp-hal-embassy/src/executor/thread.rs b/esp-hal-embassy/src/executor/thread.rs index e21c837001c..5050a3793c1 100644 --- a/esp-hal-embassy/src/executor/thread.rs +++ b/esp-hal-embassy/src/executor/thread.rs @@ -77,7 +77,7 @@ This will use software-interrupt 3 which isn't available for anything else to wa pub fn new() -> Self { #[cfg(multi_core)] unsafe { - esp_hal::system::SoftwareInterrupt::<3>::steal() + esp_hal::interrupt::software::SoftwareInterrupt::<3>::steal() .set_interrupt_handler(software3_interrupt) } diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index ba3d30599b8..32441a10703 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added `esp_hal::init` to simplify HAL initialisation (#1970) + ### Changed ### Fixed diff --git a/esp-hal/MIGRATING-0.20.md b/esp-hal/MIGRATING-0.20.md new file mode 100644 index 00000000000..0714b5a81e6 --- /dev/null +++ b/esp-hal/MIGRATING-0.20.md @@ -0,0 +1,26 @@ +Migration Guide from 0.20.x to vNext +==================================== + +HAL initialsation +----------------- + +Instead of manually grabbing peripherals and setting up clocks, you should now call `esp_hal::init`. + +```diff + use esp_hal::{ +- clock::ClockControl, +- peripherals::Peripherals, + prelude::*, +- system::SystemControl, + }; + + #[entry] + fn main() -> ! { +- let peripherals = Peripherals::take(); +- let system = SystemControl::new(peripherals.SYSTEM); +- let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); ++ let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + + // ... + } +``` diff --git a/esp-hal/src/aes/mod.rs b/esp-hal/src/aes/mod.rs index 2d3e7afbd48..f6f01bfef65 100644 --- a/esp-hal/src/aes/mod.rs +++ b/esp-hal/src/aes/mod.rs @@ -28,26 +28,30 @@ //! # let plaintext = b"message"; //! # let mut keybuf = [0_u8; 16]; //! # keybuf[..keytext.len()].copy_from_slice(keytext); -//! let mut block_buf = [0_u8; 16]; -//! block_buf[..plaintext.len()].copy_from_slice(plaintext); -//! let mut block = block_buf.clone(); +//! # +//! let mut block = [0_u8; 16]; +//! block[..plaintext.len()].copy_from_slice(plaintext); //! //! let mut aes = Aes::new(peripherals.AES); //! aes.process(&mut block, Mode::Encryption128, keybuf); -//! let hw_encrypted = block.clone(); +//! +//! // The encryption happens in-place, so the ciphertext is in `block` //! //! aes.process(&mut block, Mode::Decryption128, keybuf); -//! let hw_decrypted = block; +//! +//! // The decryption happens in-place, so the plaintext is in `block` //! # } //! ``` //! //! ### AES-DMA +//! //! Visit the [AES-DMA] test for a more advanced example of using AES-DMA //! mode. //! //! [AES-DMA]: https://github.com/esp-rs/esp-hal/blob/main/hil-test/tests/aes_dma.rs //! //! ## Implementation State +//! //! * AES-DMA mode is currently not supported on ESP32 and ESP32S2 //! * AES-DMA Initialization Vector (IV) is currently not supported diff --git a/esp-hal/src/analog/adc/mod.rs b/esp-hal/src/analog/adc/mod.rs index a39c337ffb7..7a1aa62413f 100644 --- a/esp-hal/src/analog/adc/mod.rs +++ b/esp-hal/src/analog/adc/mod.rs @@ -32,7 +32,6 @@ //! # use esp_hal::analog::adc::Adc; //! # use esp_hal::delay::Delay; //! # use esp_hal::gpio::Io; -//! //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); #![cfg_attr(esp32, doc = "let analog_pin = io.pins.gpio32;")] #![cfg_attr(any(esp32s2, esp32s3), doc = "let analog_pin = io.pins.gpio3;")] @@ -41,8 +40,10 @@ doc = "let analog_pin = io.pins.gpio2;" )] //! let mut adc1_config = AdcConfig::new(); -//! let mut pin = adc1_config.enable_pin(analog_pin, -//! Attenuation::Attenuation11dB); +//! let mut pin = adc1_config.enable_pin( +//! analog_pin, +//! Attenuation::Attenuation11dB, +//! ); //! let mut adc1 = Adc::new(peripherals.ADC1, adc1_config); //! //! let mut delay = Delay::new(&clocks); @@ -54,8 +55,10 @@ //! } //! # } //! ``` +//! //! ## Implementation State -//! - [ADC calibration is not implemented for all targets]. +//! +//! - [ADC calibration is not implemented for all targets]. //! //! [ADC calibration is not implemented for all targets]: https://github.com/esp-rs/esp-hal/issues/326 use core::marker::PhantomData; diff --git a/esp-hal/src/clock/mod.rs b/esp-hal/src/clock/mod.rs index 48a00279354..59cb01cf6a1 100644 --- a/esp-hal/src/clock/mod.rs +++ b/esp-hal/src/clock/mod.rs @@ -13,20 +13,14 @@ //! module clocks. //! //! ## Configuration -//! Proper clock configuration is essential for the correct functioning of the -//! microcontroller and its peripherals. //! -//! The `Clock` driver supports configuring multiple clocks, including: -//! * CPU clock -//! * APB (Advanced Peripheral Bus) clock -//! * XTAL (External Crystal) clock -//! * PLL (Phase Lock Loop) clock -//! -//! and other specific clocks based on the ESP microcontroller's architecture. +//! During HAL initialization, specify a CPU clock speed to configure the +//! desired clock frequencies. //! //! The `CPU clock` is responsible for defining the speed at which the central //! processing unit (CPU) operates. This driver provides predefined options for -//! different CPU clock speeds, such +//! different CPU clock speeds, such as +//! //! * 80 MHz //! * 96 MHz //! * 120 MHz @@ -35,52 +29,56 @@ //! //! and others, depending on the microcontroller model. //! -//! ### Clock Control -//! The `ClockControl` struct allows users to configure the desired clock -//! frequencies before applying them. It offers flexibility in selecting -//! appropriate clock frequencies based on specific application requirements. -//! //! ### Frozen Clock Frequencies -//! Once the clock configuration is applied using the `freeze` function of the -//! ClockControl struct, the clock frequencies become `frozen` and cannot be -//! changed. The `Clocks` struct is returned after freezing, providing read-only -//! access to the configured clock frequencies. +//! +//! Once the clock configuration is applied, the clock frequencies become +//! `frozen` and cannot be changed. The `Clocks` struct is returned as part of +//! the `System` struct, providing read-only access to the configured clock +//! frequencies. //! //! ## Examples +//! //! ### Initialize With Different Clock Frequencies //! ```rust, no_run //! # #![no_std] -//! # use esp_hal::peripherals::Peripherals; -//! # use esp_hal::clock::ClockControl; -//! # use esp_hal::system::SystemControl; +//! # use esp_hal::prelude::*; //! # #[panic_handler] //! # fn panic(_ : &core::panic::PanicInfo) -> ! { //! # loop {} //! # } //! # fn main() { -//! # let peripherals = Peripherals::take(); -//! # let system = SystemControl::new(peripherals.SYSTEM); //! // Initialize with the highest possible frequency for this chip -//! let clocks = ClockControl::max(system.clock_control).freeze(); +//! let (peripherals, clocks) = esp_hal::init({ +//! let mut config = esp_hal::Config::default(); +//! config.cpu_clock = CpuClock::max(); +//! config +//! }); //! //! // Initialize with custom clock frequency -//! // let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock160MHz).freeze(); +//! // let (peripherals, clocks) = esp_hal::init({ +//! // let mut config = esp_hal::Config::default(); +#![cfg_attr( + not(any(esp32c2, esp32h2)), + doc = "// config.cpu_clock = CpuClock::Clock160MHz;" +)] +#![cfg_attr(esp32c2, doc = "// config.cpu_clock = CpuClock::Clock120MHz;")] +#![cfg_attr(esp32h2, doc = "// config.cpu_clock = CpuClock::Clock96MHz;")] +//! // config +//! // }); //! // //! // Initialize with default clock frequency for this chip -//! // let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); +//! // let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); //! # } //! ``` +use core::marker::PhantomData; + use fugit::HertzU32; #[cfg(esp32c2)] use portable_atomic::{AtomicU32, Ordering}; #[cfg(any(esp32, esp32c2))] use crate::rtc_cntl::RtcClock; -use crate::{ - peripheral::{Peripheral, PeripheralRef}, - system::SystemClockControl, -}; #[cfg_attr(esp32, path = "clocks_ll/esp32.rs")] #[cfg_attr(esp32c2, path = "clocks_ll/esp32c2.rs")] @@ -108,40 +106,63 @@ pub trait Clock { } /// CPU clock speed -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum CpuClock { /// 80MHz CPU clock #[cfg(not(esp32h2))] - Clock80MHz, + Clock80MHz = 80, + /// 96MHz CPU clock #[cfg(esp32h2)] - Clock96MHz, + Clock96MHz = 96, + /// 120MHz CPU clock #[cfg(esp32c2)] - Clock120MHz, + Clock120MHz = 120, + /// 160MHz CPU clock #[cfg(not(any(esp32c2, esp32h2)))] - Clock160MHz, + Clock160MHz = 160, + /// 240MHz CPU clock #[cfg(xtensa)] - Clock240MHz, + Clock240MHz = 240, +} + +impl Default for CpuClock { + fn default() -> Self { + cfg_if::cfg_if! { + if #[cfg(esp32h2)] { + Self::Clock96MHz + } else { + // FIXME: I don't think this is correct in general? + Self::Clock80MHz + } + } + } +} + +impl CpuClock { + /// Use the highest possible frequency for a particular chip. + pub const fn max() -> Self { + cfg_if::cfg_if! { + if #[cfg(esp32c2)] { + Self::Clock120MHz + } else if #[cfg(any(esp32c3, esp32c6))] { + Self::Clock160MHz + } else if #[cfg(esp32h2)] { + Self::Clock96MHz + } else { + Self::Clock240MHz + } + } + } } -#[allow(dead_code)] impl Clock for CpuClock { fn frequency(&self) -> HertzU32 { - match self { - #[cfg(not(esp32h2))] - CpuClock::Clock80MHz => HertzU32::MHz(80), - #[cfg(esp32h2)] - CpuClock::Clock96MHz => HertzU32::MHz(96), - #[cfg(esp32c2)] - CpuClock::Clock120MHz => HertzU32::MHz(120), - #[cfg(not(any(esp32c2, esp32h2)))] - CpuClock::Clock160MHz => HertzU32::MHz(160), - #[cfg(xtensa)] - CpuClock::Clock240MHz => HertzU32::MHz(240), - } + HertzU32::MHz(*self as u32) } } @@ -257,81 +278,65 @@ 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<'d> { - _private: PeripheralRef<'d, SystemClockControl>, - /// CPU clock frequency - pub cpu_clock: HertzU32, - /// APB clock frequency - pub apb_clock: HertzU32, - /// XTAL clock frequency - pub xtal_clock: HertzU32, - /// I2C clock frequency - #[cfg(esp32)] - pub i2c_clock: HertzU32, - /// PWM clock frequency - #[cfg(esp32)] - pub pwm_clock: HertzU32, - /// Crypto PWM clock frequency - #[cfg(esp32s3)] - pub crypto_pwm_clock: HertzU32, - /// Crypto clock frequency - #[cfg(any(esp32c6, esp32h2))] - pub crypto_clock: HertzU32, - /// PLL 48M clock frequency (fixed) - #[cfg(esp32h2)] - pub pll_48m_clock: HertzU32, - /// PLL 96M clock frequency (fixed) - #[cfg(esp32h2)] - pub pll_96m_clock: HertzU32, +/// longer be changed. +pub struct Clocks<'a> { + _private: PhantomData<&'a ()>, + rates: RawClocks, } -#[doc(hidden)] -impl<'d> Clocks<'d> { +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 fn from_raw_clocks( - system_clock_control: PeripheralRef<'d, SystemClockControl>, - raw_clocks: RawClocks, - ) -> Clocks<'d> { + pub(crate) fn from_raw_clocks(raw_clocks: RawClocks) -> Clocks<'a> { Self { - _private: system_clock_control, - cpu_clock: raw_clocks.cpu_clock, - apb_clock: raw_clocks.apb_clock, - xtal_clock: raw_clocks.xtal_clock, - #[cfg(esp32)] - i2c_clock: raw_clocks.i2c_clock, - #[cfg(esp32)] - pwm_clock: raw_clocks.pwm_clock, - #[cfg(esp32s3)] - crypto_pwm_clock: raw_clocks.crypto_pwm_clock, - #[cfg(any(esp32c6, esp32h2))] - crypto_clock: raw_clocks.crypto_clock, - #[cfg(esp32h2)] - pll_48m_clock: raw_clocks.pll_48m_clock, - #[cfg(esp32h2)] - pll_96m_clock: raw_clocks.pll_96m_clock, + _private: PhantomData, + rates: raw_clocks, } } } -#[doc(hidden)] +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 { + /// CPU clock frequency pub cpu_clock: HertzU32, + + /// APB clock frequency pub apb_clock: HertzU32, + + /// XTAL clock frequency pub xtal_clock: HertzU32, + + /// I2C clock frequency #[cfg(esp32)] pub i2c_clock: HertzU32, + + /// PWM clock frequency #[cfg(esp32)] pub pwm_clock: HertzU32, + + /// Crypto PWM clock frequency #[cfg(esp32s3)] pub crypto_pwm_clock: HertzU32, + + /// Crypto clock frequency #[cfg(any(esp32c6, esp32h2))] pub crypto_clock: HertzU32, + + /// PLL 48M clock frequency (fixed) #[cfg(esp32h2)] pub pll_48m_clock: HertzU32, + + /// PLL 96M clock frequency (fixed) #[cfg(esp32h2)] pub pll_96m_clock: HertzU32, } @@ -360,72 +365,51 @@ cfg_if::cfg_if! { /// /// After setting all frequencies, call the freeze function to apply the /// configuration. -pub struct ClockControl<'d> { - _private: PeripheralRef<'d, SystemClockControl>, +pub struct ClockControl { desired_rates: RawClocks, } -impl<'d> ClockControl<'d> { +impl ClockControl { + pub(crate) fn new(clock: CpuClock) -> Self { + Self::configure(clock) + } + /// 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<'d> { - Clocks::from_raw_clocks(self._private, self.desired_rates) + pub fn freeze(self) -> Clocks<'static> { + Clocks::from_raw_clocks(self.desired_rates) } } #[cfg(esp32)] -impl<'d> ClockControl<'d> { - /// Use what is considered the default settings after boot. - pub fn boot_defaults( - clock_control: impl Peripheral

+ 'd, - ) -> ClockControl<'d> { - let xtal_freq = if RtcClock::estimate_xtal_frequency() > 33 { - 40 - } else { - 26 - }; - - ClockControl { - _private: clock_control.into_ref(), - desired_rates: RawClocks { - cpu_clock: HertzU32::MHz(80), - apb_clock: HertzU32::MHz(80), - xtal_clock: HertzU32::MHz(xtal_freq), - i2c_clock: HertzU32::MHz(80), - pwm_clock: HertzU32::MHz(160), - }, - } - } - +impl ClockControl { /// Configure the CPU clock speed. - pub fn configure( - clock_control: impl Peripheral

+ 'd, - cpu_clock_speed: CpuClock, - ) -> ClockControl<'d> { + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { let xtal_freq = if RtcClock::estimate_xtal_frequency() > 33 { XtalClock::RtcXtalFreq40M } else { XtalClock::RtcXtalFreq26M }; - let pll_freq = match cpu_clock_speed { - CpuClock::Clock80MHz => PllClock::Pll320MHz, - CpuClock::Clock160MHz => PllClock::Pll320MHz, - CpuClock::Clock240MHz => PllClock::Pll480MHz, - }; - - clocks_ll::esp32_rtc_update_to_xtal(xtal_freq, 1); - clocks_ll::esp32_rtc_bbpll_enable(); - clocks_ll::esp32_rtc_bbpll_configure(xtal_freq, pll_freq); - clocks_ll::set_cpu_freq(cpu_clock_speed); + if cpu_clock_speed != CpuClock::default() { + let pll_freq = match cpu_clock_speed { + CpuClock::Clock80MHz => PllClock::Pll320MHz, + CpuClock::Clock160MHz => PllClock::Pll320MHz, + CpuClock::Clock240MHz => PllClock::Pll480MHz, + }; + + clocks_ll::esp32_rtc_update_to_xtal(xtal_freq, 1); + clocks_ll::esp32_rtc_bbpll_enable(); + clocks_ll::esp32_rtc_bbpll_configure(xtal_freq, pll_freq); + clocks_ll::set_cpu_freq(cpu_clock_speed); + } ClockControl { - _private: clock_control.into_ref(), desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(), apb_clock: HertzU32::MHz(80), - xtal_clock: HertzU32::MHz(40), + 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. @@ -434,43 +418,12 @@ impl<'d> ClockControl<'d> { }, } } - - /// Use the highest possible frequency for a particular chip - pub fn max(clock_control: impl Peripheral

+ 'd) -> ClockControl<'d> { - Self::configure(clock_control, CpuClock::Clock240MHz) - } } #[cfg(esp32c2)] -impl<'d> ClockControl<'d> { - /// Use what is considered the default settings after boot. - pub fn boot_defaults( - clock_control: impl Peripheral

+ 'd, - ) -> ClockControl<'d> { - let xtal_freq = if RtcClock::estimate_xtal_frequency() > 33 { - 40 - } else { - 26 - }; - XTAL_FREQ_MHZ.store(xtal_freq, Ordering::Relaxed); - - ClockControl { - _private: clock_control.into_ref(), - desired_rates: RawClocks { - cpu_clock: HertzU32::MHz(80), - apb_clock: HertzU32::MHz(40), - xtal_clock: HertzU32::MHz(xtal_freq), - }, - } - } - +impl ClockControl { /// Configure the CPU clock speed. - pub fn configure( - clock_control: impl Peripheral

+ 'd, - cpu_clock_speed: CpuClock, - ) -> ClockControl<'d> { - let apb_freq; - + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { let xtal_freq = if RtcClock::estimate_xtal_frequency() > 33 { XtalClock::RtcXtalFreq40M } else { @@ -478,22 +431,26 @@ impl<'d> ClockControl<'d> { }; XTAL_FREQ_MHZ.store(xtal_freq.mhz(), Ordering::Relaxed); - let pll_freq = PllClock::Pll480MHz; - - if cpu_clock_speed.mhz() <= xtal_freq.mhz() { - apb_freq = ApbClock::ApbFreqOther(cpu_clock_speed.mhz()); - clocks_ll::esp32c2_rtc_update_to_xtal(xtal_freq, 1); - clocks_ll::esp32c2_rtc_apb_freq_update(apb_freq); + let apb_freq; + if cpu_clock_speed != CpuClock::default() { + let pll_freq = PllClock::Pll480MHz; + + if cpu_clock_speed.mhz() <= xtal_freq.mhz() { + apb_freq = ApbClock::ApbFreqOther(cpu_clock_speed.mhz()); + clocks_ll::esp32c2_rtc_update_to_xtal(xtal_freq, 1); + clocks_ll::esp32c2_rtc_apb_freq_update(apb_freq); + } else { + apb_freq = ApbClock::ApbFreq40MHz; + clocks_ll::esp32c2_rtc_bbpll_enable(); + clocks_ll::esp32c2_rtc_bbpll_configure(xtal_freq, pll_freq); + clocks_ll::esp32c2_rtc_freq_to_pll_mhz(cpu_clock_speed); + clocks_ll::esp32c2_rtc_apb_freq_update(apb_freq); + } } else { apb_freq = ApbClock::ApbFreq40MHz; - clocks_ll::esp32c2_rtc_bbpll_enable(); - clocks_ll::esp32c2_rtc_bbpll_configure(xtal_freq, pll_freq); - clocks_ll::esp32c2_rtc_freq_to_pll_mhz(cpu_clock_speed); - clocks_ll::esp32c2_rtc_apb_freq_update(apb_freq); } ClockControl { - _private: clock_control.into_ref(), desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(), apb_clock: apb_freq.frequency(), @@ -501,52 +458,33 @@ impl<'d> ClockControl<'d> { }, } } - - /// Use the highest possible frequency for a particular chip - pub fn max(clock_control: impl Peripheral

+ 'd) -> ClockControl<'d> { - Self::configure(clock_control, CpuClock::Clock120MHz) - } } #[cfg(esp32c3)] -impl<'d> ClockControl<'d> { - /// Use what is considered the default settings after boot. - pub fn boot_defaults( - clock_control: impl Peripheral

+ 'd, - ) -> ClockControl<'d> { - ClockControl { - _private: clock_control.into_ref(), - desired_rates: RawClocks { - cpu_clock: HertzU32::MHz(80), - apb_clock: HertzU32::MHz(80), - xtal_clock: HertzU32::MHz(40), - }, - } - } - +impl ClockControl { /// Configure the CPU clock speed. - pub fn configure( - clock_control: impl Peripheral

+ 'd, - cpu_clock_speed: CpuClock, - ) -> ClockControl<'d> { - let apb_freq; + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { let xtal_freq = XtalClock::RtcXtalFreq40M; - let pll_freq = PllClock::Pll480MHz; - if cpu_clock_speed.mhz() <= xtal_freq.mhz() { - apb_freq = ApbClock::ApbFreqOther(cpu_clock_speed.mhz()); - clocks_ll::esp32c3_rtc_update_to_xtal(xtal_freq, 1); - clocks_ll::esp32c3_rtc_apb_freq_update(apb_freq); + let apb_freq; + if cpu_clock_speed != CpuClock::default() { + if cpu_clock_speed.mhz() <= xtal_freq.mhz() { + apb_freq = ApbClock::ApbFreqOther(cpu_clock_speed.mhz()); + clocks_ll::esp32c3_rtc_update_to_xtal(xtal_freq, 1); + clocks_ll::esp32c3_rtc_apb_freq_update(apb_freq); + } else { + let pll_freq = PllClock::Pll480MHz; + apb_freq = ApbClock::ApbFreq80MHz; + clocks_ll::esp32c3_rtc_bbpll_enable(); + clocks_ll::esp32c3_rtc_bbpll_configure(xtal_freq, pll_freq); + clocks_ll::esp32c3_rtc_freq_to_pll_mhz(cpu_clock_speed); + clocks_ll::esp32c3_rtc_apb_freq_update(apb_freq); + } } else { apb_freq = ApbClock::ApbFreq80MHz; - clocks_ll::esp32c3_rtc_bbpll_enable(); - clocks_ll::esp32c3_rtc_bbpll_configure(xtal_freq, pll_freq); - clocks_ll::esp32c3_rtc_freq_to_pll_mhz(cpu_clock_speed); - clocks_ll::esp32c3_rtc_apb_freq_update(apb_freq); } ClockControl { - _private: clock_control.into_ref(), desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(), apb_clock: apb_freq.frequency(), @@ -554,53 +492,33 @@ impl<'d> ClockControl<'d> { }, } } - - /// Use the highest possible frequency for a particular chip - pub fn max(clock_control: impl Peripheral

+ 'd) -> ClockControl<'d> { - Self::configure(clock_control, CpuClock::Clock160MHz) - } } #[cfg(esp32c6)] -impl<'d> ClockControl<'d> { - /// Use what is considered the default settings after boot. - pub fn boot_defaults( - clock_control: impl Peripheral

+ 'd, - ) -> ClockControl<'d> { - ClockControl { - _private: clock_control.into_ref(), - desired_rates: RawClocks { - cpu_clock: HertzU32::MHz(80), - apb_clock: HertzU32::MHz(80), - xtal_clock: HertzU32::MHz(40), - crypto_clock: HertzU32::MHz(160), - }, - } - } - +impl ClockControl { /// Configure the CPU clock speed. - pub fn configure( - clock_control: impl Peripheral

+ 'd, - cpu_clock_speed: CpuClock, - ) -> ClockControl<'d> { - let apb_freq; + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { let xtal_freq = XtalClock::RtcXtalFreq40M; - let pll_freq = PllClock::Pll480MHz; - if cpu_clock_speed.mhz() <= xtal_freq.mhz() { - apb_freq = ApbClock::ApbFreqOther(cpu_clock_speed.mhz()); - clocks_ll::esp32c6_rtc_update_to_xtal(xtal_freq, 1); - clocks_ll::esp32c6_rtc_apb_freq_update(apb_freq); + let apb_freq; + if cpu_clock_speed != CpuClock::default() { + if cpu_clock_speed.mhz() <= xtal_freq.mhz() { + apb_freq = ApbClock::ApbFreqOther(cpu_clock_speed.mhz()); + clocks_ll::esp32c6_rtc_update_to_xtal(xtal_freq, 1); + clocks_ll::esp32c6_rtc_apb_freq_update(apb_freq); + } else { + let pll_freq = PllClock::Pll480MHz; + apb_freq = ApbClock::ApbFreq80MHz; + clocks_ll::esp32c6_rtc_bbpll_enable(); + clocks_ll::esp32c6_rtc_bbpll_configure(xtal_freq, pll_freq); + clocks_ll::esp32c6_rtc_freq_to_pll_mhz(cpu_clock_speed); + clocks_ll::esp32c6_rtc_apb_freq_update(apb_freq); + } } else { apb_freq = ApbClock::ApbFreq80MHz; - clocks_ll::esp32c6_rtc_bbpll_enable(); - clocks_ll::esp32c6_rtc_bbpll_configure(xtal_freq, pll_freq); - clocks_ll::esp32c6_rtc_freq_to_pll_mhz(cpu_clock_speed); - clocks_ll::esp32c6_rtc_apb_freq_update(apb_freq); } ClockControl { - _private: clock_control.into_ref(), desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(), apb_clock: apb_freq.frequency(), @@ -609,55 +527,33 @@ impl<'d> ClockControl<'d> { }, } } - - /// Use the highest possible frequency for a particular chip - pub fn max(clock_control: impl Peripheral

+ 'd) -> ClockControl<'d> { - Self::configure(clock_control, CpuClock::Clock160MHz) - } } #[cfg(esp32h2)] -impl<'d> ClockControl<'d> { - /// Use what is considered the default settings after boot. - pub fn boot_defaults( - clock_control: impl Peripheral

+ 'd, - ) -> ClockControl<'d> { - ClockControl { - _private: clock_control.into_ref(), - desired_rates: RawClocks { - cpu_clock: HertzU32::MHz(96), - apb_clock: HertzU32::MHz(32), - xtal_clock: HertzU32::MHz(32), - pll_48m_clock: HertzU32::MHz(48), - crypto_clock: HertzU32::MHz(96), - pll_96m_clock: HertzU32::MHz(96), - }, - } - } - +impl ClockControl { /// Configure the CPU clock speed. - pub fn configure( - clock_control: impl Peripheral

+ 'd, - cpu_clock_speed: CpuClock, - ) -> ClockControl<'d> { - let apb_freq; + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { let xtal_freq = XtalClock::RtcXtalFreq32M; - let pll_freq = PllClock::Pll96MHz; - if cpu_clock_speed.mhz() <= xtal_freq.mhz() { - apb_freq = ApbClock::ApbFreqOther(cpu_clock_speed.mhz()); - clocks_ll::esp32h2_rtc_update_to_xtal(xtal_freq, 1); - clocks_ll::esp32h2_rtc_apb_freq_update(apb_freq); + let apb_freq; + if cpu_clock_speed != CpuClock::default() { + if cpu_clock_speed.mhz() <= xtal_freq.mhz() { + apb_freq = ApbClock::ApbFreqOther(cpu_clock_speed.mhz()); + clocks_ll::esp32h2_rtc_update_to_xtal(xtal_freq, 1); + clocks_ll::esp32h2_rtc_apb_freq_update(apb_freq); + } else { + let pll_freq = PllClock::Pll96MHz; + apb_freq = ApbClock::ApbFreq32MHz; + clocks_ll::esp32h2_rtc_bbpll_enable(); + clocks_ll::esp32h2_rtc_bbpll_configure(xtal_freq, pll_freq); + clocks_ll::esp32h2_rtc_freq_to_pll_mhz(cpu_clock_speed); + clocks_ll::esp32h2_rtc_apb_freq_update(apb_freq); + } } else { apb_freq = ApbClock::ApbFreq32MHz; - clocks_ll::esp32h2_rtc_bbpll_enable(); - clocks_ll::esp32h2_rtc_bbpll_configure(xtal_freq, pll_freq); - clocks_ll::esp32h2_rtc_freq_to_pll_mhz(cpu_clock_speed); - clocks_ll::esp32h2_rtc_apb_freq_update(apb_freq); } ClockControl { - _private: clock_control.into_ref(), desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(), apb_clock: apb_freq.frequency(), @@ -668,38 +564,17 @@ impl<'d> ClockControl<'d> { }, } } - - /// Use the highest possible frequency for a particular chip - pub fn max(clock_control: impl Peripheral

+ 'd) -> ClockControl<'d> { - Self::configure(clock_control, CpuClock::Clock96MHz) - } } #[cfg(esp32s2)] -impl<'d> ClockControl<'d> { - /// Use what is considered the default settings after boot. - pub fn boot_defaults( - clock_control: impl Peripheral

+ 'd, - ) -> ClockControl<'d> { - ClockControl { - _private: clock_control.into_ref(), - desired_rates: RawClocks { - cpu_clock: HertzU32::MHz(80), - apb_clock: HertzU32::MHz(80), - xtal_clock: HertzU32::MHz(40), - }, - } - } - +impl ClockControl { /// Configure the CPU clock speed. - pub fn configure( - clock_control: impl Peripheral

+ 'd, - cpu_clock_speed: CpuClock, - ) -> ClockControl<'d> { - clocks_ll::set_cpu_clock(cpu_clock_speed); + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { + if cpu_clock_speed != CpuClock::default() { + clocks_ll::set_cpu_clock(cpu_clock_speed); + } ClockControl { - _private: clock_control.into_ref(), desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(), apb_clock: HertzU32::MHz(80), @@ -707,39 +582,17 @@ impl<'d> ClockControl<'d> { }, } } - - /// Use the highest possible frequency for a particular chip - pub fn max(clock_control: impl Peripheral

+ 'd) -> ClockControl<'d> { - Self::configure(clock_control, CpuClock::Clock240MHz) - } } #[cfg(esp32s3)] -impl<'d> ClockControl<'d> { - /// Use what is considered the default settings after boot. - pub fn boot_defaults( - clock_control: impl Peripheral

+ 'd, - ) -> ClockControl<'d> { - ClockControl { - _private: clock_control.into_ref(), - desired_rates: RawClocks { - cpu_clock: HertzU32::MHz(80), - apb_clock: HertzU32::MHz(80), - xtal_clock: HertzU32::MHz(40), - crypto_pwm_clock: HertzU32::MHz(160), - }, - } - } - +impl ClockControl { /// Configure the CPU clock speed. - pub fn configure( - clock_control: impl Peripheral

+ 'd, - cpu_clock_speed: CpuClock, - ) -> ClockControl<'d> { - clocks_ll::set_cpu_clock(cpu_clock_speed); + pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { + if cpu_clock_speed != CpuClock::default() { + clocks_ll::set_cpu_clock(cpu_clock_speed); + } ClockControl { - _private: clock_control.into_ref(), desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(), apb_clock: HertzU32::MHz(80), @@ -748,9 +601,4 @@ impl<'d> ClockControl<'d> { }, } } - - /// Use the highest possible frequency for a particular chip - pub fn max(clock_control: impl Peripheral

+ 'd) -> ClockControl<'d> { - Self::configure(clock_control, CpuClock::Clock240MHz) - } } diff --git a/esp-hal/src/delay.rs b/esp-hal/src/delay.rs index 842d7bcbf28..c15c6e66ae6 100644 --- a/esp-hal/src/delay.rs +++ b/esp-hal/src/delay.rs @@ -1,16 +1,18 @@ //! # Delay //! //! ## Overview +//! //! The Delay driver provides blocking delay functionalities using the -//! `SYSTIMER` peripheral for RISC-V devices and the built-in Xtensa timer for -//! Xtensa devices. +//! [current_time] function. //! //! ## Configuration +//! //! The delays are implemented in a "best-effort" way, meaning that the CPU will //! block for at least the amount of time specified, but accuracy can be //! affected by many factors, including interrupt usage. //! //! ## Usage +//! //! This module implements the blocking [DelayMs] and [DelayUs] traits from //! [embedded-hal], both 0.2.x and 1.x.x. //! @@ -29,6 +31,7 @@ //! [DelayMs]: embedded_hal_02::blocking::delay::DelayMs //! [DelayUs]: embedded_hal_02::blocking::delay::DelayUs //! [embedded-hal]: https://docs.rs/embedded-hal/1.0.0/embedded_hal/delay/index.html +//! [current_time]: crate::time::current_time pub use fugit::MicrosDurationU64; diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs index 5dc5e2ec48b..059bd98b1a1 100644 --- a/esp-hal/src/dma/mod.rs +++ b/esp-hal/src/dma/mod.rs @@ -21,7 +21,6 @@ //! # use esp_hal::gpio::Io; //! # use esp_hal::spi::{master::Spi, SpiMode}; //! # use esp_hal::dma::{Dma, DmaPriority}; -//! # use crate::esp_hal::prelude::_fugit_RateExtU32; //! let dma = Dma::new(peripherals.DMA); #![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = dma.spi2channel;")] #![cfg_attr(not(any(esp32, esp32s2)), doc = "let dma_channel = dma.channel0;")] @@ -31,7 +30,12 @@ //! let mosi = io.pins.gpio4; //! let cs = io.pins.gpio5; //! -//! let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks) +//! let mut spi = Spi::new( +//! peripherals.SPI2, +//! 100.kHz(), +//! SpiMode::Mode0, +//! &clocks +//! ) //! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) //! .with_dma(dma_channel.configure( //! false, @@ -43,10 +47,10 @@ //! ⚠️ Note: Descriptors should be sized as `(max_transfer_size + CHUNK_SIZE - 1) / CHUNK_SIZE`. //! I.e., to transfer buffers of size `1..=CHUNK_SIZE`, you need 1 descriptor. //! -//! ⚠️ Note: For chips that support DMA to/from PSRAM (esp32s3) DMA transfers to/from PSRAM +//! ⚠️ Note: For chips that support DMA to/from PSRAM (ESP32-S3) DMA transfers to/from PSRAM //! have extra alignment requirements. The address and size of the buffer pointed to by //! each descriptor must be a multiple of the cache line (block) size. This is 32 bytes -//! on esp32s3. +//! on ESP32-S3. //! //! For convenience you can use the [crate::dma_buffers] macro. @@ -288,7 +292,7 @@ mod gdma; #[cfg(pdma)] mod pdma; -/// Kinds of interrupt to listen to +/// Kinds of interrupt to listen to. #[derive(EnumSetType)] pub enum DmaInterrupt { /// TX is done @@ -297,15 +301,21 @@ pub enum DmaInterrupt { RxDone, } -/// The default CHUNK_SIZE used for DMA transfers +/// The default chunk size used for DMA transfers. pub const CHUNK_SIZE: usize = 4092; -/// Convenience macro to create DMA buffers and descriptors +/// Convenience macro to create DMA buffers and descriptors. /// /// ## Usage -/// ```rust,ignore -/// // TX and RX buffers are 32000 bytes - passing only one parameter makes TX and RX the same size -/// let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = dma_buffers!(32000, 32000); +/// ```rust,no_run +#[doc = crate::before_snippet!()] +/// use esp_hal::dma_buffers; +/// +/// // TX and RX buffers are 32000 bytes - passing only one parameter makes TX +/// // and RX the same size. +/// let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = +/// dma_buffers!(32000, 32000); +/// # } /// ``` #[macro_export] macro_rules! dma_buffers { @@ -317,13 +327,18 @@ macro_rules! dma_buffers { }; } -/// Convenience macro to create circular DMA buffers and descriptors +/// Convenience macro to create circular DMA buffers and descriptors. /// /// ## Usage -/// ```rust,ignore -/// // TX and RX buffers are 32000 bytes - passing only one parameter makes TX and RX the same size +/// ```rust,no_run +#[doc = crate::before_snippet!()] +/// use esp_hal::dma_circular_buffers; +/// +/// // TX and RX buffers are 32000 bytes - passing only one parameter makes TX +/// // and RX the same size. /// let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = /// dma_circular_buffers!(32000, 32000); +/// # } /// ``` #[macro_export] macro_rules! dma_circular_buffers { @@ -336,12 +351,17 @@ macro_rules! dma_circular_buffers { }; } -/// Convenience macro to create DMA descriptors +/// Convenience macro to create DMA descriptors. /// /// ## Usage -/// ```rust,ignore -/// // Create TX and RX descriptors for transactions up to 32000 bytes - passing only one parameter assumes TX and RX are the same size +/// ```rust,no_run +#[doc = crate::before_snippet!()] +/// use esp_hal::dma_descriptors; +/// +/// // Create TX and RX descriptors for transactions up to 32000 bytes - passing +/// // only one parameter assumes TX and RX are the same size. /// let (tx_descriptors, rx_descriptors) = dma_descriptors!(32000, 32000); +/// # } /// ``` #[macro_export] macro_rules! dma_descriptors { @@ -354,12 +374,18 @@ macro_rules! dma_descriptors { }; } -/// Convenience macro to create circular DMA descriptors +/// Convenience macro to create circular DMA descriptors. /// /// ## Usage -/// ```rust,ignore -/// // Create TX and RX descriptors for transactions up to 32000 bytes - passing only one parameter assumes TX and RX are the same size -/// let (tx_descriptors, rx_descriptors) = dma_circular_descriptors!(32000, 32000); +/// ```rust,no_run +#[doc = crate::before_snippet!()] +/// use esp_hal::dma_circular_descriptors; +/// +/// // Create TX and RX descriptors for transactions up to 32000 +/// // bytes - passing only one parameter assumes TX and RX are the same size. +/// let (tx_descriptors, rx_descriptors) = +/// dma_circular_descriptors!(32000, 32000); +/// # } /// ``` #[macro_export] macro_rules! dma_circular_descriptors { @@ -373,12 +399,18 @@ macro_rules! dma_circular_descriptors { } /// Convenience macro to create DMA buffers and descriptors with specific chunk -/// size +/// size. /// /// ## Usage -/// ```rust,ignore -/// // TX and RX buffers are 32000 bytes - passing only one parameter makes TX and RX the same size -/// let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = dma_buffers!(32000, 32000, 4032); +/// ```rust,no_run +#[doc = crate::before_snippet!()] +/// use esp_hal::dma_buffers_chunk_size; +/// +/// // TX and RX buffers are 32000 bytes - passing only one parameter makes TX +/// // and RX the same size. +/// let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = +/// dma_buffers_chunk_size!(32000, 32000, 4032); +/// # } /// ``` #[macro_export] macro_rules! dma_buffers_chunk_size { @@ -403,13 +435,18 @@ macro_rules! dma_buffers_chunk_size { } /// Convenience macro to create circular DMA buffers and descriptors with -/// specific chunk size +/// specific chunk size. /// /// ## Usage -/// ```rust,ignore -/// // TX and RX buffers are 32000 bytes - passing only one parameter makes TX and RX the same size +/// ```rust,no_run +#[doc = crate::before_snippet!()] +/// use esp_hal::dma_circular_buffers_chunk_size; +/// +/// // TX and RX buffers are 32000 bytes - passing only one parameter makes TX +/// // and RX the same size. /// let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = -/// dma_circular_buffers!(32000, 32000, 4032); +/// dma_circular_buffers_chunk_size!(32000, 32000, 4032); +/// # } /// ``` #[macro_export] macro_rules! dma_circular_buffers_chunk_size { @@ -436,9 +473,15 @@ macro_rules! dma_circular_buffers_chunk_size { /// Convenience macro to create DMA descriptors with specific chunk size /// /// ## Usage -/// ```rust,ignore -/// // Create TX and RX descriptors for transactions up to 32000 bytes - passing only one parameter assumes TX and RX are the same size -/// let (tx_descriptors, rx_descriptors) = dma_descriptors_chunk_size!(32000, 32000, 4032); +/// ```rust,no_run +#[doc = crate::before_snippet!()] +/// use esp_hal::dma_descriptors_chunk_size; +/// +/// // Create TX and RX descriptors for transactions up to 32000 bytes - passing +/// // only one parameter assumes TX and RX are the same size. +/// let (tx_descriptors, rx_descriptors) = +/// dma_descriptors_chunk_size!(32000, 32000, 4032); +/// # } /// ``` #[macro_export] macro_rules! dma_descriptors_chunk_size { @@ -465,9 +508,15 @@ macro_rules! dma_descriptors_chunk_size { /// size /// /// ## Usage -/// ```rust,ignore -/// // Create TX and RX descriptors for transactions up to 32000 bytes - passing only one parameter assumes TX and RX are the same size -/// let (tx_descriptors, rx_descriptors) = dma_circular_descriptors!(32000, 32000, 4032); +/// ```rust,no_run +#[doc = crate::before_snippet!()] +/// use esp_hal::dma_circular_descriptors_chunk_size; +/// +/// // Create TX and RX descriptors for transactions up to 32000 bytes - passing +/// // only one parameter assumes TX and RX are the same size. +/// let (tx_descriptors, rx_descriptors) = +/// dma_circular_descriptors_chunk_size!(32000, 32000, 4032); +/// # } /// ``` #[macro_export] macro_rules! dma_circular_descriptors_chunk_size { diff --git a/esp-hal/src/gpio/rtc_io.rs b/esp-hal/src/gpio/rtc_io.rs index 423e2b9cee6..db3ed328829 100644 --- a/esp-hal/src/gpio/rtc_io.rs +++ b/esp-hal/src/gpio/rtc_io.rs @@ -1,10 +1,12 @@ //! RTC IO //! //! # Overview +//! //! The hardware provides a couple of GPIO pins with low power (LP) //! capabilities and analog functions. //! //! ## Configuration +//! //! These pins can be controlled by either IO MUX or RTC IO. //! //! If controlled by RTC IO, these pins will bypass IO MUX and GPIO @@ -14,12 +16,18 @@ //! the peripherals in RTC system during chip Deep-sleep, and wake up the //! chip from Deep-sleep. //! -//! # Example -//! ## Configure a ULP Pin as Output -//! ```rust, ignore +//! ## Example +//! +//! ### Configure a ULP Pin as Output +//! +//! ```rust, no_run +#![doc = crate::before_snippet!()] +//! # use esp_hal::gpio::rtc_io::LowPowerOutput; +//! # use esp_hal::gpio::Io; //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! // configure GPIO 1 as ULP output pin -//! let lp_pin = LowPowerOutput::new(io.pins.gpio1); +//! let lp_pin = LowPowerOutput::<'static, 1>::new(io.pins.gpio1); +//! # } //! ``` use core::marker::PhantomData; diff --git a/esp-hal/src/i2c.rs b/esp-hal/src/i2c.rs index c3071229027..d2c2ca0c6b0 100644 --- a/esp-hal/src/i2c.rs +++ b/esp-hal/src/i2c.rs @@ -5,54 +5,38 @@ //! same bus. I2C uses two bidirectional open-drain lines: serial data line //! (SDA) and serial clock line (SCL), pulled up by resistors. //! -//! Espressif devices sometimes have more than one I2C controller (also called -//! port), responsible for handling communication on the I2C bus. A single I2C -//! controller can be a master or a slave. +//! Espressif devices sometimes have more than one I2C controller, responsible +//! for handling communication on the I2C bus. A single I2C controller can be +//! a master or a slave. //! //! Typically, an I2C slave device has a 7-bit address or 10-bit address. -//! Espressif devices supports both I2C Standard-mode (Sm) and Fast-mode -//! (Fm) which can go up to 100KHz and 400KHz respectively. +//! Devices supports both I2C Standard-mode (Sm) and Fast-mode (Fm) which can +//! go up to 100KHz and 400KHz respectively. //! //! ## Configuration //! //! Each I2C controller is individually configurable, and the usual setting //! such as frequency, timeout, and SDA/SCL pins can easily be configured. //! -//! ```rust, no_run -#![doc = crate::before_snippet!()] -//! # use esp_hal::i2c::I2C; -//! # use esp_hal::gpio::Io; -//! # use crate::esp_hal::prelude::_fugit_RateExtU32; -//! 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.gpio1, -//! io.pins.gpio2, -//! 100.kHz(), -//! &clocks, -//! ); -//! # } -//! ``` -//! //! ## Usage //! //! The I2C driver implements a number of third-party traits, with the //! intention of making the HAL inter-compatible with various device drivers //! from the community. This includes the [embedded-hal] for both 0.2.x and -//! 1.x.x versions. +//! 1.0.x versions. //! //! ## Examples +//! //! ### Read Data from a BMP180 Sensor +//! //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::i2c::I2C; //! # use esp_hal::gpio::Io; -//! # use crate::esp_hal::prelude::_fugit_RateExtU32; //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); +//! //! // Create a new peripheral object with the described wiring -//! // and standard I2C clock speed +//! // and standard I2C clock speed. //! let mut i2c = I2C::new( //! peripherals.I2C0, //! io.pins.gpio1, @@ -60,6 +44,7 @@ //! 100.kHz(), //! &clocks, //! ); +//! //! loop { //! let mut data = [0u8; 22]; //! i2c.write_read(0x77, &[0xaa], &mut data).ok(); diff --git a/esp-hal/src/i2s.rs b/esp-hal/src/i2s.rs index 08f0f3a5b32..ac390c9fde0 100644 --- a/esp-hal/src/i2s.rs +++ b/esp-hal/src/i2s.rs @@ -1,14 +1,15 @@ //! # Inter-IC Sound (I2S) //! //! ## Overview +//! //! I2S (Inter-IC Sound) is a synchronous serial communication protocol usually //! used for transmitting audio data between two digital audio devices. //! Espressif devices may contain more than one I2S peripheral(s). These //! peripherals can be configured to input and output sample data via the I2S //! driver. //! -//! //! ## Configuration +//! //! I2S supports different data formats, including varying data and channel //! widths, different standards, such as the Philips standard and configurable //! pin mappings for I2S clock (BCLK), word select (WS), and data input/output @@ -18,24 +19,23 @@ //! supports various configurations, such as different data formats, standards //! (e.g., Philips) and pin configurations. It relies on other peripheral //! modules, such as -//! - `GPIO` -//! - `DMA` -//! - `system` (to configure and enable the I2S peripheral) +//! - `GPIO` +//! - `DMA` +//! - `system` (to configure and enable the I2S peripheral) +//! +//! ## Example //! -//! ## Examples //! ### Initialization +//! //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::i2s::I2s; //! # use esp_hal::i2s::Standard; //! # use esp_hal::i2s::DataFormat; +//! # use esp_hal::i2s::I2sReadDma; //! # use esp_hal::gpio::Io; //! # use esp_hal::dma_buffers; //! # use esp_hal::dma::{Dma, DmaPriority}; -//! # use crate::esp_hal::prelude::_fugit_RateExtU32; -//! # use crate::esp_hal::peripherals::Peripherals; -//! # use crate::esp_hal::i2s::I2sReadDma; -//! # use core::ptr::addr_of_mut; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! let dma = Dma::new(peripherals.DMA); #![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = dma.i2s0channel;")] diff --git a/esp-hal/src/interrupt/mod.rs b/esp-hal/src/interrupt/mod.rs index d082f93d81f..b71b9757f93 100644 --- a/esp-hal/src/interrupt/mod.rs +++ b/esp-hal/src/interrupt/mod.rs @@ -30,43 +30,35 @@ //! //! ```rust, no_run #![doc = crate::before_snippet!()] -//! # use core::cell::RefCell; +//! let mut sw_int = +//! SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); +//! critical_section::with(|cs| { +//! sw_int +//! .software_interrupt0 +//! .set_interrupt_handler(swint0_handler); +//! SWINT0 +//! .borrow_ref_mut(cs) +//! .replace(sw_int.software_interrupt0); +//! }); +//! +//! critical_section::with(|cs| { +//! SWINT0.borrow_ref(cs).as_ref().unwrap().raise(); +//! }); +//! # +//! # loop {} +//! # } //! +//! # use core::cell::RefCell; +//! # //! # use critical_section::Mutex; -//! # use esp_hal::{ -//! # prelude::*, -//! # system::{SoftwareInterrupt, SystemControl}, -//! # }; +//! # use esp_hal::interrupt::software::{SoftwareInterrupt, SoftwareInterruptControl}; //! # use esp_hal::interrupt::Priority; //! # use esp_hal::interrupt::InterruptHandler; -//! +//! # //! static SWINT0: Mutex>>> = -//! Mutex::new(RefCell::new(None)); +//! Mutex::new(RefCell::new(None)); //! -//! let mut sw_int = system.software_interrupt_control; -//! critical_section::with(|cs| { -//! sw_int -//! .software_interrupt0 -//! .set_interrupt_handler(swint0_handler); -//! SWINT0 -//! .borrow_ref_mut(cs) -//! .replace(sw_int.software_interrupt0); -//! }); -//! -//! critical_section::with(|cs| { -//! SWINT0.borrow_ref(cs).as_ref().unwrap().raise(); -//! }); -//! -//! loop {} -//! } -//! -//! # use procmacros::handler; -//! # use esp_hal::interrupt; -//! # use critical_section::Mutex; -//! # use core::cell::RefCell; -//! # use esp_hal::system::SoftwareInterrupt; -//! # static SWINT0: Mutex>>> = Mutex::new(RefCell::new(None)); -//! #[handler(priority = esp_hal::interrupt::Priority::Priority1)] +//! #[handler(priority = Priority::Priority1)] //! fn swint0_handler() { //! // esp_println::println!("SW interrupt0"); //! critical_section::with(|cs| { @@ -87,6 +79,8 @@ mod riscv; #[cfg(xtensa)] mod xtensa; +pub mod software; + /// An interrupt handler #[cfg_attr( multi_core, diff --git a/esp-hal/src/interrupt/software.rs b/esp-hal/src/interrupt/software.rs new file mode 100644 index 00000000000..67aab7dcb1d --- /dev/null +++ b/esp-hal/src/interrupt/software.rs @@ -0,0 +1,192 @@ +//! # Software Interrupts +//! +//! The [`SoftwareInterruptControl`] struct gives access to the available +//! software interrupts. +//! +//! The [`SoftwareInterrupt`] struct allows raising or resetting software +//! interrupts using the [`raise()`][SoftwareInterrupt::raise] and +//! [`reset()`][SoftwareInterrupt::reset] methods. +//! +//! ## Examples +//! +//! ```rust, no_run +#![doc = crate::before_snippet!()] +//! let sw_ints = +//! SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); +//! +//! // Take the interrupt you want to use. +//! let mut int0 = sw_ints.software_interrupt0; +//! +//! // Set up the interrupt handler. Do this in a critical section so the global +//! // contains the interrupt object before the interrupt is triggered. +//! critical_section::with(|cs| { +//! int0.set_interrupt_handler(interrupt_handler); +//! SWINT0.borrow_ref_mut(cs).replace(int0); +//! }); +//! # } +//! +//! # use core::cell::RefCell; +//! # use critical_section::Mutex; +//! # use esp_hal::interrupt::software::{SoftwareInterrupt, SoftwareInterruptControl}; +//! // ... somewhere outside of your main function +//! +//! // Define a shared handle to the software interrupt. +//! static SWINT0: Mutex>>> = +//! Mutex::new(RefCell::new(None)); +//! +//! #[handler] +//! fn interrupt_handler() { +//! // esp_println::println!("SW interrupt0 handled"); +//! +//! // Clear the interrupt request. +//! critical_section::with(|cs| { +//! SWINT0.borrow_ref(cs).as_ref().unwrap().reset(); +//! }); +//! } +//! ``` + +use crate::{interrupt::InterruptHandler, InterruptConfigurable}; + +/// A software interrupt can be triggered by software. +#[non_exhaustive] +pub struct SoftwareInterrupt; + +impl SoftwareInterrupt { + /// Sets the interrupt handler for this software-interrupt + pub fn set_interrupt_handler(&mut self, handler: InterruptHandler) { + let interrupt = match NUM { + 0 => crate::peripherals::Interrupt::FROM_CPU_INTR0, + 1 => crate::peripherals::Interrupt::FROM_CPU_INTR1, + 2 => crate::peripherals::Interrupt::FROM_CPU_INTR2, + 3 => crate::peripherals::Interrupt::FROM_CPU_INTR3, + _ => unreachable!(), + }; + + unsafe { + crate::interrupt::bind_interrupt(interrupt, handler.handler()); + crate::interrupt::enable(interrupt, handler.priority()).unwrap(); + } + } + + /// Trigger this software-interrupt + pub fn raise(&self) { + cfg_if::cfg_if! { + if #[cfg(any(esp32c6, esp32h2))] { + let system = unsafe { &*crate::peripherals::INTPRI::PTR }; + } else { + let system = unsafe { &*crate::peripherals::SYSTEM::PTR }; + } + } + + match NUM { + 0 => system + .cpu_intr_from_cpu_0() + .write(|w| w.cpu_intr_from_cpu_0().set_bit()), + 1 => system + .cpu_intr_from_cpu_1() + .write(|w| w.cpu_intr_from_cpu_1().set_bit()), + 2 => system + .cpu_intr_from_cpu_2() + .write(|w| w.cpu_intr_from_cpu_2().set_bit()), + 3 => system + .cpu_intr_from_cpu_3() + .write(|w| w.cpu_intr_from_cpu_3().set_bit()), + _ => unreachable!(), + } + } + + /// Resets this software-interrupt + pub fn reset(&self) { + cfg_if::cfg_if! { + if #[cfg(any(esp32c6, esp32h2))] { + let system = unsafe { &*crate::peripherals::INTPRI::PTR }; + } else { + let system = unsafe { &*crate::peripherals::SYSTEM::PTR }; + } + } + + match NUM { + 0 => system + .cpu_intr_from_cpu_0() + .write(|w| w.cpu_intr_from_cpu_0().clear_bit()), + 1 => system + .cpu_intr_from_cpu_1() + .write(|w| w.cpu_intr_from_cpu_1().clear_bit()), + 2 => system + .cpu_intr_from_cpu_2() + .write(|w| w.cpu_intr_from_cpu_2().clear_bit()), + 3 => system + .cpu_intr_from_cpu_3() + .write(|w| w.cpu_intr_from_cpu_3().clear_bit()), + _ => unreachable!(), + } + } + + /// Unsafely create an instance of this peripheral out of thin air. + /// + /// # Safety + /// + /// You must ensure that you're only using one instance of this type at a + /// time. + #[inline] + pub unsafe fn steal() -> Self { + Self + } +} + +impl crate::peripheral::Peripheral for SoftwareInterrupt { + type P = SoftwareInterrupt; + + #[inline] + unsafe fn clone_unchecked(&mut self) -> Self::P { + Self::steal() + } +} + +impl crate::private::Sealed for SoftwareInterrupt {} + +impl InterruptConfigurable for SoftwareInterrupt { + fn set_interrupt_handler(&mut self, handler: crate::interrupt::InterruptHandler) { + SoftwareInterrupt::set_interrupt_handler(self, handler); + } +} + +/// This gives access to the available software interrupts. +/// +/// This struct contains several instances of software interrupts that can be +/// used for signaling between different parts of a program or system. Each +/// interrupt is identified by an index (0 to 3). +#[cfg_attr( + multi_core, + doc = r#" + +Please note: Software interrupt 3 is reserved +for inter-processor communication when using +`esp-hal-embassy`."# +)] +#[non_exhaustive] +pub struct SoftwareInterruptControl { + /// Software interrupt 0. + pub software_interrupt0: SoftwareInterrupt<0>, + /// Software interrupt 1. + pub software_interrupt1: SoftwareInterrupt<1>, + /// Software interrupt 2. + pub software_interrupt2: SoftwareInterrupt<2>, + #[cfg(not(all(feature = "__esp_hal_embassy", multi_core)))] + /// Software interrupt 3. Only available when not using `esp-hal-embassy`, + /// or on single-core systems. + pub software_interrupt3: SoftwareInterrupt<3>, +} + +impl SoftwareInterruptControl { + /// Create a new instance of the software interrupt control. + pub fn new(_peripheral: crate::peripherals::SW_INTERRUPT) -> Self { + SoftwareInterruptControl { + software_interrupt0: SoftwareInterrupt {}, + software_interrupt1: SoftwareInterrupt {}, + software_interrupt2: SoftwareInterrupt {}, + #[cfg(not(all(feature = "__esp_hal_embassy", multi_core)))] + software_interrupt3: SoftwareInterrupt {}, + } + } +} diff --git a/esp-hal/src/lcd_cam/lcd/i8080.rs b/esp-hal/src/lcd_cam/lcd/i8080.rs index 0a67505bda9..27af36a8578 100644 --- a/esp-hal/src/lcd_cam/lcd/i8080.rs +++ b/esp-hal/src/lcd_cam/lcd/i8080.rs @@ -1,14 +1,17 @@ //! # LCD - I8080/MOTO6800 Mode. //! //! ## Overview +//! //! The LCD_CAM peripheral I8080 driver provides support for the I8080 -//! format/timing. The driver mandates DMA for DMA (Direct Memory Access) for +//! format/timing. The driver mandates DMA (Direct Memory Access) for //! efficient data transfer. //! -//! ## Examples +//! ## Example +//! //! ### MIPI-DSI Display -//! Following code show how to send a command to a MIPI-DSI display over I8080 -//! protocol. +//! +//! The following example shows how to send a command to a MIPI-DSI display over +//! the I8080 protocol. //! //! ```rust, no_run #![doc = crate::before_snippet!()] @@ -16,8 +19,6 @@ //! # use esp_hal::lcd_cam::{LcdCam, lcd::i8080::{Config, I8080, TxEightBits}}; //! # use esp_hal::dma_buffers; //! # use esp_hal::dma::{Dma, DmaPriority}; -//! # use fugit::RateExtU32; -//! //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! //! # let dma = Dma::new(peripherals.DMA); diff --git a/esp-hal/src/ledc/mod.rs b/esp-hal/src/ledc/mod.rs index f37af1fbef2..86a8f18a5fb 100644 --- a/esp-hal/src/ledc/mod.rs +++ b/esp-hal/src/ledc/mod.rs @@ -18,8 +18,10 @@ //! ## Examples //! //! ### Low Speed Channel -//! The following will configure the Low Speed Channel0 to 24kHz output with -//! 10% duty using the ABPClock +//! +//! The following example will configure the Low Speed Channel0 to 24kHz output +//! with 10% duty using the ABPClock. +//! //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::ledc::Ledc; @@ -28,10 +30,6 @@ //! # use esp_hal::ledc::LowSpeed; //! # use esp_hal::ledc::channel; //! # use esp_hal::gpio::Io; -//! # use crate::esp_hal::prelude::_esp_hal_ledc_timer_TimerIFace; -//! # use crate::esp_hal::prelude::_fugit_RateExtU32; -//! # use crate::esp_hal::prelude::_esp_hal_ledc_channel_ChannelIFace; -//! //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let led = io.pins.gpio0; //! diff --git a/esp-hal/src/lib.rs b/esp-hal/src/lib.rs index 1af867cfc8a..07636b5cfb9 100644 --- a/esp-hal/src/lib.rs +++ b/esp-hal/src/lib.rs @@ -17,7 +17,7 @@ #![cfg_attr(esp32c3, doc = "**ESP32-C3**")] #![cfg_attr(esp32c6, doc = "**ESP32-C6**")] #![cfg_attr(esp32h2, doc = "**ESP32-H2**")] -//! please ensure you are reading the correct [documentation] for your target +//! . Please ensure you are reading the correct [documentation] for your target //! device. //! //! ## Choosing a Device @@ -60,26 +60,20 @@ //! #![no_std] //! #![no_main] //! -//! // A panic - handler e.g. `use esp_backtrace as _;` -//! +//! // You'll need a panic handler e.g. `use esp_backtrace as _;` +//! # #[panic_handler] +//! # fn panic(_ : &core::panic::PanicInfo) -> ! { +//! # loop {} +//! # } //! use esp_hal::{ -//! clock::ClockControl, //! delay::Delay, //! gpio::{Io, Level, Output}, -//! peripherals::Peripherals, //! prelude::*, -//! system::SystemControl, //! }; -//! # #[panic_handler] -//! # fn panic(_ : &core::panic::PanicInfo) -> ! { -//! # loop {} -//! # } //! //! #[entry] //! fn main() -> ! { -//! let peripherals = Peripherals::take(); -//! let system = SystemControl::new(peripherals.SYSTEM); -//! let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); +//! let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); //! //! // Set GPIO0 as an output, and set its state high initially. //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -95,14 +89,11 @@ //! ``` //! //! The steps here are: -//! - Take all the peripherals from the PAC to pass them to the HAL drivers -//! later -//! - Create [system::SystemControl] -//! - Configure the system clocks - in this case use the boot defaults -//! - Create [gpio::Io] which provides access to the GPIO pins -//! - Create an [gpio::Output] pin driver which lets us control the logical +//! - Call [`init`] with the desired [`CpuClock`] configuration +//! - Create [`gpio::Io`] which provides access to the GPIO pins +//! - Create an [`gpio::Output`] pin driver which lets us control the logical //! level of an output pin -//! - Create a [delay::Delay] driver +//! - Create a [`delay::Delay`] driver //! - In a loop, toggle the output pin's logical level with a delay of 1000 ms //! //! ## `PeripheralRef` Pattern @@ -111,7 +102,7 @@ //! This means you can pass the pin/peripheral or a mutable reference to the //! pin/peripheral. //! -//! The later can be used to regain access to the pin when the driver gets +//! The latter can be used to regain access to the pin when the driver gets //! dropped. Then it's possible to reuse the pin/peripheral for a different //! purpose. //! @@ -626,17 +617,38 @@ macro_rules! before_snippet { () => { r#" # #![no_std] -# use esp_hal::peripherals::Peripherals; -# use esp_hal::clock::ClockControl; -# use esp_hal::system::SystemControl; +# use esp_hal::prelude::*; +# use procmacros::handler; +# use esp_hal::interrupt; # #[panic_handler] # fn panic(_ : &core::panic::PanicInfo) -> ! { # loop {} # } # fn main() { -# let peripherals = Peripherals::take(); -# let system = SystemControl::new(peripherals.SYSTEM); -# let mut clocks = ClockControl::boot_defaults(system.clock_control).freeze(); +# let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); "# }; } + +use crate::{ + clock::{ClockControl, Clocks, CpuClock}, + peripherals::Peripherals, +}; + +/// System configuration. +#[non_exhaustive] +#[derive(Default)] +pub struct Config { + /// The CPU clock configuration. + pub cpu_clock: CpuClock, +} + +/// Initialize the system. +/// +/// This function sets up the CPU clock and returns the peripherals and clocks. +pub fn init(config: Config) -> (Peripherals, Clocks<'static>) { + let peripherals = Peripherals::take(); + let clocks = ClockControl::new(config.cpu_clock).freeze(); + + (peripherals, clocks) +} diff --git a/esp-hal/src/mcpwm/mod.rs b/esp-hal/src/mcpwm/mod.rs index 94d84909a44..0d1b1cfcd16 100644 --- a/esp-hal/src/mcpwm/mod.rs +++ b/esp-hal/src/mcpwm/mod.rs @@ -42,14 +42,16 @@ #![cfg_attr(esp32h2, doc = "Clock source is XTAL")] #![doc = ""] //! ## Examples +//! //! ### Output a 20 kHz signal -//! Uses timer0 and operator0 of the MCPWM0 peripheral to output a 50% duty -//! signal at 20 kHz. The signal will be output to the pin assigned to `pin`. +//! +//! This example uses timer0 and operator0 of the MCPWM0 peripheral to output a +//! 50% duty signal at 20 kHz. The signal will be output to the pin assigned to +//! `pin`. +//! //! ```rust, no_run #![doc = crate::before_snippet!()] -//! # use esp_hal::{mcpwm, prelude::*}; -//! # use esp_hal::mcpwm::operator::{DeadTimeCfg, PWMStream}; -//! # use mcpwm::{operator::PwmPinConfig, timer::PwmWorkingMode, McPwm, PeripheralClockConfig}; +//! # use esp_hal::mcpwm::{operator::{DeadTimeCfg, PWMStream, PwmPinConfig}, timer::PwmWorkingMode, McPwm, PeripheralClockConfig}; //! # use esp_hal::gpio::Io; //! //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/esp-hal/src/mcpwm/operator.rs b/esp-hal/src/mcpwm/operator.rs index de6c5fe3517..9d08ac1966a 100644 --- a/esp-hal/src/mcpwm/operator.rs +++ b/esp-hal/src/mcpwm/operator.rs @@ -479,6 +479,7 @@ impl<'d, Pin: OutputPin, PWM: PwmPeripheral, const OP: u8, const IS_A: bool> /// configured deadtime. /// /// # H-Bridge example +/// /// ```rust, no_run #[doc = crate::before_snippet!()] /// # use esp_hal::{mcpwm, prelude::*}; diff --git a/esp-hal/src/prelude.rs b/esp-hal/src/prelude.rs index 32c9a1cd8a5..11ad6b9ae56 100644 --- a/esp-hal/src/prelude.rs +++ b/esp-hal/src/prelude.rs @@ -38,4 +38,4 @@ pub use crate::timer::timg::{ pub use crate::timer::Timer as _esp_hal_timer_Timer; #[cfg(any(uart0, uart1, uart2))] pub use crate::uart::Instance as _esp_hal_uart_Instance; -pub use crate::{entry, macros::*, InterruptConfigurable}; +pub use crate::{clock::CpuClock, entry, macros::*, InterruptConfigurable}; diff --git a/esp-hal/src/rmt.rs b/esp-hal/src/rmt.rs index d3ee8abd2a1..a2efc8eb87a 100644 --- a/esp-hal/src/rmt.rs +++ b/esp-hal/src/rmt.rs @@ -18,24 +18,25 @@ //! the input signal //! //! ### Channels +//! //! There are #![cfg_attr( esp32, - doc = "8 channels, each of them can be either receiver or transmitter" + doc = "8 channels, each of them can be either receiver or transmitter." )] #![cfg_attr( esp32s2, - doc = "4 channels, each of them can be either receiver or transmitter" + doc = "4 channels, each of them can be either receiver or transmitter." )] #![cfg_attr( esp32s3, - doc = "8 channels, `Channel<0>`-`Channel<3>` hardcoded for transmitting signals and `Channel<4>`-`Channel<7>` hardcoded for receiving signals" + doc = "8 channels, `Channel<0>`-`Channel<3>` hardcoded for transmitting signals and `Channel<4>`-`Channel<7>` hardcoded for receiving signals." )] #![cfg_attr( any(esp32c3, esp32c6, esp32h2), doc = "4 channels, `Channel<0>` and `Channel<1>` hardcoded for transmitting signals and `Channel<2>` and `Channel<3>` hardcoded for receiving signals." )] -#![doc = " "] +#![doc = ""] //! For more information, please refer to the #![doc = concat!("[ESP-IDF documentation](https://docs.espressif.com/projects/esp-idf/en/latest/", crate::soc::chip!(), "/api-reference/peripherals/rmt.html)")] //! ## Configuration @@ -44,8 +45,10 @@ //! channels are indicated by n which is used as a placeholder for the channel //! number, and by m for RX channels. //! -//! ## Examples +//! ## Example +//! //! ### Initialization +//! //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::peripherals::Peripherals; @@ -54,7 +57,6 @@ //! # use esp_hal::gpio::Io; //! # use esp_hal::clock::ClockControl; //! # use crate::esp_hal::rmt::TxChannelCreator; -//! # use crate::esp_hal::prelude::_fugit_RateExtU32; //! # 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();")] @@ -76,8 +78,8 @@ //! .unwrap(); //! # } //! ``` -//! (on ESP32 and ESP32-S2 you cannot specify a base frequency other than 80 -//! MHz) +//! +//! > Note: on ESP32 and ESP32-S2 you cannot specify a base frequency other than 80 MHz use core::marker::PhantomData; diff --git a/esp-hal/src/rom/md5.rs b/esp-hal/src/rom/md5.rs index cfae6ebba9c..43b5b7e7e72 100644 --- a/esp-hal/src/rom/md5.rs +++ b/esp-hal/src/rom/md5.rs @@ -55,6 +55,7 @@ //! # let mut uart0 = Uart::new(peripherals.UART0, &clocks, io.pins.gpio1, io.pins.gpio2).unwrap(); //! # let data0 = "Dummy"; //! # let data1 = "Dummy"; +//! # //! let mut ctx = md5::Context::new(); //! ctx.consume(&data0); //! ctx.consume(&data1); diff --git a/esp-hal/src/rtc_cntl/mod.rs b/esp-hal/src/rtc_cntl/mod.rs index cfbf13f0756..c379228c923 100644 --- a/esp-hal/src/rtc_cntl/mod.rs +++ b/esp-hal/src/rtc_cntl/mod.rs @@ -14,11 +14,10 @@ //! * Clock Configuration //! * Calibration //! * Low-Power Management -//! * Real-Time Clock //! * Handling Watchdog Timers //! -//! ## Examples -//! ### Print Time in Milliseconds From the RTC Timer +//! ## Example +//! //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use core::cell::RefCell; @@ -33,28 +32,23 @@ //! let mut delay = Delay::new(&clocks); //! //! let mut rtc = Rtc::new(peripherals.LPWR); +//! //! rtc.set_interrupt_handler(interrupt_handler); //! rtc.rwdt.set_timeout(2000.millis()); //! rtc.rwdt.listen(); //! //! critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); -//! -//! -//! loop {} //! # } //! //! // Where the `LP_WDT` interrupt handler is defined as: -//! // Handle the corresponding interrupt //! # use core::cell::RefCell; //! //! # use critical_section::Mutex; -//! # use esp_hal::prelude::handler; -//! # use esp_hal::interrupt::InterruptHandler; -//! # use esp_hal::interrupt; -//! # use esp_hal::interrupt::Priority; -//! # use crate::esp_hal::prelude::_fugit_ExtU64; //! # use esp_hal::rtc_cntl::Rwdt; +//! //! static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); +//! +//! // Handle the corresponding interrupt //! #[handler] //! fn interrupt_handler() { //! critical_section::with(|cs| { diff --git a/esp-hal/src/soc/esp32/peripherals.rs b/esp-hal/src/soc/esp32/peripherals.rs index fe2be78c2be..ab9b31ce6d1 100644 --- a/esp-hal/src/soc/esp32/peripherals.rs +++ b/esp-hal/src/soc/esp32/peripherals.rs @@ -63,6 +63,7 @@ crate::peripherals! { SPI2 <= SPI2 (SPI2_DMA, SPI2), SPI3 <= SPI3 (SPI3_DMA, SPI3), SYSTEM <= DPORT, + SW_INTERRUPT <= virtual, TIMG0 <= TIMG0, TIMG1 <= TIMG1, TOUCH <= virtual, diff --git a/esp-hal/src/soc/esp32c2/peripherals.rs b/esp-hal/src/soc/esp32c2/peripherals.rs index adf05427afc..3cd86959d96 100644 --- a/esp-hal/src/soc/esp32c2/peripherals.rs +++ b/esp-hal/src/soc/esp32c2/peripherals.rs @@ -43,6 +43,7 @@ crate::peripherals! { SPI2 <= SPI2 (SPI2), SYSTEM <= SYSTEM, SYSTIMER <= SYSTIMER, + SW_INTERRUPT <= virtual, TIMG0 <= TIMG0, UART0 <= UART0, UART1 <= UART1, diff --git a/esp-hal/src/soc/esp32c3/peripherals.rs b/esp-hal/src/soc/esp32c3/peripherals.rs index 4ffd2aa402a..dd5308df0c2 100644 --- a/esp-hal/src/soc/esp32c3/peripherals.rs +++ b/esp-hal/src/soc/esp32c3/peripherals.rs @@ -50,6 +50,7 @@ crate::peripherals! { SPI2 <= SPI2 (SPI2), SYSTEM <= SYSTEM, SYSTIMER <= SYSTIMER, + SW_INTERRUPT <= virtual, TIMG0 <= TIMG0, TIMG1 <= TIMG1, TWAI0 <= TWAI0, diff --git a/esp-hal/src/soc/esp32c6/peripherals.rs b/esp-hal/src/soc/esp32c6/peripherals.rs index 6952cdc0d00..ef74459ed22 100644 --- a/esp-hal/src/soc/esp32c6/peripherals.rs +++ b/esp-hal/src/soc/esp32c6/peripherals.rs @@ -76,6 +76,7 @@ crate::peripherals! { SPI2 <= SPI2 (SPI2), SYSTEM <= PCR, SYSTIMER <= SYSTIMER, + SW_INTERRUPT <= virtual, TEE <= TEE, TIMG0 <= TIMG0, TIMG1 <= TIMG1, diff --git a/esp-hal/src/soc/esp32h2/peripherals.rs b/esp-hal/src/soc/esp32h2/peripherals.rs index 205c1bad47c..7fbda39c981 100644 --- a/esp-hal/src/soc/esp32h2/peripherals.rs +++ b/esp-hal/src/soc/esp32h2/peripherals.rs @@ -68,6 +68,7 @@ crate::peripherals! { SPI2 <= SPI2 (SPI2), SYSTEM <= PCR, SYSTIMER <= SYSTIMER, + SW_INTERRUPT <= virtual, TEE <= TEE, TIMG0 <= TIMG0, TIMG1 <= TIMG1, diff --git a/esp-hal/src/soc/esp32s2/peripherals.rs b/esp-hal/src/soc/esp32s2/peripherals.rs index 7ed7c128248..31d989cf28f 100644 --- a/esp-hal/src/soc/esp32s2/peripherals.rs +++ b/esp-hal/src/soc/esp32s2/peripherals.rs @@ -58,6 +58,7 @@ crate::peripherals! { SYSCON <= SYSCON, SYSTEM <= SYSTEM, SYSTIMER <= SYSTIMER, + SW_INTERRUPT <= virtual, TIMG0 <= TIMG0, TIMG1 <= TIMG1, TWAI0 <= TWAI0, diff --git a/esp-hal/src/soc/esp32s2/ulp_core.rs b/esp-hal/src/soc/esp32s2/ulp_core.rs index 579317b2a8f..6515635347a 100644 --- a/esp-hal/src/soc/esp32s2/ulp_core.rs +++ b/esp-hal/src/soc/esp32s2/ulp_core.rs @@ -17,17 +17,21 @@ #![doc = crate::before_snippet!()] //! const CODE: &[u8] = &[ //! 0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0x05, 0x01, 0x81, 0x45, 0x85, 0x05, -//! 0x0c, 0xc1, 0xf5, 0xbf, 0x00, 0x00, 0x00, 0x00, -//! ]; +//! 0x0c, 0xc1, 0xf5, 0xbf, 0x00, 0x00, 0x00, 0x00, +//! ]; //! let mut ulp_core = -//! esp_hal::ulp_core::UlpCore::new(peripherals.ULP_RISCV_CORE); +//! esp_hal::ulp_core::UlpCore::new(peripherals.ULP_RISCV_CORE); //! // ulp_core.stop(); currently not implemented //! //! // copy code to RTC ram //! let lp_ram = 0x5000_0000 as *mut u8; //! unsafe { -//! core::ptr::copy_nonoverlapping(CODE as *const _ as *const u8, lp_ram, -//! CODE.len()); } +//! core::ptr::copy_nonoverlapping( +//! CODE as *const _ as *const u8, +//! lp_ram, +//! CODE.len(), +//! ); +//! } //! //! // start ULP core //! ulp_core.run(esp_hal::ulp_core::UlpCoreWakeupSource::HpCpu); diff --git a/esp-hal/src/soc/esp32s3/cpu_control.rs b/esp-hal/src/soc/esp32s3/cpu_control.rs index 403ddd98887..be5b2ae03f0 100644 --- a/esp-hal/src/soc/esp32s3/cpu_control.rs +++ b/esp-hal/src/soc/esp32s3/cpu_control.rs @@ -13,10 +13,8 @@ //! # use esp_hal::cpu_control::{CpuControl, Stack}; //! # use core::{cell::RefCell, ptr::addr_of_mut}; //! # use critical_section::Mutex; -//! # use esp_hal::prelude::*; -//! static mut APP_CORE_STACK: Stack<8192> = Stack::new(); -//! //! # let delay = Delay::new(&clocks); +//! static mut APP_CORE_STACK: Stack<8192> = Stack::new(); //! //! let counter = Mutex::new(RefCell::new(0)); //! @@ -25,8 +23,10 @@ //! cpu1_task(&delay, &counter); //! }; //! let _guard = cpu_control -//! .start_app_core(unsafe { &mut *addr_of_mut!(APP_CORE_STACK) }, -//! cpu1_fnctn) .unwrap(); +//! .start_app_core( +//! unsafe { &mut *addr_of_mut!(APP_CORE_STACK) }, +//! cpu1_fnctn, +//! ).unwrap(); //! //! loop { //! delay.delay(1.secs()); @@ -37,7 +37,7 @@ //! // Where `cpu1_task()` may be defined as: //! # use esp_hal::delay::Delay; //! # use core::cell::RefCell; -//! # use esp_hal::prelude::*; +//! //! fn cpu1_task( //! delay: &Delay, //! counter: &critical_section::Mutex>, diff --git a/esp-hal/src/soc/esp32s3/peripherals.rs b/esp-hal/src/soc/esp32s3/peripherals.rs index 8671a1e516c..9e0592abf52 100644 --- a/esp-hal/src/soc/esp32s3/peripherals.rs +++ b/esp-hal/src/soc/esp32s3/peripherals.rs @@ -63,6 +63,7 @@ crate::peripherals! { SPI3 <= SPI3 (SPI3), SYSTEM <= SYSTEM, SYSTIMER <= SYSTIMER, + SW_INTERRUPT <= virtual, TIMG0 <= TIMG0, TIMG1 <= TIMG1, TWAI0 <= TWAI0, diff --git a/esp-hal/src/soc/esp32s3/ulp_core.rs b/esp-hal/src/soc/esp32s3/ulp_core.rs index 865387bcb15..deae3f75a92 100644 --- a/esp-hal/src/soc/esp32s3/ulp_core.rs +++ b/esp-hal/src/soc/esp32s3/ulp_core.rs @@ -1,6 +1,7 @@ //! Control the ULP core //! //! ## Overview +//! //! The `ULP CORE` peripheral allows control over the `Ultra-Low Power //! (ULP) core` in `ESP` chips. The ULP core is a low-power processor //! designed for executing tasks in deep sleep mode, enabling efficient power @@ -11,22 +12,28 @@ //! operation. The `UlpCore` struct is initialized with a peripheral reference //! to the `ULP CORE` instance. //! -//! ## Examples +//! ## Example +//! //! ```rust, no_run #![doc = crate::before_snippet!()] //! const CODE: &[u8] = &[ //! 0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0x05, 0x01, 0x81, 0x45, 0x85, 0x05, -//! 0x0c, 0xc1, 0xf5, 0xbf, 0x00, 0x00, 0x00, 0x00, -//! ]; +//! 0x0c, 0xc1, 0xf5, 0xbf, 0x00, 0x00, 0x00, 0x00, +//! ]; +//! //! let mut ulp_core = -//! esp_hal::ulp_core::UlpCore::new(peripherals.ULP_RISCV_CORE); +//! esp_hal::ulp_core::UlpCore::new(peripherals.ULP_RISCV_CORE); //! ulp_core.stop(); //! //! // copy code to RTC ram //! let lp_ram = 0x5000_0000 as *mut u8; //! unsafe { -//! core::ptr::copy_nonoverlapping(CODE as *const _ as *const u8, lp_ram, -//! CODE.len()); } +//! core::ptr::copy_nonoverlapping( +//! CODE as *const _ as *const u8, +//! lp_ram, +//! CODE.len(), +//! ); +//! } //! //! // start ULP core //! ulp_core.run(esp_hal::ulp_core::UlpCoreWakeupSource::HpCpu); diff --git a/esp-hal/src/spi/master.rs b/esp-hal/src/spi/master.rs index b65b28d805c..ebd086f79c7 100644 --- a/esp-hal/src/spi/master.rs +++ b/esp-hal/src/spi/master.rs @@ -38,7 +38,6 @@ //! ### SPI Initialization //! ```rust, no_run #![doc = crate::before_snippet!()] -//! # use crate::esp_hal::prelude::_fugit_RateExtU32; //! # use esp_hal::spi::SpiMode; //! # use esp_hal::spi::master::Spi; //! # use esp_hal::gpio::Io; @@ -52,7 +51,7 @@ //! peripherals.SPI2, //! 100.kHz(), //! SpiMode::Mode0, -//! &mut clocks, +//! &clocks, //! ) //! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)); //! # } diff --git a/esp-hal/src/spi/slave.rs b/esp-hal/src/spi/slave.rs index 52491f57fdb..52c3b2eabac 100644 --- a/esp-hal/src/spi/slave.rs +++ b/esp-hal/src/spi/slave.rs @@ -48,8 +48,8 @@ //! let mut receive = rx_buffer; //! //! let transfer = spi -//! .dma_transfer(&mut send, &mut receive) -//! .unwrap(); +//! .dma_transfer(&mut send, &mut receive) +//! .unwrap(); //! //! transfer.wait().unwrap(); //! # } diff --git a/esp-hal/src/system.rs b/esp-hal/src/system.rs index 1c31a0e611b..4b031e91c17 100755 --- a/esp-hal/src/system.rs +++ b/esp-hal/src/system.rs @@ -1,46 +1,20 @@ //! # System Control //! //! ## Overview -//! This `system` driver provides an interface to control and configure various -//! system-related features and peripherals on ESP chips. It includes -//! functionality to control peripheral clocks, manage software interrupts, -//! configure chip clocks, and control radio peripherals. //! -//! ### Software Interrupts -//! The `SoftwareInterruptControl` struct gives access to the available software -//! interrupts. -//! -//! The `SoftwareInterrupt` struct allows raising or resetting software -//! interrupts using the `raise()` and `reset()` methods. -//! -//! ### Peripheral Clock Control -//! The `PeripheralClockControl` struct controls the enablement of peripheral -//! clocks. -//! -//! It provides an `enable()` method to enable and reset specific peripherals. -//! The available peripherals are represented by the `Peripheral` enum -//! -//! ## Examples -//! ```rust, no_run -#![doc = crate::before_snippet!()] -//! let peripherals = Peripherals::take(); -//! let system = SystemControl::new(peripherals.SYSTEM); -//! let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); -//! # } -//! ``` +//! This `system` module defines the available radio peripherals and provides an +//! interface to control and configure radio clocks. -use crate::{ - interrupt::InterruptHandler, - peripheral::PeripheralRef, - peripherals::SYSTEM, - InterruptConfigurable, -}; +use crate::peripherals::SYSTEM; /// Peripherals which can be enabled via `PeripheralClockControl`. /// /// This enum represents various hardware peripherals that can be enabled /// by the system's clock control. Depending on the target device, different /// peripherals will be available for enabling. +// FIXME: This enum needs to be public because it's exposed via a bunch of traits, but it's not +// useful to users. +#[doc(hidden)] pub enum Peripheral { /// SPI2 peripheral. #[cfg(spi2)] @@ -146,183 +120,6 @@ pub enum Peripheral { Systimer, } -/// The `DPORT`/`PCR`/`SYSTEM` peripheral split into its different logical -/// components. -pub struct SystemControl<'d> { - /// Inner reference to the SYSTEM peripheral. - _inner: PeripheralRef<'d, SYSTEM>, - /// Controls the system's clock settings and configurations. - pub clock_control: SystemClockControl, - /// Controls the system's software interrupt settings. - pub software_interrupt_control: SoftwareInterruptControl, -} - -impl<'d> SystemControl<'d> { - /// Construct a new instance of [`SystemControl`]. - pub fn new(system: impl crate::peripheral::Peripheral

+ 'd) -> Self { - crate::into_ref!(system); - - Self { - _inner: system, - clock_control: SystemClockControl::new(), - software_interrupt_control: SoftwareInterruptControl::new(), - } - } -} - -/// A software interrupt can be triggered by software. -#[non_exhaustive] -pub struct SoftwareInterrupt; - -impl SoftwareInterrupt { - /// Sets the interrupt handler for this software-interrupt - pub fn set_interrupt_handler(&mut self, handler: InterruptHandler) { - let interrupt = match NUM { - 0 => crate::peripherals::Interrupt::FROM_CPU_INTR0, - 1 => crate::peripherals::Interrupt::FROM_CPU_INTR1, - 2 => crate::peripherals::Interrupt::FROM_CPU_INTR2, - 3 => crate::peripherals::Interrupt::FROM_CPU_INTR3, - _ => unreachable!(), - }; - - unsafe { - crate::interrupt::bind_interrupt(interrupt, handler.handler()); - crate::interrupt::enable(interrupt, handler.priority()).unwrap(); - } - } - - /// Trigger this software-interrupt - pub fn raise(&self) { - #[cfg(not(any(esp32c6, esp32h2)))] - let system = unsafe { &*SYSTEM::PTR }; - #[cfg(any(esp32c6, esp32h2))] - let system = unsafe { &*crate::peripherals::INTPRI::PTR }; - - match NUM { - 0 => { - system - .cpu_intr_from_cpu_0() - .write(|w| w.cpu_intr_from_cpu_0().set_bit()); - } - 1 => { - system - .cpu_intr_from_cpu_1() - .write(|w| w.cpu_intr_from_cpu_1().set_bit()); - } - 2 => { - system - .cpu_intr_from_cpu_2() - .write(|w| w.cpu_intr_from_cpu_2().set_bit()); - } - 3 => { - system - .cpu_intr_from_cpu_3() - .write(|w| w.cpu_intr_from_cpu_3().set_bit()); - } - _ => unreachable!(), - } - } - - /// Resets this software-interrupt - pub fn reset(&self) { - #[cfg(not(any(esp32c6, esp32h2)))] - let system = unsafe { &*SYSTEM::PTR }; - #[cfg(any(esp32c6, esp32h2))] - let system = unsafe { &*crate::peripherals::INTPRI::PTR }; - - match NUM { - 0 => { - system - .cpu_intr_from_cpu_0() - .write(|w| w.cpu_intr_from_cpu_0().clear_bit()); - } - 1 => { - system - .cpu_intr_from_cpu_1() - .write(|w| w.cpu_intr_from_cpu_1().clear_bit()); - } - 2 => { - system - .cpu_intr_from_cpu_2() - .write(|w| w.cpu_intr_from_cpu_2().clear_bit()); - } - 3 => { - system - .cpu_intr_from_cpu_3() - .write(|w| w.cpu_intr_from_cpu_3().clear_bit()); - } - _ => unreachable!(), - } - } - - /// Unsafely create an instance of this peripheral out of thin air. - /// - /// # Safety - /// - /// You must ensure that you're only using one instance of this type at a - /// time. - #[inline] - pub unsafe fn steal() -> Self { - Self - } -} - -impl crate::peripheral::Peripheral for SoftwareInterrupt { - type P = SoftwareInterrupt; - - #[inline] - unsafe fn clone_unchecked(&mut self) -> Self::P { - Self::steal() - } -} - -impl crate::private::Sealed for SoftwareInterrupt {} - -impl InterruptConfigurable for SoftwareInterrupt { - fn set_interrupt_handler(&mut self, handler: crate::interrupt::InterruptHandler) { - SoftwareInterrupt::set_interrupt_handler(self, handler); - } -} - -/// This gives access to the available software interrupts. -/// -/// This struct contains several instances of software interrupts that can be -/// used for signaling between different parts of a program or system. Each -/// interrupt is identified by an index (0 to 3). -#[cfg_attr( - multi_core, - doc = r#" - -Please note: Software interrupt 3 is reserved -for inter-processor communication when using -`esp-hal-embassy`."# -)] -#[non_exhaustive] -pub struct SoftwareInterruptControl { - /// Software interrupt 0. - pub software_interrupt0: SoftwareInterrupt<0>, - /// Software interrupt 1. - pub software_interrupt1: SoftwareInterrupt<1>, - /// Software interrupt 2. - pub software_interrupt2: SoftwareInterrupt<2>, - #[cfg(not(all(feature = "__esp_hal_embassy", multi_core)))] - /// Software interrupt 3. Only available when not using `esp-hal-embassy`, - /// or on single-core systems. - pub software_interrupt3: SoftwareInterrupt<3>, -} - -impl SoftwareInterruptControl { - fn new() -> Self { - SoftwareInterruptControl { - software_interrupt0: SoftwareInterrupt {}, - software_interrupt1: SoftwareInterrupt {}, - software_interrupt2: SoftwareInterrupt {}, - #[cfg(not(all(feature = "__esp_hal_embassy", multi_core)))] - software_interrupt3: SoftwareInterrupt {}, - } - } -} - /// Controls the enablement of peripheral clocks. pub(crate) struct PeripheralClockControl; @@ -1187,35 +984,6 @@ impl PeripheralClockControl { } } -/// Controls the configuration of the chip's clocks. -pub struct SystemClockControl { - _private: (), -} - -impl SystemClockControl { - /// Creates new instance of `SystemClockControl`. - pub fn new() -> Self { - Self { _private: () } - } -} - -impl Default for SystemClockControl { - fn default() -> Self { - Self::new() - } -} - -impl crate::peripheral::Peripheral for SystemClockControl { - type P = SystemClockControl; - - #[inline] - unsafe fn clone_unchecked(&mut self) -> Self::P { - SystemClockControl { _private: () } - } -} - -impl crate::private::Sealed for SystemClockControl {} - /// Enumeration of the available radio peripherals for this chip. #[cfg(any(bt, ieee802154, wifi))] pub enum RadioPeripherals { diff --git a/esp-hal/src/time.rs b/esp-hal/src/time.rs index 24fe8aff314..82aefad3cd7 100644 --- a/esp-hal/src/time.rs +++ b/esp-hal/src/time.rs @@ -1,17 +1,8 @@ //! # Time //! -//! ## Overview //! The `time` module offers a way to get the system uptime. -//! -//! ## Examples -//! ```rust, no_run -#![doc = crate::before_snippet!()] -//! # use esp_hal::time; -//! let time = time::current_time(); -//! # } -//! ``` -/// Provides time since system start in microseconds precision +/// Provides time since system start in microseconds precision. /// /// The counter won’t measure time in sleep-mode. /// diff --git a/esp-hal/src/timer/mod.rs b/esp-hal/src/timer/mod.rs index 313772472ad..2e2552684a5 100644 --- a/esp-hal/src/timer/mod.rs +++ b/esp-hal/src/timer/mod.rs @@ -17,7 +17,7 @@ //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::timer::{OneShotTimer, PeriodicTimer, timg::TimerGroup}; -//! # use esp_hal::prelude::*; +//! # //! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); //! let one_shot = OneShotTimer::new(timg0.timer0); //! @@ -29,7 +29,7 @@ //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::timer::{PeriodicTimer, timg::TimerGroup}; -//! # use esp_hal::prelude::*; +//! # //! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); //! let mut periodic = PeriodicTimer::new(timg0.timer0); //! diff --git a/esp-hal/src/timer/systimer.rs b/esp-hal/src/timer/systimer.rs index 21013044343..537bdd6d3b3 100644 --- a/esp-hal/src/timer/systimer.rs +++ b/esp-hal/src/timer/systimer.rs @@ -15,58 +15,57 @@ //! [Alarm]s can be configured in two modes: [Target] (one-shot) and [Periodic]. //! //! ## Examples -//! ### General-purpose Timer -//! ```rust, no_run -#![doc = crate::before_snippet!()] -//! # use esp_hal::timer::systimer::SystemTimer; -//! # use esp_hal::timer::timg::TimerGroup; -//! # use crate::esp_hal::prelude::_esp_hal_timer_Timer; -//! # use esp_hal::prelude::*; -//! let systimer = SystemTimer::new(peripherals.SYSTIMER); //! -//! // Get the current timestamp, in microseconds: -//! let now = SystemTimer::now(); +//! ### Splitting up the System Timer into three alarms //! -//! let timg0 = TimerGroup::new( -//! peripherals.TIMG0, -//! &clocks, -//! ); +//! Use the [split][SystemTimer::split] method to create three alarms from the +//! System Timer, contained in a [SysTimerAlarms] struct. //! -//! let mut timer0 = timg0.timer0; -//! timer0.set_interrupt_handler(tg0_t0_level); +//! ```rust, no_run +#![doc = crate::before_snippet!()] +//! use esp_hal::timer::systimer::{ +//! SystemTimer, +//! Periodic, +//! }; //! -//! // Wait for timeout: -//! timer0.load_value(1.secs()); -//! timer0.start(); +//! let systimer = SystemTimer::new( +//! peripherals.SYSTIMER, +//! ).split::(); //! -//! while !timer0.is_interrupt_set() { -//! // Wait -//! } +//! // Reconfigure a periodic alarm to be a target alarm +//! let target_alarm = systimer.alarm0.into_target(); //! # } +//! ``` +//! +//! ### General-purpose Timer +//! ```rust, no_run +#![doc = crate::before_snippet!()] +//! use esp_hal::timer::systimer::{ +//! Alarm, +//! FrozenUnit, +//! SpecificUnit, +//! SystemTimer, +//! }; //! +//! let mut systimer = SystemTimer::new(peripherals.SYSTIMER); //! -//! # use core::cell::RefCell; -//! # use critical_section::Mutex; -//! # use procmacros::handler; -//! # use esp_hal::interrupt::InterruptHandler; -//! # use esp_hal::interrupt; -//! # use esp_hal::peripherals::TIMG0; -//! # use esp_hal::timer::timg::{Timer, Timer0}; -//! # use crate::esp_hal::prelude::_esp_hal_timer_Timer; -//! # static TIMER0: Mutex, esp_hal::Blocking>>>> = Mutex::new(RefCell::new(None)); -//! #[handler] -//! fn tg0_t0_level() { -//! critical_section::with(|cs| { -//! let mut timer0 = TIMER0.borrow_ref_mut(cs); -//! let timer0 = timer0.as_mut().unwrap(); +//! // Get the current timestamp, in microseconds: +//! let now = SystemTimer::now(); //! -//! timer0.clear_interrupt(); +//! let frozen_unit = FrozenUnit::new(&mut systimer.unit0); +//! let alarm0 = Alarm::new(systimer.comparator0, &frozen_unit); //! -//! // Counter value should be a very small number as the alarm triggered a -//! // counter reload to 0 and ETM stopped the counter quickly after -//! // esp_println::println!("counter in interrupt: {}", timer0.now()); -//! }); +//! alarm0.set_target( +//! SystemTimer::now() + SystemTimer::ticks_per_second() * 2 +//! ); +//! alarm0.enable_interrupt(true); +//! +//! while !alarm0.is_interrupt_set() { +//! // Wait for the interrupt to be set //! } +//! +//! alarm0.clear_interrupt(); +//! # } //! ``` use core::{ diff --git a/esp-hal/src/timer/timg.rs b/esp-hal/src/timer/timg.rs index 6b73e1e247d..074252ebbe1 100644 --- a/esp-hal/src/timer/timg.rs +++ b/esp-hal/src/timer/timg.rs @@ -27,8 +27,7 @@ //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::timer::timg::TimerGroup; -//! # use crate::esp_hal::prelude::_esp_hal_timer_Timer; -//! # use esp_hal::prelude::*; +//! //! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); //! let timer0 = timg0.timer0; //! @@ -42,6 +41,8 @@ //! while !timer0.is_interrupt_set() { //! // Wait //! } +//! +//! timer0.clear_interrupt(); //! # } //! ``` //! @@ -49,7 +50,7 @@ //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::timer::timg::TimerGroup; -//! # use esp_hal::prelude::*; +//! //! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); //! let mut wdt = timg0.wdt; //! diff --git a/esp-hal/src/uart.rs b/esp-hal/src/uart.rs index c06aa380e15..62e49a474e1 100644 --- a/esp-hal/src/uart.rs +++ b/esp-hal/src/uart.rs @@ -1,6 +1,7 @@ //! # Universal Asynchronous Receiver/Transmitter (UART) //! //! ## Overview +//! //! The UART is a hardware peripheral which handles communication using serial //! communication interfaces, such as RS232 and RS485. This peripheral provides //! a cheap and ubiquitous method for full- and half-duplex communication @@ -13,6 +14,7 @@ //! protocols. //! //! ## Configuration +//! //! Each UART controller is individually configurable, and the usual setting //! such as baud rate, data bits, parity, and stop bits can easily be //! configured. Additionally, the transmit (TX) and receive (RX) pins need to @@ -20,20 +22,26 @@ //! //! ```rust, no_run #![doc = crate::before_snippet!()] -//! # use esp_hal::uart::{config::Config, Uart}; +//! # use esp_hal::uart::Uart; //! use esp_hal::gpio::Io; +//! //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! -//! let mut uart1 = Uart::new(peripherals.UART1, &clocks, io.pins.gpio1, -//! io.pins.gpio2).unwrap(); +//! let mut uart1 = Uart::new( +//! peripherals.UART1, +//! &clocks, +//! io.pins.gpio1, +//! io.pins.gpio2, +//! ).unwrap(); //! # } //! ``` //! //! The UART controller can be configured to invert the polarity of the pins. -//! This is achived by inverting the desired pins, and then constructing the +//! This is achieved by inverting the desired pins, and then constructing the //! UART instance using the inverted pins. //! //! ## Usage +//! //! The UART driver implements a number of third-party traits, with the //! intention of making the HAL inter-compatible with various device drivers //! from the community. This includes, but is not limited to, the [embedded-hal] @@ -49,7 +57,7 @@ //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::uart::{config::Config, Uart}; -//! use esp_hal::gpio::Io; +//! # use esp_hal::gpio::Io; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let mut uart1 = Uart::new_with_config( //! # peripherals.UART1, @@ -67,7 +75,7 @@ //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::uart::{config::Config, Uart}; -//! use esp_hal::gpio::Io; +//! # use esp_hal::gpio::Io; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let mut uart1 = Uart::new_with_config( //! # peripherals.UART1, @@ -88,21 +96,28 @@ //! ### Inverting TX and RX Pins //! ```rust, no_run #![doc = crate::before_snippet!()] -//! # use esp_hal::uart::{config::Config, Uart}; +//! # use esp_hal::uart::Uart; //! use esp_hal::gpio::{AnyPin, Io}; +//! //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! //! let tx = AnyPin::new_inverted(io.pins.gpio1); //! let rx = AnyPin::new_inverted(io.pins.gpio2); -//! let mut uart1 = Uart::new(peripherals.UART1, &clocks, tx, rx).unwrap(); +//! let mut uart1 = Uart::new( +//! peripherals.UART1, +//! &clocks, +//! tx, +//! rx, +//! ).unwrap(); //! # } //! ``` //! //! ### Constructing TX and RX Components //! ```rust, no_run #![doc = crate::before_snippet!()] -//! # use esp_hal::uart::{config::Config, UartTx, UartRx}; +//! # use esp_hal::uart::{UartTx, UartRx}; //! use esp_hal::gpio::{AnyPin, Io}; +//! //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! //! let tx = UartTx::new(peripherals.UART0, &clocks, @@ -167,7 +182,7 @@ cfg_if::cfg_if! { /// Default RX pin for UART0 on ESP32-C3. /// Corresponds to GPIO20. pub type DefaultRxPin = crate::gpio::Gpio20; - }else if #[cfg(esp32c6)] { + } else if #[cfg(esp32c6)] { /// Default TX pin for UART0 on ESP32-C6. /// Corresponds to GPIO16. pub type DefaultTxPin = crate::gpio::Gpio16; @@ -175,7 +190,7 @@ cfg_if::cfg_if! { /// Default RX pin for UART0 on ESP32-C6. /// Corresponds to GPIO17. pub type DefaultRxPin = crate::gpio::Gpio17; - }else if #[cfg(esp32h2)] { + } else if #[cfg(esp32h2)] { /// Default TX pin for UART0 on ESP32-H2. /// Corresponds to GPIO24. pub type DefaultTxPin = crate::gpio::Gpio24; diff --git a/esp-hal/src/usb_serial_jtag.rs b/esp-hal/src/usb_serial_jtag.rs index 9de1122fd15..5e70c0b1199 100644 --- a/esp-hal/src/usb_serial_jtag.rs +++ b/esp-hal/src/usb_serial_jtag.rs @@ -45,17 +45,19 @@ //! ```rust, no_run #![doc = crate::before_snippet!()] //! use esp_hal::usb_serial_jtag::UsbSerialJtag; +//! //! let mut usb_serial = UsbSerialJtag::new(peripherals.USB_DEVICE); //! //! // Write bytes out over the USB Serial/JTAG: //! usb_serial.write_bytes(b"Hello, world!").expect("write error!"); -//! } +//! # } //! ``` //! //! ### Splitting the USB Serial/JTAG into TX and RX Components //! ```rust, no_run #![doc = crate::before_snippet!()] -//! # use esp_hal::usb_serial_jtag::UsbSerialJtag; +//! use esp_hal::usb_serial_jtag::UsbSerialJtag; +//! //! let mut usb_serial = UsbSerialJtag::new(peripherals.USB_DEVICE); //! // The USB Serial/JTAG can be split into separate Transmit and Receive //! // components: diff --git a/examples/src/bin/adc.rs b/examples/src/bin/adc.rs index 00d528c17ba..1c9413e2c26 100644 --- a/examples/src/bin/adc.rs +++ b/examples/src/bin/adc.rs @@ -19,20 +19,15 @@ use esp_backtrace as _; use esp_hal::{ analog::adc::{Adc, AdcConfig, Attenuation}, - clock::ClockControl, delay::Delay, gpio::Io, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); cfg_if::cfg_if! { diff --git a/examples/src/bin/adc_cal.rs b/examples/src/bin/adc_cal.rs index 8b8689e1128..1466e01cc46 100644 --- a/examples/src/bin/adc_cal.rs +++ b/examples/src/bin/adc_cal.rs @@ -15,20 +15,15 @@ use esp_backtrace as _; use esp_hal::{ analog::adc::{Adc, AdcConfig, Attenuation}, - clock::ClockControl, delay::Delay, gpio::Io, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); cfg_if::cfg_if! { diff --git a/examples/src/bin/advanced_serial.rs b/examples/src/bin/advanced_serial.rs index 12b4d455151..b4a3760189f 100644 --- a/examples/src/bin/advanced_serial.rs +++ b/examples/src/bin/advanced_serial.rs @@ -13,23 +13,13 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - delay::Delay, - gpio::Io, - peripherals::Peripherals, - prelude::*, - system::SystemControl, - uart::Uart, -}; +use esp_hal::{delay::Delay, gpio::Io, prelude::*, uart::Uart}; use esp_println::println; use nb::block; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/blinky.rs b/examples/src/bin/blinky.rs index 4509656832f..114854599eb 100644 --- a/examples/src/bin/blinky.rs +++ b/examples/src/bin/blinky.rs @@ -10,19 +10,14 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, gpio::{Io, Level, Output}, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); // Set GPIO0 as an output, and set its state high initially. let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/blinky_erased_pins.rs b/examples/src/bin/blinky_erased_pins.rs index d5c6519e065..65204583333 100644 --- a/examples/src/bin/blinky_erased_pins.rs +++ b/examples/src/bin/blinky_erased_pins.rs @@ -13,19 +13,14 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, gpio::{AnyInput, AnyOutput, Io, Level, Pull}, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/dac.rs b/examples/src/bin/dac.rs index 7ad9c00226a..825600c09a5 100644 --- a/examples/src/bin/dac.rs +++ b/examples/src/bin/dac.rs @@ -19,21 +19,11 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{ - analog::dac::Dac, - clock::ClockControl, - delay::Delay, - gpio::Io, - peripherals::Peripherals, - prelude::*, - system::SystemControl, -}; +use esp_hal::{analog::dac::Dac, delay::Delay, gpio::Io, prelude::*}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/debug_assist.rs b/examples/src/bin/debug_assist.rs index 37a236c2287..3a39b30cb7e 100644 --- a/examples/src/bin/debug_assist.rs +++ b/examples/src/bin/debug_assist.rs @@ -11,22 +11,14 @@ use core::cell::RefCell; use critical_section::Mutex; use esp_backtrace as _; -use esp_hal::{ - assist_debug::DebugAssist, - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - system::SystemControl, -}; +use esp_hal::{assist_debug::DebugAssist, prelude::*}; use esp_println::println; static DA: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let mut da = DebugAssist::new(peripherals.ASSIST_DEBUG); da.set_interrupt_handler(interrupt_handler); diff --git a/examples/src/bin/dma_extmem2mem.rs b/examples/src/bin/dma_extmem2mem.rs index 63360a776cf..fcc4832b93a 100644 --- a/examples/src/bin/dma_extmem2mem.rs +++ b/examples/src/bin/dma_extmem2mem.rs @@ -9,13 +9,10 @@ use aligned::{Aligned, A64}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, dma::{Dma, DmaPriority, Mem2Mem}, dma_descriptors_chunk_size, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; use log::{error, info}; extern crate alloc; @@ -65,10 +62,9 @@ fn init_heap(psram: impl esp_hal::peripheral::Peripheral

! { esp_println::logger::init_logger(log::LevelFilter::Info); - let peripherals = Peripherals::take(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + init_heap(peripherals.PSRAM); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let delay = Delay::new(&clocks); let mut extram_buffer: &mut [u8] = dma_alloc_buffer!(DATA_SIZE, 64); diff --git a/examples/src/bin/dma_mem2mem.rs b/examples/src/bin/dma_mem2mem.rs index 6374d03c7bb..39f7a02f434 100644 --- a/examples/src/bin/dma_mem2mem.rs +++ b/examples/src/bin/dma_mem2mem.rs @@ -8,13 +8,10 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, dma::{Dma, DmaPriority, Mem2Mem}, dma_buffers, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; use log::{error, info}; @@ -24,9 +21,8 @@ const DATA_SIZE: usize = 1024 * 10; fn main() -> ! { esp_println::logger::init_logger(log::LevelFilter::Info); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let delay = Delay::new(&clocks); 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 9f289cb230a..9b47ccf416c 100644 --- a/examples/src/bin/embassy_hello_world.rs +++ b/examples/src/bin/embassy_hello_world.rs @@ -12,12 +12,7 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::timer::timg::TimerGroup; #[embassy_executor::task] async fn run() { @@ -30,11 +25,9 @@ async fn run() { #[esp_hal_embassy::main] async fn main(spawner: Spawner) { esp_println::logger::init_logger_from_env(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_i2c.rs b/examples/src/bin/embassy_i2c.rs index 9ef50be70d6..995c99942ad 100644 --- a/examples/src/bin/embassy_i2c.rs +++ b/examples/src/bin/embassy_i2c.rs @@ -19,22 +19,12 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - gpio::Io, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{gpio::Io, i2c::I2C, prelude::*, timer::timg::TimerGroup}; use lis3dh_async::{Lis3dh, Range, SlaveAddr}; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs b/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs index 1e4482f101d..2ba39581c2d 100644 --- a/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs +++ b/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs @@ -20,21 +20,11 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - gpio::Io, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{gpio::Io, i2c::I2C, prelude::*, timer::timg::TimerGroup}; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_i2s_read.rs b/examples/src/bin/embassy_i2s_read.rs index edffeec2885..24324c64661 100644 --- a/examples/src/bin/embassy_i2s_read.rs +++ b/examples/src/bin/embassy_i2s_read.rs @@ -20,14 +20,11 @@ use embassy_executor::Spawner; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, gpio::Io, i2s::{asynch::*, DataFormat, I2s, Standard}, - peripherals::Peripherals, prelude::*, - system::SystemControl, timer::timg::TimerGroup, }; use esp_println::println; @@ -35,9 +32,7 @@ use esp_println::println; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_i2s_sound.rs b/examples/src/bin/embassy_i2s_sound.rs index bc136a6d6b2..1a5a0a76b02 100644 --- a/examples/src/bin/embassy_i2s_sound.rs +++ b/examples/src/bin/embassy_i2s_sound.rs @@ -34,14 +34,11 @@ use embassy_executor::Spawner; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, gpio::Io, i2s::{asynch::*, DataFormat, I2s, Standard}, - peripherals::Peripherals, prelude::*, - system::SystemControl, timer::timg::TimerGroup, }; use esp_println::println; @@ -57,9 +54,7 @@ const SINE: [i16; 64] = [ #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_multicore.rs b/examples/src/bin/embassy_multicore.rs index 6a150409763..872d0846e3d 100644 --- a/examples/src/bin/embassy_multicore.rs +++ b/examples/src/bin/embassy_multicore.rs @@ -19,12 +19,9 @@ use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, signal::Signal} use embassy_time::{Duration, Ticker}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, cpu_control::{CpuControl, Stack}, get_core, gpio::{AnyOutput, Io, Level}, - peripherals::Peripherals, - system::SystemControl, timer::{timg::TimerGroup, ErasedTimer}, }; use esp_hal_embassy::Executor; @@ -54,9 +51,7 @@ async fn control_led( #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_multicore_interrupt.rs b/examples/src/bin/embassy_multicore_interrupt.rs index 523ed18b522..48c72e8e894 100644 --- a/examples/src/bin/embassy_multicore_interrupt.rs +++ b/examples/src/bin/embassy_multicore_interrupt.rs @@ -18,14 +18,11 @@ use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, signal::Signal} use embassy_time::{Duration, Ticker}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, cpu_control::{CpuControl, Stack}, get_core, gpio::{AnyOutput, Io, Level}, - interrupt::Priority, - peripherals::Peripherals, + interrupt::{software::SoftwareInterruptControl, Priority}, prelude::*, - system::SystemControl, timer::{timg::TimerGroup, ErasedTimer}, }; use esp_hal_embassy::InterruptExecutor; @@ -74,9 +71,9 @@ async fn enable_disable_led(control: &'static Signal ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + + let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -93,8 +90,7 @@ fn main() -> ! { let led = AnyOutput::new(io.pins.gpio0, Level::Low); static EXECUTOR_CORE_1: StaticCell> = StaticCell::new(); - let executor_core1 = - InterruptExecutor::new(system.software_interrupt_control.software_interrupt1); + let executor_core1 = InterruptExecutor::new(sw_ints.software_interrupt1); let executor_core1 = EXECUTOR_CORE_1.init(executor_core1); let _guard = cpu_control @@ -109,8 +105,7 @@ fn main() -> ! { .unwrap(); static EXECUTOR_CORE_0: StaticCell> = StaticCell::new(); - let executor_core0 = - InterruptExecutor::new(system.software_interrupt_control.software_interrupt0); + let executor_core0 = InterruptExecutor::new(sw_ints.software_interrupt0); let executor_core0 = EXECUTOR_CORE_0.init(executor_core0); let spawner = executor_core0.start(Priority::Priority1); diff --git a/examples/src/bin/embassy_multiprio.rs b/examples/src/bin/embassy_multiprio.rs index e3802a5d8ac..d6f52df36d2 100644 --- a/examples/src/bin/embassy_multiprio.rs +++ b/examples/src/bin/embassy_multiprio.rs @@ -24,10 +24,7 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Instant, Ticker, Timer}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, - interrupt::Priority, - peripherals::Peripherals, - system::SystemControl, + interrupt::{software::SoftwareInterruptControl, Priority}, timer::{timg::TimerGroup, ErasedTimer}, }; use esp_hal_embassy::InterruptExecutor; @@ -73,9 +70,10 @@ async fn low_prio_async() { async fn main(low_prio_spawner: Spawner) { esp_println::logger::init_logger_from_env(); println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + + let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timer0: ErasedTimer = timg0.timer0.into(); @@ -94,7 +92,7 @@ async fn main(low_prio_spawner: Spawner) { esp_hal_embassy::init(&clocks, [timer0, timer1]); static EXECUTOR: StaticCell> = StaticCell::new(); - let executor = InterruptExecutor::new(system.software_interrupt_control.software_interrupt2); + let executor = InterruptExecutor::new(sw_ints.software_interrupt2); let executor = EXECUTOR.init(executor); let spawner = executor.start(Priority::Priority3); diff --git a/examples/src/bin/embassy_parl_io_rx.rs b/examples/src/bin/embassy_parl_io_rx.rs index 43328f2e037..dae767bbd47 100644 --- a/examples/src/bin/embassy_parl_io_rx.rs +++ b/examples/src/bin/embassy_parl_io_rx.rs @@ -14,14 +14,11 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, gpio::Io, parl_io::{no_clk_pin, BitPackOrder, ParlIoRxOnly, RxFourBits}, - peripherals::Peripherals, prelude::*, - system::SystemControl, timer::systimer::{SystemTimer, Target}, }; use esp_println::println; @@ -29,9 +26,7 @@ use esp_println::println; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); esp_hal_embassy::init(&clocks, systimer.alarm0); diff --git a/examples/src/bin/embassy_parl_io_tx.rs b/examples/src/bin/embassy_parl_io_tx.rs index ae747156dfc..7a90821e50f 100644 --- a/examples/src/bin/embassy_parl_io_tx.rs +++ b/examples/src/bin/embassy_parl_io_tx.rs @@ -18,7 +18,6 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, gpio::Io, @@ -30,9 +29,7 @@ use esp_hal::{ TxFourBits, TxPinConfigWithValidPin, }, - peripherals::Peripherals, prelude::*, - system::SystemControl, timer::systimer::{SystemTimer, Target}, }; use esp_println::println; @@ -40,9 +37,7 @@ use esp_println::println; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); esp_hal_embassy::init(&clocks, systimer.alarm0); diff --git a/examples/src/bin/embassy_rmt_rx.rs b/examples/src/bin/embassy_rmt_rx.rs index 16d48dce79c..794aeceedd9 100644 --- a/examples/src/bin/embassy_rmt_rx.rs +++ b/examples/src/bin/embassy_rmt_rx.rs @@ -13,12 +13,9 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::{Gpio5, Io, Level, Output}, - peripherals::Peripherals, prelude::*, rmt::{asynch::RxChannelAsync, PulseCode, Rmt, RxChannelConfig, RxChannelCreatorAsync}, - system::SystemControl, timer::timg::TimerGroup, }; use esp_println::{print, println}; @@ -42,9 +39,7 @@ async fn signal_task(mut pin: Output<'static, Gpio5>) { #[esp_hal_embassy::main] async fn main(spawner: Spawner) { println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_rmt_tx.rs b/examples/src/bin/embassy_rmt_tx.rs index 8c179bcd02a..c8cc3c83427 100644 --- a/examples/src/bin/embassy_rmt_tx.rs +++ b/examples/src/bin/embassy_rmt_tx.rs @@ -15,12 +15,9 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::Io, - peripherals::Peripherals, prelude::*, rmt::{asynch::TxChannelAsync, PulseCode, Rmt, TxChannelConfig, TxChannelCreatorAsync}, - system::SystemControl, timer::timg::TimerGroup, }; use esp_println::println; @@ -28,9 +25,7 @@ use esp_println::println; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_serial.rs b/examples/src/bin/embassy_serial.rs index 0ea4bdab627..541ea6c8e89 100644 --- a/examples/src/bin/embassy_serial.rs +++ b/examples/src/bin/embassy_serial.rs @@ -1,7 +1,7 @@ //! embassy serial //! //! This is an example of running the embassy executor and asynchronously -//! writing to and reading from uart +//! writing to and reading from UART. //% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 //% FEATURES: async embassy embassy-generic-timers @@ -13,10 +13,8 @@ use embassy_executor::Spawner; use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::Io, - peripherals::{Peripherals, UART0}, - system::SystemControl, + peripherals::UART0, timer::timg::TimerGroup, uart::{ config::{AtCmdConfig, Config}, @@ -80,9 +78,7 @@ async fn reader( #[esp_hal_embassy::main] async fn main(spawner: Spawner) { esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_spi.rs b/examples/src/bin/embassy_spi.rs index 4a62f2a8450..a8f6ab68720 100644 --- a/examples/src/bin/embassy_spi.rs +++ b/examples/src/bin/embassy_spi.rs @@ -22,23 +22,18 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, dma::*, dma_buffers, gpio::Io, - peripherals::Peripherals, prelude::*, spi::{master::Spi, SpiMode}, - system::SystemControl, timer::timg::TimerGroup, }; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_touch.rs b/examples/src/bin/embassy_touch.rs index eb686243575..e0f199442f9 100644 --- a/examples/src/bin/embassy_touch.rs +++ b/examples/src/bin/embassy_touch.rs @@ -17,11 +17,8 @@ use embassy_futures::select::{select, Either}; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::Io, - peripherals::Peripherals, rtc_cntl::Rtc, - system::SystemControl, timer::timg::TimerGroup, touch::{Touch, TouchConfig, TouchPad}, }; @@ -30,10 +27,7 @@ use esp_println::println; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_twai.rs b/examples/src/bin/embassy_twai.rs index 6c0984d4db6..10ddc4e8df9 100644 --- a/examples/src/bin/embassy_twai.rs +++ b/examples/src/bin/embassy_twai.rs @@ -25,11 +25,9 @@ use embassy_sync::{blocking_mutex::raw::NoopRawMutex, channel::Channel}; use embedded_can::{Frame, Id}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::Io, interrupt, - peripherals::{self, Peripherals, TWAI0}, - system::SystemControl, + peripherals::{self, TWAI0}, timer::timg::TimerGroup, twai::{self, EspTwaiFrame, TwaiMode, TwaiRx, TwaiTx}, }; @@ -84,9 +82,7 @@ async fn transmitter( #[esp_hal_embassy::main] async fn main(spawner: Spawner) { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_usb_serial.rs b/examples/src/bin/embassy_usb_serial.rs index cd37616c907..f9acd516163 100644 --- a/examples/src/bin/embassy_usb_serial.rs +++ b/examples/src/bin/embassy_usb_serial.rs @@ -21,23 +21,18 @@ use embassy_usb::{ }; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::Io, otg_fs::{ asynch::{Config, Driver}, Usb, }, - peripherals::Peripherals, - system::SystemControl, timer::timg::TimerGroup, }; #[esp_hal_embassy::main] -async fn main(_spawner: Spawner) -> () { +async fn main(_spawner: Spawner) { esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_usb_serial_jtag.rs b/examples/src/bin/embassy_usb_serial_jtag.rs index 9cb154f83b7..d72089fdfb5 100644 --- a/examples/src/bin/embassy_usb_serial_jtag.rs +++ b/examples/src/bin/embassy_usb_serial_jtag.rs @@ -12,9 +12,6 @@ use embassy_executor::Spawner; use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - system::SystemControl, timer::timg::TimerGroup, usb_serial_jtag::{UsbSerialJtag, UsbSerialJtagRx, UsbSerialJtagTx}, Async, @@ -64,11 +61,9 @@ async fn reader( } #[esp_hal_embassy::main] -async fn main(spawner: Spawner) -> () { +async fn main(spawner: Spawner) { esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); diff --git a/examples/src/bin/embassy_wait.rs b/examples/src/bin/embassy_wait.rs index 82e8d3c86b2..9b9d5854db7 100644 --- a/examples/src/bin/embassy_wait.rs +++ b/examples/src/bin/embassy_wait.rs @@ -12,28 +12,27 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::{Input, Io, Pull}, - peripherals::Peripherals, - system::SystemControl, timer::timg::TimerGroup, }; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] - let mut input = Input::new(io.pins.gpio0, Pull::Down); - #[cfg(not(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3")))] - let mut input = Input::new(io.pins.gpio9, Pull::Down); + + cfg_if::cfg_if! { + if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] { + let mut input = Input::new(io.pins.gpio0, Pull::Down); + } else { + let mut input = Input::new(io.pins.gpio9, Pull::Down); + } + } loop { esp_println::println!("Waiting..."); diff --git a/examples/src/bin/etm_blinky_systimer.rs b/examples/src/bin/etm_blinky_systimer.rs index 89d5ce953ee..b0057d4cee5 100644 --- a/examples/src/bin/etm_blinky_systimer.rs +++ b/examples/src/bin/etm_blinky_systimer.rs @@ -17,7 +17,6 @@ use esp_hal::{ Level, Pull, }, - peripherals::Peripherals, prelude::*, timer::systimer::{etm::SysTimerEtmEvent, Periodic, SystemTimer}, }; @@ -25,7 +24,7 @@ use fugit::ExtU32; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let syst = SystemTimer::new(peripherals.SYSTIMER); let syst_alarms = syst.split::(); diff --git a/examples/src/bin/etm_gpio.rs b/examples/src/bin/etm_gpio.rs index ecced8d304e..36adfbdc393 100644 --- a/examples/src/bin/etm_gpio.rs +++ b/examples/src/bin/etm_gpio.rs @@ -17,13 +17,12 @@ use esp_hal::{ Level, Pull, }, - peripherals::Peripherals, prelude::*, }; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let mut led = io.pins.gpio1; diff --git a/examples/src/bin/etm_timer.rs b/examples/src/bin/etm_timer.rs index 802588313a2..649e64590cc 100644 --- a/examples/src/bin/etm_timer.rs +++ b/examples/src/bin/etm_timer.rs @@ -11,12 +11,10 @@ use core::cell::RefCell; use critical_section::Mutex; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, etm::Etm, - peripherals::{Peripherals, TIMG0}, + peripherals::TIMG0, prelude::*, - system::SystemControl, timer::timg::{ etm::{TimerEtmEvents, TimerEtmTasks}, Timer, @@ -30,9 +28,7 @@ static TIMER0: Mutex, esp_hal::Blocking>>>> = #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timer0 = timg0.timer0; diff --git a/examples/src/bin/gpio_interrupt.rs b/examples/src/bin/gpio_interrupt.rs index 06d730fd301..2e7a60fe36c 100644 --- a/examples/src/bin/gpio_interrupt.rs +++ b/examples/src/bin/gpio_interrupt.rs @@ -16,13 +16,10 @@ use core::cell::RefCell; use critical_section::Mutex; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, gpio::{self, Event, Input, Io, Level, Output, Pull}, macros::ram, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; cfg_if::cfg_if! { @@ -35,9 +32,7 @@ cfg_if::cfg_if! { #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); // Set GPIO2 as an output, and set its state high initially. let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/hello_rgb.rs b/examples/src/bin/hello_rgb.rs index 5dacba6a05d..d2afd555892 100644 --- a/examples/src/bin/hello_rgb.rs +++ b/examples/src/bin/hello_rgb.rs @@ -25,15 +25,7 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - delay::Delay, - gpio::Io, - peripherals::Peripherals, - prelude::*, - rmt::Rmt, - system::SystemControl, -}; +use esp_hal::{delay::Delay, gpio::Io, prelude::*, rmt::Rmt}; use esp_hal_smartled::{smartLedBuffer, SmartLedsAdapter}; use smart_leds::{ brightness, @@ -44,9 +36,7 @@ use smart_leds::{ #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/hello_world.rs b/examples/src/bin/hello_world.rs index dc378198900..ebda656f449 100644 --- a/examples/src/bin/hello_world.rs +++ b/examples/src/bin/hello_world.rs @@ -15,21 +15,11 @@ use core::fmt::Write; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - delay::Delay, - gpio::Io, - peripherals::Peripherals, - prelude::*, - system::SystemControl, - uart::Uart, -}; +use esp_hal::{delay::Delay, gpio::Io, prelude::*, uart::Uart}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(&clocks); diff --git a/examples/src/bin/hmac.rs b/examples/src/bin/hmac.rs index 3df3ef86400..0cd9bf634c2 100644 --- a/examples/src/bin/hmac.rs +++ b/examples/src/bin/hmac.rs @@ -59,12 +59,9 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, hmac::{Hmac, HmacPurpose, KeyId}, - peripherals::Peripherals, prelude::*, rng::Rng, - system::SystemControl, timer::systimer::SystemTimer, }; use esp_println::println; @@ -76,9 +73,7 @@ type HmacSha256 = HmacSw; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let mut rng = Rng::new(peripherals.RNG); diff --git a/examples/src/bin/i2c_bmp180_calibration_data.rs b/examples/src/bin/i2c_bmp180_calibration_data.rs index adf19b1da9c..e3f61626a01 100644 --- a/examples/src/bin/i2c_bmp180_calibration_data.rs +++ b/examples/src/bin/i2c_bmp180_calibration_data.rs @@ -12,21 +12,12 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - gpio::Io, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - system::SystemControl, -}; +use esp_hal::{gpio::Io, i2c::I2C, prelude::*}; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/i2c_display.rs b/examples/src/bin/i2c_display.rs index 7b874872a25..a225d44b0f4 100644 --- a/examples/src/bin/i2c_display.rs +++ b/examples/src/bin/i2c_display.rs @@ -23,22 +23,12 @@ use embedded_graphics::{ text::{Alignment, Text}, }; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - delay::Delay, - gpio::Io, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - system::SystemControl, -}; +use esp_hal::{delay::Delay, gpio::Io, i2c::I2C, prelude::*}; use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(&clocks); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/i2s_read.rs b/examples/src/bin/i2s_read.rs index 395e1b23257..5a1616eef38 100644 --- a/examples/src/bin/i2s_read.rs +++ b/examples/src/bin/i2s_read.rs @@ -18,22 +18,17 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, gpio::Io, i2s::{DataFormat, I2s, I2sReadDma, Standard}, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/i2s_sound.rs b/examples/src/bin/i2s_sound.rs index 991b39d3381..998bb127cdf 100644 --- a/examples/src/bin/i2s_sound.rs +++ b/examples/src/bin/i2s_sound.rs @@ -1,7 +1,7 @@ -//! This shows how to transmit data continously via I2S. +//! This shows how to transmit data continuously via I2S. //! //! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS -//! andDOUT with a logic analyzer. +//! and DOUT with a logic analyzer. //! //! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full //! scale), so turn down the volume before running this example. @@ -32,14 +32,11 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, gpio::Io, i2s::{DataFormat, I2s, I2sWriteDma, Standard}, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; const SINE: [i16; 64] = [ @@ -52,9 +49,7 @@ const SINE: [i16; 64] = [ #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/ieee802154_receive_all_frames.rs b/examples/src/bin/ieee802154_receive_all_frames.rs index 5adb3c0ad0c..ce078a0223d 100644 --- a/examples/src/bin/ieee802154_receive_all_frames.rs +++ b/examples/src/bin/ieee802154_receive_all_frames.rs @@ -4,13 +4,13 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{peripherals::Peripherals, prelude::*}; -use esp_ieee802154::*; +use esp_hal::prelude::*; +use esp_ieee802154::{Config, Ieee802154}; use esp_println::println; #[entry] fn main() -> ! { - let mut peripherals = Peripherals::take(); + let (mut peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); ieee802154.set_config(Config { @@ -19,7 +19,7 @@ fn main() -> ! { rx_when_idle: true, auto_ack_rx: false, auto_ack_tx: false, - ..Config::default() + ..Default::default() }); println!("Start receiving:"); diff --git a/examples/src/bin/ieee802154_receive_frame.rs b/examples/src/bin/ieee802154_receive_frame.rs index 07e5de3f071..5fa678a3a52 100644 --- a/examples/src/bin/ieee802154_receive_frame.rs +++ b/examples/src/bin/ieee802154_receive_frame.rs @@ -4,13 +4,13 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{peripherals::Peripherals, prelude::*}; -use esp_ieee802154::*; +use esp_hal::prelude::*; +use esp_ieee802154::{Config, Ieee802154}; use esp_println::println; #[entry] fn main() -> ! { - let mut peripherals = Peripherals::take(); + let (mut peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); ieee802154.set_config(Config { @@ -21,7 +21,7 @@ fn main() -> ! { auto_ack_tx: true, pan_id: Some(0x4242), short_addr: Some(0x2323), - ..Config::default() + ..Default::default() }); println!("Start receiving:"); diff --git a/examples/src/bin/ieee802154_send_broadcast_frame.rs b/examples/src/bin/ieee802154_send_broadcast_frame.rs index 070cf8e7983..1053a934e16 100644 --- a/examples/src/bin/ieee802154_send_broadcast_frame.rs +++ b/examples/src/bin/ieee802154_send_broadcast_frame.rs @@ -4,14 +4,8 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - delay::Delay, - peripherals::Peripherals, - prelude::*, - system::SystemControl, -}; -use esp_ieee802154::*; +use esp_hal::{delay::Delay, prelude::*}; +use esp_ieee802154::{Config, Frame, Ieee802154}; use esp_println::println; use ieee802154::mac::{ Address, @@ -25,9 +19,7 @@ use ieee802154::mac::{ #[entry] fn main() -> ! { - let mut peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (mut peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(&clocks); @@ -38,7 +30,7 @@ fn main() -> ! { promiscuous: false, pan_id: Some(0x4242), short_addr: Some(0x2323), - ..Config::default() + ..Default::default() }); let mut seq_number = 0u8; diff --git a/examples/src/bin/ieee802154_send_frame.rs b/examples/src/bin/ieee802154_send_frame.rs index 7992a71694e..9cf2e72ba9e 100644 --- a/examples/src/bin/ieee802154_send_frame.rs +++ b/examples/src/bin/ieee802154_send_frame.rs @@ -4,14 +4,8 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - delay::Delay, - peripherals::Peripherals, - prelude::*, - system::SystemControl, -}; -use esp_ieee802154::*; +use esp_hal::{delay::Delay, prelude::*}; +use esp_ieee802154::{Config, Frame, Ieee802154}; use esp_println::println; use ieee802154::mac::{ Address, @@ -25,9 +19,7 @@ use ieee802154::mac::{ #[entry] fn main() -> ! { - let mut peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (mut peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(&clocks); @@ -38,7 +30,7 @@ fn main() -> ! { promiscuous: false, pan_id: Some(0x4242), short_addr: Some(0x2222), - ..Config::default() + ..Default::default() }); let mut seq_number = 0u8; diff --git a/examples/src/bin/ieee802154_sniffer.rs b/examples/src/bin/ieee802154_sniffer.rs index b7e2bb07089..c78a7166a1e 100644 --- a/examples/src/bin/ieee802154_sniffer.rs +++ b/examples/src/bin/ieee802154_sniffer.rs @@ -8,23 +8,13 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - gpio::Io, - peripherals::Peripherals, - prelude::*, - reset::software_reset, - system::SystemControl, - uart::Uart, -}; -use esp_ieee802154::*; +use esp_hal::{gpio::Io, prelude::*, reset::software_reset, uart::Uart}; +use esp_ieee802154::{Config, Ieee802154}; use esp_println::println; #[entry] fn main() -> ! { - let mut peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (mut peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -69,7 +59,7 @@ fn main() -> ! { rx_when_idle: true, auto_ack_rx: false, auto_ack_tx: false, - ..Config::default() + ..Default::default() }); ieee802154.start_receive(); diff --git a/examples/src/bin/lcd_cam_ov2640.rs b/examples/src/bin/lcd_cam_ov2640.rs index 07f12f8a1cf..caa62eeb383 100644 --- a/examples/src/bin/lcd_cam_ov2640.rs +++ b/examples/src/bin/lcd_cam_ov2640.rs @@ -25,7 +25,6 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, dma::{Dma, DmaPriority}, dma_buffers, @@ -36,18 +35,14 @@ use esp_hal::{ cam::{Camera, RxEightBits}, LcdCam, }, - peripherals::Peripherals, prelude::*, - system::SystemControl, Blocking, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/lcd_i8080.rs b/examples/src/bin/lcd_i8080.rs index b3b02a06292..20597d7babb 100644 --- a/examples/src/bin/lcd_i8080.rs +++ b/examples/src/bin/lcd_i8080.rs @@ -23,7 +23,6 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, dma::{Dma, DmaPriority}, dma_buffers, @@ -32,17 +31,13 @@ use esp_hal::{ lcd::i8080::{Config, TxEightBits, I8080}, LcdCam, }, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/ledc.rs b/examples/src/bin/ledc.rs index 94d8dbdb3c9..b7dd70e6c20 100644 --- a/examples/src/bin/ledc.rs +++ b/examples/src/bin/ledc.rs @@ -11,7 +11,6 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::Io, ledc::{ channel::{self, ChannelIFace}, @@ -20,16 +19,12 @@ use esp_hal::{ Ledc, LowSpeed, }, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let led = io.pins.gpio0; diff --git a/examples/src/bin/lp_core_basic.rs b/examples/src/bin/lp_core_basic.rs index 81dc1a7a632..9b35e8c0eba 100644 --- a/examples/src/bin/lp_core_basic.rs +++ b/examples/src/bin/lp_core_basic.rs @@ -17,14 +17,13 @@ use esp_backtrace as _; use esp_hal::{ gpio::{lp_io::LowPowerOutput, Io}, lp_core::{LpCore, LpCoreWakeupSource}, - peripherals::Peripherals, prelude::*, }; use esp_println::{print, println}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); // configure GPIO 1 as LP output pin let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/lp_core_i2c.rs b/examples/src/bin/lp_core_i2c.rs index b285b4b172d..c4a817fd9f4 100644 --- a/examples/src/bin/lp_core_i2c.rs +++ b/examples/src/bin/lp_core_i2c.rs @@ -19,14 +19,13 @@ use esp_hal::{ gpio::{lp_io::LowPowerOutputOpenDrain, Io}, i2c::lp_i2c::LpI2c, lp_core::{LpCore, LpCoreWakeupSource}, - peripherals::Peripherals, prelude::*, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/lp_core_uart.rs b/examples/src/bin/lp_core_uart.rs index df795db9682..79e5962e946 100644 --- a/examples/src/bin/lp_core_uart.rs +++ b/examples/src/bin/lp_core_uart.rs @@ -16,24 +16,19 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::{ lp_io::{LowPowerInput, LowPowerOutput}, Io, }, lp_core::{LpCore, LpCoreWakeupSource}, - peripherals::Peripherals, prelude::*, - system::SystemControl, uart::{config::Config, lp_uart::LpUart, Uart}, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/mcpwm.rs b/examples/src/bin/mcpwm.rs index f25d932e6c8..783046ae783 100644 --- a/examples/src/bin/mcpwm.rs +++ b/examples/src/bin/mcpwm.rs @@ -11,19 +11,14 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::Io, mcpwm::{operator::PwmPinConfig, timer::PwmWorkingMode, McPwm, PeripheralClockConfig}, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let pin = io.pins.gpio0; diff --git a/examples/src/bin/multicore.rs b/examples/src/bin/multicore.rs index 1d028bdc9b9..28297e91733 100644 --- a/examples/src/bin/multicore.rs +++ b/examples/src/bin/multicore.rs @@ -13,12 +13,9 @@ use core::{cell::RefCell, ptr::addr_of_mut}; use critical_section::Mutex; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, cpu_control::{CpuControl, Stack}, delay::Delay, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; use esp_println::println; @@ -26,9 +23,7 @@ static mut APP_CORE_STACK: Stack<8192> = Stack::new(); #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(&clocks); diff --git a/examples/src/bin/parl_io_rx.rs b/examples/src/bin/parl_io_rx.rs index 0606667f75f..04d31ce6302 100644 --- a/examples/src/bin/parl_io_rx.rs +++ b/examples/src/bin/parl_io_rx.rs @@ -11,23 +11,18 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, dma::{Dma, DmaPriority}, dma_buffers, gpio::Io, parl_io::{no_clk_pin, BitPackOrder, ParlIoRxOnly, RxFourBits}, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/parl_io_tx.rs b/examples/src/bin/parl_io_tx.rs index 60536033a9e..8fc1b9eac6d 100644 --- a/examples/src/bin/parl_io_tx.rs +++ b/examples/src/bin/parl_io_tx.rs @@ -15,7 +15,6 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, dma::{Dma, DmaPriority}, dma_buffers, @@ -28,17 +27,13 @@ use esp_hal::{ TxFourBits, TxPinConfigWithValidPin, }, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/pcnt_encoder.rs b/examples/src/bin/pcnt_encoder.rs index 8e22d236b77..5cba71d117a 100644 --- a/examples/src/bin/pcnt_encoder.rs +++ b/examples/src/bin/pcnt_encoder.rs @@ -1,6 +1,6 @@ //! PCNT Encoder Demo //! -//! This example decodes a quadrature encoder +//! This example decodes a quadrature encoder. //! //! Since the PCNT units reset to zero when they reach their limits //! we enable an interrupt on the upper and lower limits and @@ -27,7 +27,6 @@ use esp_hal::{ unit, Pcnt, }, - peripherals::Peripherals, prelude::*, }; use esp_println::println; @@ -38,7 +37,7 @@ static VALUE: AtomicI32 = AtomicI32::new(0); #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/psram_octal.rs b/examples/src/bin/psram_octal.rs index 1916ba4d0c3..a1c46c7d80f 100644 --- a/examples/src/bin/psram_octal.rs +++ b/examples/src/bin/psram_octal.rs @@ -13,7 +13,7 @@ extern crate alloc; use alloc::{string::String, vec::Vec}; use esp_backtrace as _; -use esp_hal::{peripherals::Peripherals, prelude::*, psram}; +use esp_hal::{prelude::*, psram}; use esp_println::println; #[global_allocator] @@ -30,7 +30,7 @@ fn main() -> ! { #[cfg(debug_assertions)] compile_error!("This example MUST be built in release mode!"); - let peripherals = Peripherals::take(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); psram::init_psram(peripherals.PSRAM); init_psram_heap(); diff --git a/examples/src/bin/psram_quad.rs b/examples/src/bin/psram_quad.rs index 47dfc69ceb8..93c0d9747ac 100644 --- a/examples/src/bin/psram_quad.rs +++ b/examples/src/bin/psram_quad.rs @@ -13,13 +13,7 @@ extern crate alloc; use alloc::{string::String, vec::Vec}; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - psram, - system::SystemControl, -}; +use esp_hal::{prelude::*, psram}; use esp_println::println; #[global_allocator] @@ -36,14 +30,11 @@ fn main() -> ! { #[cfg(debug_assertions)] compile_error!("PSRAM example must be built in release mode!"); - let peripherals = Peripherals::take(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); psram::init_psram(peripherals.PSRAM); init_psram_heap(); - let system = SystemControl::new(peripherals.SYSTEM); - let _clocks = ClockControl::max(system.clock_control).freeze(); - println!("Going to access PSRAM"); let mut large_vec = Vec::::with_capacity(500 * 1024 / 4); diff --git a/examples/src/bin/qspi_flash.rs b/examples/src/bin/qspi_flash.rs index 9c503d8a0ee..65ee4ef5732 100644 --- a/examples/src/bin/qspi_flash.rs +++ b/examples/src/bin/qspi_flash.rs @@ -29,27 +29,22 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::Io, - peripherals::Peripherals, prelude::*, spi::{ master::{Address, Command, Spi}, SpiDataMode, SpiMode, }, - system::SystemControl, }; use esp_println::{print, println}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); cfg_if::cfg_if! { diff --git a/examples/src/bin/ram.rs b/examples/src/bin/ram.rs index bd165d99e2d..bece3c8a998 100644 --- a/examples/src/bin/ram.rs +++ b/examples/src/bin/ram.rs @@ -17,15 +17,7 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - delay::Delay, - macros::ram, - peripherals::Peripherals, - prelude::*, - rtc_cntl::Rtc, - system::SystemControl, -}; +use esp_hal::{delay::Delay, macros::ram, prelude::*, rtc_cntl::Rtc}; use esp_println::println; #[ram(rtc_fast)] @@ -39,9 +31,7 @@ static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8]; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(&clocks); diff --git a/examples/src/bin/rmt_rx.rs b/examples/src/bin/rmt_rx.rs index ca9984cec28..9ad6803f979 100644 --- a/examples/src/bin/rmt_rx.rs +++ b/examples/src/bin/rmt_rx.rs @@ -13,13 +13,10 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, gpio::Io, - peripherals::Peripherals, prelude::*, rmt::{PulseCode, Rmt, RxChannel, RxChannelConfig, RxChannelCreator}, - system::SystemControl, }; use esp_println::{print, println}; @@ -27,9 +24,7 @@ const WIDTH: usize = 80; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let mut out = io.pins.gpio5; diff --git a/examples/src/bin/rmt_tx.rs b/examples/src/bin/rmt_tx.rs index d6ef6cf3953..fd5dbc8807d 100644 --- a/examples/src/bin/rmt_tx.rs +++ b/examples/src/bin/rmt_tx.rs @@ -12,20 +12,15 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, gpio::Io, - peripherals::Peripherals, prelude::*, rmt::{PulseCode, Rmt, TxChannel, TxChannelConfig, TxChannelCreator}, - system::SystemControl, }; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/rng.rs b/examples/src/bin/rng.rs index fc87b7d8fda..e981faac46a 100644 --- a/examples/src/bin/rng.rs +++ b/examples/src/bin/rng.rs @@ -6,12 +6,12 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{peripherals::Peripherals, prelude::*, rng::Rng}; +use esp_hal::{prelude::*, rng::Rng}; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let mut rng = Rng::new(peripherals.RNG); // Generate a random word (u32): diff --git a/examples/src/bin/rtc_time.rs b/examples/src/bin/rtc_time.rs index c4e9b876b06..4c0e9c4d189 100644 --- a/examples/src/bin/rtc_time.rs +++ b/examples/src/bin/rtc_time.rs @@ -6,20 +6,11 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - delay::Delay, - peripherals::Peripherals, - prelude::*, - rtc_cntl::Rtc, - system::SystemControl, -}; +use esp_hal::{delay::Delay, prelude::*, rtc_cntl::Rtc}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let rtc = Rtc::new(peripherals.LPWR); let delay = Delay::new(&clocks); diff --git a/examples/src/bin/rtc_watchdog.rs b/examples/src/bin/rtc_watchdog.rs index cddd09dcf8e..e197bd13038 100644 --- a/examples/src/bin/rtc_watchdog.rs +++ b/examples/src/bin/rtc_watchdog.rs @@ -1,4 +1,4 @@ -//! This demos the RTC Watchdog Timer (RWDT). +//! This example demonstrates the RTC Watchdog Timer (RWDT). //! //! The RWDT is initially configured to trigger an interrupt after a given //! timeout. Then, upon expiration, the RWDT is restarted and then reconfigured @@ -14,16 +14,17 @@ use core::cell::RefCell; use critical_section::Mutex; use esp_backtrace as _; use esp_hal::{ - peripherals::Peripherals, + interrupt::Priority, prelude::*, rtc_cntl::{Rtc, Rwdt}, }; +use esp_println::println; static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let mut rtc = Rtc::new(peripherals.LPWR); rtc.set_interrupt_handler(interrupt_handler); @@ -35,16 +36,16 @@ fn main() -> ! { loop {} } -#[handler(priority = esp_hal::interrupt::Priority::min())] +#[handler(priority = Priority::min())] fn interrupt_handler() { critical_section::with(|cs| { - esp_println::println!("RWDT Interrupt"); + println!("RWDT Interrupt"); let mut rwdt = RWDT.borrow_ref_mut(cs); let rwdt = rwdt.as_mut().unwrap(); rwdt.clear_interrupt(); - esp_println::println!("Restarting in 5 seconds..."); + println!("Restarting in 5 seconds..."); rwdt.set_timeout(5000.millis()); rwdt.unlisten(); diff --git a/examples/src/bin/serial_interrupts.rs b/examples/src/bin/serial_interrupts.rs index e0a12904f26..729f5a3d3a9 100644 --- a/examples/src/bin/serial_interrupts.rs +++ b/examples/src/bin/serial_interrupts.rs @@ -12,12 +12,10 @@ use core::{cell::RefCell, fmt::Write}; use critical_section::Mutex; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, gpio::Io, - peripherals::{Peripherals, UART0}, + peripherals::UART0, prelude::*, - system::SystemControl, uart::{ config::{AtCmdConfig, Config}, Uart, @@ -29,9 +27,7 @@ static SERIAL: Mutex>>> = Mutex::new(RefCel #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(&clocks); diff --git a/examples/src/bin/sleep_timer.rs b/examples/src/bin/sleep_timer.rs index fa882bd9ac4..1a0db0116ef 100644 --- a/examples/src/bin/sleep_timer.rs +++ b/examples/src/bin/sleep_timer.rs @@ -9,21 +9,16 @@ use core::time::Duration; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, entry, - peripherals::Peripherals, rtc_cntl::{get_reset_reason, get_wakeup_cause, sleep::TimerWakeupSource, Rtc, SocResetReason}, - system::SystemControl, Cpu, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(&clocks); let mut rtc = Rtc::new(peripherals.LPWR); diff --git a/examples/src/bin/sleep_timer_ext0.rs b/examples/src/bin/sleep_timer_ext0.rs index b54e646871a..4fef91badb2 100644 --- a/examples/src/bin/sleep_timer_ext0.rs +++ b/examples/src/bin/sleep_timer_ext0.rs @@ -12,11 +12,9 @@ use core::time::Duration; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, entry, gpio::Io, - peripherals::Peripherals, rtc_cntl::{ get_reset_reason, get_wakeup_cause, @@ -24,16 +22,13 @@ use esp_hal::{ Rtc, SocResetReason, }, - system::SystemControl, Cpu, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let mut rtc = Rtc::new(peripherals.LPWR); diff --git a/examples/src/bin/sleep_timer_ext1.rs b/examples/src/bin/sleep_timer_ext1.rs index 2f702642ffe..bf1c0f881bf 100644 --- a/examples/src/bin/sleep_timer_ext1.rs +++ b/examples/src/bin/sleep_timer_ext1.rs @@ -12,11 +12,9 @@ use core::time::Duration; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, entry, gpio::{Io, RtcPin}, - peripherals::Peripherals, rtc_cntl::{ get_reset_reason, get_wakeup_cause, @@ -24,16 +22,13 @@ use esp_hal::{ Rtc, SocResetReason, }, - system::SystemControl, Cpu, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let mut rtc = Rtc::new(peripherals.LPWR); diff --git a/examples/src/bin/sleep_timer_lpio.rs b/examples/src/bin/sleep_timer_lpio.rs index 63c7074f422..05f8a8e04f7 100644 --- a/examples/src/bin/sleep_timer_lpio.rs +++ b/examples/src/bin/sleep_timer_lpio.rs @@ -13,11 +13,9 @@ use core::time::Duration; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, entry, gpio::{Io, RtcPinWithResistors}, - peripherals::Peripherals, rtc_cntl::{ get_reset_reason, get_wakeup_cause, @@ -25,16 +23,13 @@ use esp_hal::{ Rtc, SocResetReason, }, - system::SystemControl, Cpu, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let mut rtc = Rtc::new(peripherals.LPWR); diff --git a/examples/src/bin/sleep_timer_rtcio.rs b/examples/src/bin/sleep_timer_rtcio.rs index 6b963f1bee5..6b33624beaa 100644 --- a/examples/src/bin/sleep_timer_rtcio.rs +++ b/examples/src/bin/sleep_timer_rtcio.rs @@ -16,12 +16,10 @@ use core::time::Duration; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, entry, gpio, gpio::Io, - peripherals::Peripherals, rtc_cntl::{ get_reset_reason, get_wakeup_cause, @@ -29,16 +27,13 @@ use esp_hal::{ Rtc, SocResetReason, }, - system::SystemControl, Cpu, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let mut rtc = Rtc::new(peripherals.LPWR); diff --git a/examples/src/bin/software_interrupts.rs b/examples/src/bin/software_interrupts.rs index 5fa0f5252b9..48c1a88bc74 100644 --- a/examples/src/bin/software_interrupts.rs +++ b/examples/src/bin/software_interrupts.rs @@ -14,11 +14,9 @@ use core::cell::RefCell; use critical_section::Mutex; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, - peripherals::Peripherals, + interrupt::software::{SoftwareInterrupt, SoftwareInterruptControl}, prelude::*, - system::{SoftwareInterrupt, SystemControl}, }; static SWINT0: Mutex>>> = Mutex::new(RefCell::new(None)); @@ -28,39 +26,38 @@ static SWINT3: Mutex>>> = Mutex::new(RefCell #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + + let mut sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); - let mut sw_int = system.software_interrupt_control; critical_section::with(|cs| { - sw_int + sw_ints .software_interrupt0 .set_interrupt_handler(swint0_handler); SWINT0 .borrow_ref_mut(cs) - .replace(sw_int.software_interrupt0); + .replace(sw_ints.software_interrupt0); - sw_int + sw_ints .software_interrupt1 .set_interrupt_handler(swint1_handler); SWINT1 .borrow_ref_mut(cs) - .replace(sw_int.software_interrupt1); + .replace(sw_ints.software_interrupt1); - sw_int + sw_ints .software_interrupt2 .set_interrupt_handler(swint2_handler); SWINT2 .borrow_ref_mut(cs) - .replace(sw_int.software_interrupt2); + .replace(sw_ints.software_interrupt2); - sw_int + sw_ints .software_interrupt3 .set_interrupt_handler(swint3_handler); SWINT3 .borrow_ref_mut(cs) - .replace(sw_int.software_interrupt3); + .replace(sw_ints.software_interrupt3); }); let delay = Delay::new(&clocks); diff --git a/examples/src/bin/spi_halfduplex_read_manufacturer_id.rs b/examples/src/bin/spi_halfduplex_read_manufacturer_id.rs index 8e56ab17b17..cd10f9a0cd4 100644 --- a/examples/src/bin/spi_halfduplex_read_manufacturer_id.rs +++ b/examples/src/bin/spi_halfduplex_read_manufacturer_id.rs @@ -29,25 +29,20 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, gpio::Io, - peripherals::Peripherals, prelude::*, spi::{ master::{Address, Command, HalfDuplexReadWrite, Spi}, SpiDataMode, SpiMode, }, - system::SystemControl, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); cfg_if::cfg_if! { diff --git a/examples/src/bin/spi_loopback.rs b/examples/src/bin/spi_loopback.rs index 6c8432592b2..17248269422 100644 --- a/examples/src/bin/spi_loopback.rs +++ b/examples/src/bin/spi_loopback.rs @@ -20,21 +20,16 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, gpio::{AnyPin, Io}, - peripherals::Peripherals, prelude::*, spi::{master::Spi, SpiMode}, - system::SystemControl, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; diff --git a/examples/src/bin/spi_loopback_dma.rs b/examples/src/bin/spi_loopback_dma.rs index c277e6fa88d..b13dd875bb4 100644 --- a/examples/src/bin/spi_loopback_dma.rs +++ b/examples/src/bin/spi_loopback_dma.rs @@ -20,23 +20,18 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::Io, - peripherals::Peripherals, prelude::*, spi::{master::Spi, SpiMode}, - system::SystemControl, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; diff --git a/examples/src/bin/spi_slave_dma.rs b/examples/src/bin/spi_slave_dma.rs index 6ab99df99a1..f821c49f168 100644 --- a/examples/src/bin/spi_slave_dma.rs +++ b/examples/src/bin/spi_slave_dma.rs @@ -31,26 +31,21 @@ use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, dma::{Dma, DmaPriority}, dma_buffers, gpio::{Gpio4, Gpio5, Gpio8, Gpio9, Input, Io, Level, Output, Pull}, - peripherals::Peripherals, prelude::*, spi::{ slave::{prelude::*, Spi}, SpiMode, }, - system::SystemControl, }; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let slave_sclk = io.pins.gpio0; diff --git a/examples/src/bin/systimer.rs b/examples/src/bin/systimer.rs index cdbf345a96b..72d1931ef9c 100644 --- a/examples/src/bin/systimer.rs +++ b/examples/src/bin/systimer.rs @@ -12,11 +12,8 @@ use core::cell::RefCell; use critical_section::Mutex; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, - peripherals::Peripherals, prelude::*, - system::SystemControl, timer::systimer::{ Alarm, FrozenUnit, @@ -50,9 +47,7 @@ static ALARM2: Mutex< #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let systimer = SystemTimer::new(peripherals.SYSTIMER); println!("SYSTIMER Current value = {}", SystemTimer::now()); diff --git a/examples/src/bin/timer_interrupt.rs b/examples/src/bin/timer_interrupt.rs index b22d10aadd4..aec50184183 100644 --- a/examples/src/bin/timer_interrupt.rs +++ b/examples/src/bin/timer_interrupt.rs @@ -12,11 +12,9 @@ use core::cell::RefCell; use critical_section::Mutex; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, interrupt::{self, Priority}, - peripherals::{Interrupt, Peripherals, TIMG0}, + peripherals::{Interrupt, TIMG0}, prelude::*, - system::SystemControl, timer::timg::{Timer, Timer0, TimerGroup}, }; @@ -25,9 +23,7 @@ static TIMER0: Mutex, esp_hal::Blocking>>>> = #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timer0 = timg0.timer0; diff --git a/examples/src/bin/touch.rs b/examples/src/bin/touch.rs index f7870b07c22..eef73f705d0 100644 --- a/examples/src/bin/touch.rs +++ b/examples/src/bin/touch.rs @@ -16,15 +16,12 @@ use core::cell::RefCell; use critical_section::Mutex; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, gpio, gpio::Io, macros::ram, - peripherals::Peripherals, prelude::*, rtc_cntl::Rtc, - system::SystemControl, touch::{Continous, Touch, TouchConfig, TouchPad}, Blocking, }; @@ -51,9 +48,7 @@ fn interrupt_handler() { #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/twai.rs b/examples/src/bin/twai.rs index 374285b3e5c..9620ae508dc 100644 --- a/examples/src/bin/twai.rs +++ b/examples/src/bin/twai.rs @@ -26,11 +26,8 @@ const IS_FIRST_SENDER: bool = true; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::Io, - peripherals::Peripherals, prelude::*, - system::SystemControl, twai::{self, filter::SingleStandardFilter, EspTwaiFrame, StandardId, TwaiMode}, }; use esp_println::println; @@ -38,9 +35,7 @@ use nb::block; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/ulp_riscv_core_basic.rs b/examples/src/bin/ulp_riscv_core_basic.rs index 578e7e6a31d..dcdac147257 100644 --- a/examples/src/bin/ulp_riscv_core_basic.rs +++ b/examples/src/bin/ulp_riscv_core_basic.rs @@ -14,7 +14,6 @@ use esp_backtrace as _; use esp_hal::{ gpio::{rtc_io::*, Io}, - peripherals::Peripherals, prelude::*, ulp_core, }; @@ -22,7 +21,7 @@ use esp_println::{print, println}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let pin = LowPowerOutput::new(io.pins.gpio1); diff --git a/examples/src/bin/usb_serial.rs b/examples/src/bin/usb_serial.rs index 4032bc8a0e4..236d5a10bb2 100644 --- a/examples/src/bin/usb_serial.rs +++ b/examples/src/bin/usb_serial.rs @@ -17,7 +17,6 @@ use esp_backtrace as _; use esp_hal::{ gpio::Io, otg_fs::{Usb, UsbBus}, - peripherals::Peripherals, prelude::*, }; use usb_device::prelude::{UsbDeviceBuilder, UsbVidPid}; @@ -27,7 +26,7 @@ static mut EP_MEMORY: [u32; 1024] = [0; 1024]; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/usb_serial_jtag.rs b/examples/src/bin/usb_serial_jtag.rs index d87ab1a7978..a75d0dd486b 100644 --- a/examples/src/bin/usb_serial_jtag.rs +++ b/examples/src/bin/usb_serial_jtag.rs @@ -16,24 +16,14 @@ use core::{cell::RefCell, fmt::Write}; use critical_section::Mutex; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - delay::Delay, - peripherals::Peripherals, - prelude::*, - system::SystemControl, - usb_serial_jtag::UsbSerialJtag, - Blocking, -}; +use esp_hal::{delay::Delay, prelude::*, usb_serial_jtag::UsbSerialJtag, Blocking}; static USB_SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(&clocks); diff --git a/examples/src/bin/watchdog.rs b/examples/src/bin/watchdog.rs index 00ba024813c..220e9ad4abf 100644 --- a/examples/src/bin/watchdog.rs +++ b/examples/src/bin/watchdog.rs @@ -9,21 +9,12 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - delay::Delay, - peripherals::Peripherals, - prelude::*, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{delay::Delay, prelude::*, timer::timg::TimerGroup}; use esp_println::println; #[entry] fn main() -> ! { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(&clocks); diff --git a/examples/src/bin/wifi_80211_tx.rs b/examples/src/bin/wifi_80211_tx.rs index d3d70ee062a..90c95060055 100644 --- a/examples/src/bin/wifi_80211_tx.rs +++ b/examples/src/bin/wifi_80211_tx.rs @@ -12,12 +12,9 @@ use core::marker::PhantomData; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, delay::Delay, - peripherals::Peripherals, prelude::*, rng::Rng, - system::SystemControl, timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer}, }; use esp_wifi::{initialize, wifi, EspWifiInitFor}; @@ -37,11 +34,11 @@ const MAC_ADDRESS: [u8; 6] = [0x00, 0x80, 0x41, 0x13, 0x37, 0x42]; #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let delay = Delay::new(&clocks); diff --git a/examples/src/bin/wifi_access_point.rs b/examples/src/bin/wifi_access_point.rs index d9807afa65f..e1e01ec525d 100644 --- a/examples/src/bin/wifi_access_point.rs +++ b/examples/src/bin/wifi_access_point.rs @@ -15,14 +15,7 @@ use embedded_io::*; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::{print, println}; use esp_wifi::{ current_millis, @@ -41,11 +34,11 @@ use smoltcp::iface::SocketStorage; #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/examples/src/bin/wifi_access_point_with_sta.rs b/examples/src/bin/wifi_access_point_with_sta.rs index 9ca5aaccb41..f58349849e6 100644 --- a/examples/src/bin/wifi_access_point_with_sta.rs +++ b/examples/src/bin/wifi_access_point_with_sta.rs @@ -16,14 +16,7 @@ use embedded_io::*; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::{print, println}; use esp_wifi::{ current_millis, @@ -48,11 +41,11 @@ const PASSWORD: &str = env!("PASSWORD"); #[entry] fn main() -> ! { esp_println::logger::init_logger(log::LevelFilter::Info); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/examples/src/bin/wifi_bench.rs b/examples/src/bin/wifi_bench.rs index 5427e3b11e6..844f291a066 100644 --- a/examples/src/bin/wifi_bench.rs +++ b/examples/src/bin/wifi_bench.rs @@ -15,15 +15,7 @@ use embedded_io::*; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - delay::Delay, - peripherals::Peripherals, - prelude::*, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{delay::Delay, prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::println; use esp_wifi::{ current_millis, @@ -59,11 +51,11 @@ const UPLOAD_DOWNLOAD_PORT: u16 = 4323; #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let server_address: Ipv4Address = HOST_IP.parse().expect("Invalid HOST_IP address"); diff --git a/examples/src/bin/wifi_ble.rs b/examples/src/bin/wifi_ble.rs index e63ffb2519c..c71bdb0ec6f 100644 --- a/examples/src/bin/wifi_ble.rs +++ b/examples/src/bin/wifi_ble.rs @@ -24,12 +24,9 @@ use bleps::{ }; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::{Input, Io, Pull}, - peripherals::*, prelude::*, rng::Rng, - system::SystemControl, timer::timg::TimerGroup, }; use esp_println::println; @@ -38,11 +35,11 @@ use esp_wifi::{ble::controller::BleConnector, initialize, EspWifiInitFor}; #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/examples/src/bin/wifi_coex.rs b/examples/src/bin/wifi_coex.rs index 4f94af99076..0bd4a4549f7 100644 --- a/examples/src/bin/wifi_coex.rs +++ b/examples/src/bin/wifi_coex.rs @@ -26,14 +26,7 @@ use bleps::{ }; use embedded_io::*; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::{print, println}; use esp_wifi::{ ble::controller::BleConnector, @@ -54,11 +47,11 @@ const PASSWORD: &str = env!("PASSWORD"); #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/examples/src/bin/wifi_dhcp.rs b/examples/src/bin/wifi_dhcp.rs index 0ae1adb2191..a02b52dd2b7 100644 --- a/examples/src/bin/wifi_dhcp.rs +++ b/examples/src/bin/wifi_dhcp.rs @@ -13,14 +13,7 @@ use embedded_io::*; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::{print, println}; use esp_wifi::{ current_millis, @@ -47,11 +40,11 @@ const PASSWORD: &str = env!("PASSWORD"); #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/examples/src/bin/wifi_embassy_access_point.rs b/examples/src/bin/wifi_embassy_access_point.rs index d030a2f856f..22e65a8e5bc 100644 --- a/examples/src/bin/wifi_embassy_access_point.rs +++ b/examples/src/bin/wifi_embassy_access_point.rs @@ -17,7 +17,6 @@ use embassy_executor::Spawner; use embassy_net::{ tcp::TcpSocket, - Config, IpListenEndpoint, Ipv4Address, Ipv4Cidr, @@ -27,13 +26,7 @@ use embassy_net::{ }; use embassy_time::{Duration, Timer}; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::{print, println}; use esp_wifi::{ initialize, @@ -62,11 +55,11 @@ macro_rules! mk_static { #[esp_hal_embassy::main] async fn main(spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); @@ -94,7 +87,7 @@ async fn main(spawner: Spawner) -> ! { } } - let config = Config::ipv4_static(StaticConfigV4 { + let config = embassy_net::Config::ipv4_static(StaticConfigV4 { address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 2, 1), 24), gateway: Some(Ipv4Address::from_bytes(&[192, 168, 2, 1])), dns_servers: Default::default(), 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 bf49c244394..42d2d2e43e9 100644 --- a/examples/src/bin/wifi_embassy_access_point_with_sta.rs +++ b/examples/src/bin/wifi_embassy_access_point_with_sta.rs @@ -20,7 +20,6 @@ use embassy_executor::Spawner; use embassy_net::{ tcp::TcpSocket, - Config, IpListenEndpoint, Ipv4Address, Ipv4Cidr, @@ -30,13 +29,7 @@ use embassy_net::{ }; use embassy_time::{Duration, Timer}; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::{print, println}; use esp_wifi::{ initialize, @@ -70,11 +63,11 @@ macro_rules! mk_static { #[esp_hal_embassy::main] async fn main(spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); @@ -102,12 +95,12 @@ async fn main(spawner: Spawner) -> ! { } } - let ap_config = Config::ipv4_static(StaticConfigV4 { + let ap_config = embassy_net::Config::ipv4_static(StaticConfigV4 { address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 2, 1), 24), gateway: Some(Ipv4Address::from_bytes(&[192, 168, 2, 1])), dns_servers: Default::default(), }); - let sta_config = Config::dhcpv4(Default::default()); + let sta_config = embassy_net::Config::dhcpv4(Default::default()); let seed = 1234; // very random, very secure seed diff --git a/examples/src/bin/wifi_embassy_bench.rs b/examples/src/bin/wifi_embassy_bench.rs index d4f216d081a..5a53e8fd4f9 100644 --- a/examples/src/bin/wifi_embassy_bench.rs +++ b/examples/src/bin/wifi_embassy_bench.rs @@ -18,16 +18,10 @@ use embassy_executor::Spawner; use embassy_futures::join::join; -use embassy_net::{tcp::TcpSocket, Config, Ipv4Address, Stack, StackResources}; +use embassy_net::{tcp::TcpSocket, Ipv4Address, Stack, StackResources}; use embassy_time::{with_timeout, Duration, Timer}; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::println; use esp_wifi::{ initialize, @@ -72,11 +66,11 @@ 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 = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let server_address: Ipv4Address = HOST_IP.parse().expect("Invalid HOST_IP address"); @@ -106,7 +100,7 @@ async fn main(spawner: Spawner) -> ! { } } - let config = Config::dhcpv4(Default::default()); + let config = embassy_net::Config::dhcpv4(Default::default()); let seed = 1234; // very random, very secure seed diff --git a/examples/src/bin/wifi_embassy_ble.rs b/examples/src/bin/wifi_embassy_ble.rs index 4692d34f167..282d6e6a17b 100644 --- a/examples/src/bin/wifi_embassy_ble.rs +++ b/examples/src/bin/wifi_embassy_ble.rs @@ -27,11 +27,9 @@ use bleps::{ use embassy_executor::Spawner; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, gpio::{Input, Io, Pull}, - peripherals::*, + prelude::*, rng::Rng, - system::SystemControl, timer::timg::TimerGroup, }; use esp_println::println; @@ -40,11 +38,11 @@ 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 = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); @@ -60,9 +58,9 @@ async fn main(_spawner: Spawner) -> ! { let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); cfg_if::cfg_if! { if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] { - let button = Input::new(io.pins.gpio0, Pull::Down); + let button = Input::new(io.pins.gpio0, Pull::Down); } else { - let button = Input::new(io.pins.gpio9, Pull::Down); + let button = Input::new(io.pins.gpio9, Pull::Down); } } diff --git a/examples/src/bin/wifi_embassy_dhcp.rs b/examples/src/bin/wifi_embassy_dhcp.rs index c92ab081cc3..96d17d926fb 100644 --- a/examples/src/bin/wifi_embassy_dhcp.rs +++ b/examples/src/bin/wifi_embassy_dhcp.rs @@ -14,16 +14,10 @@ #![no_main] use embassy_executor::Spawner; -use embassy_net::{tcp::TcpSocket, Config, Ipv4Address, Stack, StackResources}; +use embassy_net::{tcp::TcpSocket, Ipv4Address, Stack, StackResources}; use embassy_time::{Duration, Timer}; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::println; use esp_wifi::{ initialize, @@ -55,11 +49,11 @@ const PASSWORD: &str = env!("PASSWORD"); #[esp_hal_embassy::main] async fn main(spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); @@ -87,7 +81,7 @@ async fn main(spawner: Spawner) -> ! { } } - let config = Config::dhcpv4(Default::default()); + let config = embassy_net::Config::dhcpv4(Default::default()); let seed = 1234; // very random, very secure seed diff --git a/examples/src/bin/wifi_embassy_esp_now.rs b/examples/src/bin/wifi_embassy_esp_now.rs index cadb06d9532..d14d95e0d95 100644 --- a/examples/src/bin/wifi_embassy_esp_now.rs +++ b/examples/src/bin/wifi_embassy_esp_now.rs @@ -14,13 +14,7 @@ use embassy_executor::Spawner; use embassy_futures::select::{select, Either}; use embassy_time::{Duration, Ticker}; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::println; use esp_wifi::{ esp_now::{PeerInfo, BROADCAST_ADDRESS}, @@ -31,11 +25,11 @@ use esp_wifi::{ #[esp_hal_embassy::main] async fn main(_spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/examples/src/bin/wifi_embassy_esp_now_duplex.rs b/examples/src/bin/wifi_embassy_esp_now_duplex.rs index 51f7987b730..773389ac155 100644 --- a/examples/src/bin/wifi_embassy_esp_now_duplex.rs +++ b/examples/src/bin/wifi_embassy_esp_now_duplex.rs @@ -14,13 +14,7 @@ use embassy_executor::Spawner; use embassy_sync::{blocking_mutex::raw::NoopRawMutex, mutex::Mutex}; use embassy_time::{Duration, Ticker}; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::println; use esp_wifi::{ esp_now::{EspNowManager, EspNowReceiver, EspNowSender, PeerInfo, BROADCAST_ADDRESS}, @@ -41,11 +35,11 @@ macro_rules! mk_static { #[esp_hal_embassy::main] async fn main(spawner: Spawner) -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/examples/src/bin/wifi_esp_now.rs b/examples/src/bin/wifi_esp_now.rs index 9dd365c25a1..938068aaf95 100644 --- a/examples/src/bin/wifi_esp_now.rs +++ b/examples/src/bin/wifi_esp_now.rs @@ -9,14 +9,7 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::println; use esp_wifi::{ current_millis, @@ -28,11 +21,11 @@ use esp_wifi::{ #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/examples/src/bin/wifi_sniffer.rs b/examples/src/bin/wifi_sniffer.rs index 90626327507..2f277af11a0 100644 --- a/examples/src/bin/wifi_sniffer.rs +++ b/examples/src/bin/wifi_sniffer.rs @@ -20,11 +20,8 @@ use critical_section::Mutex; use esp_alloc::heap_allocator; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, prelude::*, rng::Rng, - system::SystemControl, timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer}, }; use esp_println::println; @@ -36,14 +33,15 @@ 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 mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); - let peripherals = Peripherals::take(); // Create a heap allocator, with 32kB of space. heap_allocator!(32_168); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timer0: ErasedTimer = timg0.timer0.into(); let timer = PeriodicTimer::new(timer0); diff --git a/examples/src/bin/wifi_static_ip.rs b/examples/src/bin/wifi_static_ip.rs index f4d86620cc7..2c82dcea886 100644 --- a/examples/src/bin/wifi_static_ip.rs +++ b/examples/src/bin/wifi_static_ip.rs @@ -14,14 +14,7 @@ use embedded_io::*; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rng::Rng, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, rng::Rng, timer::timg::TimerGroup}; use esp_println::{print, println}; use esp_wifi::{ current_millis, @@ -47,11 +40,11 @@ const GATEWAY_IP: &str = env!("GATEWAY_IP"); #[entry] fn main() -> ! { esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/hil-test/tests/aes.rs b/hil-test/tests/aes.rs index 3ef80264711..7e9c694884e 100644 --- a/hil-test/tests/aes.rs +++ b/hil-test/tests/aes.rs @@ -7,7 +7,7 @@ use esp_hal::{ aes::{Aes, Mode}, - peripherals::Peripherals, + prelude::*, }; use hil_test as _; @@ -15,15 +15,6 @@ struct Context<'a> { aes: Aes<'a>, } -impl Context<'_> { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let aes = Aes::new(peripherals.AES); - - Context { aes } - } -} - #[cfg(test)] #[embedded_test::tests] mod tests { @@ -33,7 +24,14 @@ mod tests { #[init] fn init() -> Context<'static> { - Context::init() + let (peripherals, _clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); + let aes = Aes::new(peripherals.AES); + + Context { aes } } #[test] diff --git a/hil-test/tests/aes_dma.rs b/hil-test/tests/aes_dma.rs index 63ab5f49edb..d3dccfe0ac5 100644 --- a/hil-test/tests/aes_dma.rs +++ b/hil-test/tests/aes_dma.rs @@ -14,6 +14,7 @@ use esp_hal::{ dma::{Dma, DmaPriority}, dma_buffers, peripherals::Peripherals, + prelude::*, }; use hil_test as _; @@ -27,12 +28,13 @@ mod tests { use super::*; #[init] - fn init() {} + fn init() -> Peripherals { + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + peripherals + } #[test] - fn test_aes_128_dma_encryption() { - let peripherals = Peripherals::take(); - + fn test_aes_128_dma_encryption(peripherals: Peripherals) { let dma = Dma::new(peripherals.DMA); let dma_channel = dma.channel0; @@ -74,9 +76,7 @@ mod tests { } #[test] - fn test_aes_128_dma_decryption() { - let peripherals = Peripherals::take(); - + fn test_aes_128_dma_decryption(peripherals: Peripherals) { let dma = Dma::new(peripherals.DMA); let dma_channel = dma.channel0; @@ -117,9 +117,7 @@ mod tests { } #[test] - fn test_aes_256_dma_encryption() { - let peripherals = Peripherals::take(); - + fn test_aes_256_dma_encryption(peripherals: Peripherals) { let dma = Dma::new(peripherals.DMA); let dma_channel = dma.channel0; @@ -161,9 +159,7 @@ mod tests { } #[test] - fn test_aes_256_dma_decryption() { - let peripherals = Peripherals::take(); - + fn test_aes_256_dma_decryption(peripherals: Peripherals) { let dma = Dma::new(peripherals.DMA); let dma_channel = dma.channel0; diff --git a/hil-test/tests/clock_monitor.rs b/hil-test/tests/clock_monitor.rs index 938108924f5..724d9165459 100644 --- a/hil-test/tests/clock_monitor.rs +++ b/hil-test/tests/clock_monitor.rs @@ -5,30 +5,13 @@ #![no_std] #![no_main] -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - rtc_cntl::Rtc, - system::SystemControl, -}; +use esp_hal::rtc_cntl::Rtc; use hil_test as _; struct Context<'a> { rtc: Rtc<'a>, } -impl Context<'_> { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - ClockControl::boot_defaults(system.clock_control).freeze(); - - let rtc = Rtc::new(peripherals.LPWR); - - Context { rtc } - } -} - #[cfg(test)] #[embedded_test::tests] mod tests { @@ -36,7 +19,10 @@ mod tests { #[init] fn init() -> Context<'static> { - Context::init() + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); + let rtc = Rtc::new(peripherals.LPWR); + + Context { rtc } } #[test] diff --git a/hil-test/tests/delay.rs b/hil-test/tests/delay.rs index 96e7adcfb32..f171263dc6b 100644 --- a/hil-test/tests/delay.rs +++ b/hil-test/tests/delay.rs @@ -6,25 +6,13 @@ #![no_main] use embedded_hal::delay::DelayNs; -use esp_hal::{clock::ClockControl, delay::Delay, peripherals::Peripherals, system::SystemControl}; +use esp_hal::delay::Delay; use hil_test as _; struct Context { delay: Delay, } -impl Context { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let delay = Delay::new(&clocks); - - Context { delay } - } -} - #[cfg(test)] #[embedded_test::tests] mod tests { @@ -32,7 +20,10 @@ mod tests { #[init] fn init() -> Context { - Context::init() + let (_peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let delay = Delay::new(&clocks); + + Context { delay } } #[test] diff --git a/hil-test/tests/dma_mem2mem.rs b/hil-test/tests/dma_mem2mem.rs index 4609a066b4a..45e9c9ebcae 100644 --- a/hil-test/tests/dma_mem2mem.rs +++ b/hil-test/tests/dma_mem2mem.rs @@ -6,18 +6,29 @@ #![no_main] use esp_hal::{ - clock::ClockControl, - dma::{Dma, DmaError, DmaPriority, Mem2Mem}, + dma::{Channel, Dma, DmaChannel0, DmaError, DmaPriority, Mem2Mem}, dma_buffers, dma_buffers_chunk_size, dma_descriptors, - peripherals::Peripherals, - system::SystemControl, + Blocking, }; use hil_test as _; const DATA_SIZE: usize = 1024 * 10; +cfg_if::cfg_if! { + if #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] { + type DmaPeripheralType = esp_hal::peripherals::SPI2; + } else { + type DmaPeripheralType = esp_hal::peripherals::MEM2MEM1; + } +} + +struct Context { + channel: Channel<'static, DmaChannel0, Blocking>, + dma_peripheral: DmaPeripheralType, +} + #[cfg(test)] #[embedded_test::tests] mod tests { @@ -26,15 +37,8 @@ mod tests { use super::*; #[init] - fn init() {} - - #[test] - fn test_internal_mem2mem() { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let (tx_buffer, tx_descriptors, mut rx_buffer, rx_descriptors) = dma_buffers!(DATA_SIZE); + fn init() -> Context { + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let dma = Dma::new(peripherals.DMA); let channel = dma.channel0.configure(false, DmaPriority::Priority0); @@ -47,8 +51,23 @@ mod tests { } } - let mut mem2mem = - Mem2Mem::new(channel, dma_peripheral, tx_descriptors, rx_descriptors).unwrap(); + Context { + channel, + dma_peripheral, + } + } + + #[test] + fn test_internal_mem2mem(ctx: Context) { + let (tx_buffer, tx_descriptors, mut rx_buffer, rx_descriptors) = dma_buffers!(DATA_SIZE); + + let mut mem2mem = Mem2Mem::new( + ctx.channel, + ctx.dma_peripheral, + tx_descriptors, + rx_descriptors, + ) + .unwrap(); for i in 0..core::mem::size_of_val(tx_buffer) { tx_buffer[i] = (i % 256) as u8; @@ -61,29 +80,15 @@ mod tests { } #[test] - fn test_internal_mem2mem_chunk_size() { + fn test_internal_mem2mem_chunk_size(ctx: Context) { const CHUNK_SIZE: usize = 2048; - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let (tx_buffer, tx_descriptors, mut rx_buffer, rx_descriptors) = dma_buffers_chunk_size!(DATA_SIZE, CHUNK_SIZE); - let dma = Dma::new(peripherals.DMA); - let channel = dma.channel0.configure(false, DmaPriority::Priority0); - - cfg_if::cfg_if! { - if #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] { - let dma_peripheral = peripherals.SPI2; - } else { - let dma_peripheral = peripherals.MEM2MEM1; - } - } - let mut mem2mem = Mem2Mem::new_with_chunk_size( - channel, - dma_peripheral, + ctx.channel, + ctx.dma_peripheral, tx_descriptors, rx_descriptors, CHUNK_SIZE, @@ -101,28 +106,13 @@ mod tests { } #[test] - fn test_mem2mem_errors_zero_tx() { + fn test_mem2mem_errors_zero_tx(ctx: Context) { use esp_hal::dma::CHUNK_SIZE; - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let dma = Dma::new(peripherals.DMA); - let channel = dma.channel0.configure(false, DmaPriority::Priority0); - - cfg_if::cfg_if! { - if #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] { - let dma_peripheral = peripherals.SPI2; - } else { - let dma_peripheral = peripherals.MEM2MEM1; - } - } - let (tx_descriptors, rx_descriptors) = dma_descriptors!(0, 1024); match Mem2Mem::new_with_chunk_size( - channel, - dma_peripheral, + ctx.channel, + ctx.dma_peripheral, tx_descriptors, rx_descriptors, CHUNK_SIZE, @@ -133,28 +123,13 @@ mod tests { } #[test] - fn test_mem2mem_errors_zero_rx() { + fn test_mem2mem_errors_zero_rx(ctx: Context) { use esp_hal::dma::CHUNK_SIZE; - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let dma = Dma::new(peripherals.DMA); - let channel = dma.channel0.configure(false, DmaPriority::Priority0); - - cfg_if::cfg_if! { - if #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] { - let dma_peripheral = peripherals.SPI2; - } else { - let dma_peripheral = peripherals.MEM2MEM1; - } - } - let (tx_descriptors, rx_descriptors) = dma_descriptors!(1024, 0); match Mem2Mem::new_with_chunk_size( - channel, - dma_peripheral, + ctx.channel, + ctx.dma_peripheral, tx_descriptors, rx_descriptors, CHUNK_SIZE, @@ -165,26 +140,11 @@ mod tests { } #[test] - fn test_mem2mem_errors_chunk_size_too_small() { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let dma = Dma::new(peripherals.DMA); - let channel = dma.channel0.configure(false, DmaPriority::Priority0); - - cfg_if::cfg_if! { - if #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] { - let dma_peripheral = peripherals.SPI2; - } else { - let dma_peripheral = peripherals.MEM2MEM1; - } - } - + fn test_mem2mem_errors_chunk_size_too_small(ctx: Context) { let (tx_descriptors, rx_descriptors) = dma_descriptors!(1024, 1024); match Mem2Mem::new_with_chunk_size( - channel, - dma_peripheral, + ctx.channel, + ctx.dma_peripheral, tx_descriptors, rx_descriptors, 0, @@ -195,26 +155,11 @@ mod tests { } #[test] - fn test_mem2mem_errors_chunk_size_too_big() { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let dma = Dma::new(peripherals.DMA); - let channel = dma.channel0.configure(false, DmaPriority::Priority0); - - cfg_if::cfg_if! { - if #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] { - let dma_peripheral = peripherals.SPI2; - } else { - let dma_peripheral = peripherals.MEM2MEM1; - } - } - + fn test_mem2mem_errors_chunk_size_too_big(ctx: Context) { let (tx_descriptors, rx_descriptors) = dma_descriptors!(1024, 1024); match Mem2Mem::new_with_chunk_size( - channel, - dma_peripheral, + ctx.channel, + ctx.dma_peripheral, tx_descriptors, rx_descriptors, 4093, diff --git a/hil-test/tests/ecc.rs b/hil-test/tests/ecc.rs index 2ad0fc923d8..5400ba84147 100644 --- a/hil-test/tests/ecc.rs +++ b/hil-test/tests/ecc.rs @@ -18,7 +18,7 @@ use elliptic_curve::sec1::ToEncodedPoint; use esp_hal::ecc::WorkMode; use esp_hal::{ ecc::{Ecc, EllipticCurve, Error}, - peripherals::Peripherals, + prelude::*, rng::Rng, Blocking, }; @@ -47,16 +47,6 @@ struct Context<'a> { rng: Rng, } -impl Context<'_> { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let ecc = Ecc::new(peripherals.ECC); - let rng = Rng::new(peripherals.RNG); - - Context { ecc, rng } - } -} - #[cfg(test)] #[embedded_test::tests] mod tests { @@ -66,7 +56,16 @@ mod tests { #[init] fn init() -> Context<'static> { - Context::init() + let (peripherals, _clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); + + let ecc = Ecc::new(peripherals.ECC); + let rng = Rng::new(peripherals.RNG); + + Context { ecc, rng } } #[test] diff --git a/hil-test/tests/embassy_interrupt_executor.rs b/hil-test/tests/embassy_interrupt_executor.rs index acb6b2c60ba..67e4f8107ee 100644 --- a/hil-test/tests/embassy_interrupt_executor.rs +++ b/hil-test/tests/embassy_interrupt_executor.rs @@ -10,10 +10,10 @@ use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, signal::Signal}; use esp_hal::{ - clock::ClockControl, - interrupt::Priority, - peripherals::Peripherals, - system::{SoftwareInterrupt, SystemControl}, + interrupt::{ + software::{SoftwareInterrupt, SoftwareInterruptControl}, + Priority, + }, timer::timg::TimerGroup, }; use esp_hal_embassy::InterruptExecutor; @@ -38,18 +38,19 @@ async fn interrupt_driven_task(signal: &'static Signal SoftwareInterrupt<1> { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0); - system.software_interrupt_control.software_interrupt1 + let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); + sw_ints.software_interrupt1 } #[test] diff --git a/hil-test/tests/embassy_timers_executors.rs b/hil-test/tests/embassy_timers_executors.rs index c44605dd7ed..7627b15a4f2 100644 --- a/hil-test/tests/embassy_timers_executors.rs +++ b/hil-test/tests/embassy_timers_executors.rs @@ -9,10 +9,10 @@ use embassy_time::{Duration, Ticker, Timer}; use esp_hal::{ - clock::{ClockControl, Clocks}, + clock::Clocks, + interrupt::software::SoftwareInterruptControl, peripherals::Peripherals, prelude::*, - system::SystemControl, timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer}, }; #[cfg(not(feature = "esp32"))] @@ -109,25 +109,15 @@ mod test_cases { } } -struct Resources { - clocks: Clocks<'static>, - timg0: esp_hal::peripherals::TIMG0, - #[cfg(not(feature = "esp32"))] - systimer: esp_hal::peripherals::SYSTIMER, - software_interrupt_control: esp_hal::system::SoftwareInterruptControl, +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); } -impl Resources { - fn set_up_embassy_with_timg0(self) { - let timg0 = TimerGroup::new(self.timg0, &self.clocks); - esp_hal_embassy::init(&self.clocks, timg0.timer0); - } - - #[cfg(not(feature = "esp32"))] - fn set_up_embassy_with_systimer(self) { - let systimer = SystemTimer::new(self.systimer).split::(); - esp_hal_embassy::init(&self.clocks, systimer.alarm0); - } +#[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); } #[cfg(test)] @@ -137,23 +127,14 @@ mod test { use crate::{test_cases::*, test_helpers::*}; #[init] - fn init() -> Resources { - let peripherals = unsafe { Peripherals::steal() }; - let system = SystemControl::new(peripherals.SYSTEM); - - Resources { - clocks: ClockControl::boot_defaults(system.clock_control).freeze(), - timg0: peripherals.TIMG0, - #[cfg(not(feature = "esp32"))] - systimer: peripherals.SYSTIMER, - software_interrupt_control: system.software_interrupt_control, - } + fn init() -> (Peripherals, Clocks<'static>) { + esp_hal::init(esp_hal::Config::default()) } #[test] #[timeout(3)] - async fn test_one_shot_timg(resources: Resources) { - resources.set_up_embassy_with_timg0(); + async fn test_one_shot_timg((peripherals, clocks): (Peripherals, Clocks<'static>)) { + set_up_embassy_with_timg0(peripherals, clocks); run_test_one_shot_async().await; } @@ -161,16 +142,16 @@ mod test { #[test] #[timeout(3)] #[cfg(not(feature = "esp32"))] - async fn test_one_shot_systimer(resources: Resources) { - resources.set_up_embassy_with_systimer(); + async fn test_one_shot_systimer((peripherals, clocks): (Peripherals, Clocks<'static>)) { + set_up_embassy_with_systimer(peripherals, clocks); run_test_one_shot_async().await; } #[test] #[timeout(3)] - fn test_periodic_timg(resources: Resources) { - let timg0 = TimerGroup::new(resources.timg0, &resources.clocks); + fn test_periodic_timg((peripherals, clocks): (Peripherals, Clocks<'static>)) { + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); run_test_periodic_timer(timg0.timer0); } @@ -178,32 +159,32 @@ mod test { #[test] #[timeout(3)] #[cfg(not(feature = "esp32"))] - fn test_periodic_systimer(resources: Resources) { - let systimer = SystemTimer::new(resources.systimer).split::(); + fn test_periodic_systimer((peripherals, _clocks): (Peripherals, Clocks<'static>)) { + let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); run_test_periodic_timer(systimer.alarm0); } #[test] #[timeout(3)] - fn test_periodic_oneshot_timg(mut resources: Resources) { - let mut timg0 = TimerGroup::new(&mut resources.timg0, &resources.clocks); + fn test_periodic_oneshot_timg((mut peripherals, clocks): (Peripherals, Clocks<'static>)) { + let mut timg0 = TimerGroup::new(&mut peripherals.TIMG0, &clocks); run_test_periodic_timer(&mut timg0.timer0); - let mut timg0 = TimerGroup::new(&mut resources.timg0, &resources.clocks); + let mut timg0 = TimerGroup::new(&mut peripherals.TIMG0, &clocks); run_test_oneshot_timer(&mut timg0.timer0); } #[test] #[timeout(3)] #[cfg(not(feature = "esp32"))] - fn test_periodic_oneshot_systimer(mut resources: Resources) { - let mut systimer = SystemTimer::new(&mut resources.systimer); + fn test_periodic_oneshot_systimer((mut peripherals, _clocks): (Peripherals, Clocks<'static>)) { + let mut systimer = SystemTimer::new(&mut peripherals.SYSTIMER); let unit = FrozenUnit::new(&mut systimer.unit0); let mut alarm: Alarm<'_, Periodic, _, _, _> = Alarm::new(systimer.comparator0, &unit); run_test_periodic_timer(&mut alarm); - let mut systimer = SystemTimer::new(&mut resources.systimer); + let mut systimer = SystemTimer::new(&mut peripherals.SYSTIMER); let unit = FrozenUnit::new(&mut systimer.unit0); let mut alarm: Alarm<'_, Target, _, _, _> = Alarm::new(systimer.comparator0, &unit); run_test_oneshot_timer(&mut alarm); @@ -211,8 +192,8 @@ mod test { #[test] #[timeout(3)] - async fn test_join_timg(resources: Resources) { - resources.set_up_embassy_with_timg0(); + async fn test_join_timg((peripherals, clocks): (Peripherals, Clocks<'static>)) { + set_up_embassy_with_timg0(peripherals, clocks); run_join_test().await; } @@ -220,8 +201,8 @@ mod test { #[test] #[timeout(3)] #[cfg(not(feature = "esp32"))] - async fn test_join_systimer(resources: Resources) { - resources.set_up_embassy_with_systimer(); + async fn test_join_systimer((peripherals, clocks): (Peripherals, Clocks<'static>)) { + set_up_embassy_with_systimer(peripherals, clocks); run_join_test().await; } @@ -230,21 +211,23 @@ mod test { #[test] #[timeout(3)] #[cfg(not(feature = "esp32"))] - async fn test_interrupt_executor(resources: Resources) { - let timg0 = TimerGroup::new(resources.timg0, &resources.clocks); + async fn test_interrupt_executor((peripherals, clocks): (Peripherals, Clocks<'static>)) { + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timer0: ErasedTimer = timg0.timer0.into(); let timer0 = OneShotTimer::new(timer0); - let systimer = SystemTimer::new(resources.systimer).split::(); + let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); let alarm0: ErasedTimer = systimer.alarm0.into(); let timer1 = OneShotTimer::new(alarm0); let timers = mk_static!([OneShotTimer; 2], [timer0, timer1]); - esp_hal_embassy::init(&resources.clocks, timers); + esp_hal_embassy::init(&clocks, timers); + + let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); let executor = mk_static!( InterruptExecutor<2>, - InterruptExecutor::new(resources.software_interrupt_control.software_interrupt2) + InterruptExecutor::new(sw_ints.software_interrupt2) ); #[embassy_executor::task] @@ -283,8 +266,8 @@ mod test { /// Test that timg0 and systimer don't have vastly different tick rates. #[test] #[timeout(3)] - async fn tick_test_timer_tick_rates(resources: Resources) { - resources.set_up_embassy_with_timg0(); + async fn tick_test_timer_tick_rates((peripherals, clocks): (Peripherals, Clocks<'static>)) { + set_up_embassy_with_timg0(peripherals, clocks); // We are retrying 5 times because probe-rs polling RTT may introduce some // jitter. diff --git a/hil-test/tests/get_time.rs b/hil-test/tests/get_time.rs index 31afab56ed5..6f34c6dd6eb 100644 --- a/hil-test/tests/get_time.rs +++ b/hil-test/tests/get_time.rs @@ -7,7 +7,7 @@ #[cfg(esp32)] use esp_hal::clock::Clocks; -use esp_hal::{clock::ClockControl, delay::Delay, peripherals::Peripherals, system::SystemControl}; +use esp_hal::delay::Delay; use hil_test as _; struct Context { @@ -16,22 +16,6 @@ struct Context { clocks: Clocks<'static>, } -impl Context { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let delay = Delay::new(&clocks); - - Context { - delay, - #[cfg(esp32)] - clocks, - } - } -} - fn time_moves_forward_during(ctx: Context, f: F) { let t1 = esp_hal::time::current_time(); f(ctx); @@ -47,7 +31,15 @@ mod tests { #[init] fn init() -> Context { - Context::init() + let (_peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + + let delay = Delay::new(&clocks); + + Context { + delay, + #[cfg(esp32)] + clocks, + } } #[test] diff --git a/hil-test/tests/gpio.rs b/hil-test/tests/gpio.rs index 0e989708d66..f8f5325fede 100644 --- a/hil-test/tests/gpio.rs +++ b/hil-test/tests/gpio.rs @@ -14,12 +14,9 @@ use core::cell::RefCell; use critical_section::Mutex; use esp_hal::{ - clock::ClockControl, delay::Delay, gpio::{AnyPin, Gpio2, Gpio3, GpioPin, Input, Io, Level, Output, Pull}, macros::handler, - peripherals::Peripherals, - system::SystemControl, timer::timg::TimerGroup, InterruptConfigurable, }; @@ -34,28 +31,6 @@ struct Context<'d> { delay: Delay, } -impl<'d> Context<'d> { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - io.set_interrupt_handler(interrupt_handler); - - let delay = Delay::new(&clocks); - - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); - - Context { - io2: Input::new(io.pins.gpio2, Pull::Down), - io3: Output::new(io.pins.gpio3, Level::Low), - delay, - } - } -} - #[handler] pub fn interrupt_handler() { critical_section::with(|cs| { @@ -79,10 +54,21 @@ mod tests { #[init] fn init() -> Context<'static> { - let mut ctx = Context::init(); - // make sure tests don't interfere with each other - ctx.io3.set_low(); - ctx + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + + let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); + io.set_interrupt_handler(interrupt_handler); + + let delay = Delay::new(&clocks); + + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + esp_hal_embassy::init(&clocks, timg0.timer0); + + Context { + io2: Input::new(io.pins.gpio2, Pull::Down), + io3: Output::new(io.pins.gpio3, Level::Low), + delay, + } } #[test] diff --git a/hil-test/tests/i2s.rs b/hil-test/tests/i2s.rs index 4aa833f50c1..219eb91dcbb 100644 --- a/hil-test/tests/i2s.rs +++ b/hil-test/tests/i2s.rs @@ -11,16 +11,13 @@ #![no_main] use esp_hal::{ - clock::ClockControl, delay::Delay, dma::{Dma, DmaPriority}, dma_buffers, gpio::Io, i2s::{DataFormat, I2s, I2sReadDma, I2sWriteDma, Standard}, peripheral::Peripheral, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; use hil_test as _; @@ -52,17 +49,14 @@ impl Iterator for SampleSource { #[cfg(test)] #[embedded_test::tests] mod tests { - use super::*; - #[init] - fn init() {} - #[test] fn test_i2s_loopback() { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + + let peripherals = peripherals; + let clocks = clocks; let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/hil-test/tests/i2s_async.rs b/hil-test/tests/i2s_async.rs index ba5175e988f..7a9aa0a5ffc 100644 --- a/hil-test/tests/i2s_async.rs +++ b/hil-test/tests/i2s_async.rs @@ -12,14 +12,12 @@ #![no_main] use esp_hal::{ - clock::ClockControl, dma::{Dma, DmaChannel0, DmaPriority}, gpio::Io, i2s::{asynch::*, DataFormat, I2s, I2sTx, Standard}, peripheral::Peripheral, - peripherals::{Peripherals, I2S0}, + peripherals::I2S0, prelude::*, - system::SystemControl, Async, }; use hil_test as _; @@ -83,16 +81,14 @@ mod tests { use super::*; - #[init] - async fn init() {} - #[test] async fn test_i2s_loopback() { let spawner = embassy_executor::Spawner::for_current_executor().await; - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + + let peripherals = peripherals; + let clocks = clocks; let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/hil-test/tests/interrupt.rs b/hil-test/tests/interrupt.rs index 105f01290be..8f6d63ea618 100644 --- a/hil-test/tests/interrupt.rs +++ b/hil-test/tests/interrupt.rs @@ -11,10 +11,14 @@ use core::{arch::asm, cell::RefCell}; use critical_section::Mutex; use esp_hal::{ - clock::ClockControl, - interrupt::{self, *}, - peripherals::{Interrupt, Peripherals}, - system::{SoftwareInterrupt, SystemControl}, + interrupt::{ + self, + software::{SoftwareInterrupt, SoftwareInterruptControl}, + CpuInterrupt, + Priority, + }, + peripherals::Interrupt, + prelude::*, }; use hil_test as _; @@ -25,41 +29,6 @@ struct Context { sw0_trigger_addr: u32, } -impl Context { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - - cfg_if::cfg_if! { - if #[cfg(any(feature = "esp32c6", feature = "esp32h2"))] { - let cpu_intr = &peripherals.INTPRI; - } else { - let cpu_intr = &peripherals.SYSTEM; - } - } - - let sw0_trigger_addr = cpu_intr.cpu_intr_from_cpu_0() as *const _ as u32; - - let system = SystemControl::new(peripherals.SYSTEM); - let _clocks = ClockControl::max(system.clock_control).freeze(); - - let sw_int = system.software_interrupt_control; - - critical_section::with(|cs| { - SWINT0 - .borrow_ref_mut(cs) - .replace(sw_int.software_interrupt0) - }); - interrupt::enable_direct( - Interrupt::FROM_CPU_INTR0, - Priority::Priority3, - CpuInterrupt::Interrupt20, - ) - .unwrap(); - - Context { sw0_trigger_addr } - } -} - #[no_mangle] fn interrupt20() { unsafe { asm!("csrrwi x0, 0x7e1, 0 #disable timer") } @@ -95,7 +64,36 @@ mod tests { #[init] fn init() -> Context { - Context::init() + let (peripherals, _clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); + let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); + + cfg_if::cfg_if! { + if #[cfg(any(feature = "esp32c6", feature = "esp32h2"))] { + let cpu_intr = &peripherals.INTPRI; + } else { + let cpu_intr = &peripherals.SYSTEM; + } + } + + let sw0_trigger_addr = cpu_intr.cpu_intr_from_cpu_0() as *const _ as u32; + + critical_section::with(|cs| { + SWINT0 + .borrow_ref_mut(cs) + .replace(sw_ints.software_interrupt0) + }); + interrupt::enable_direct( + Interrupt::FROM_CPU_INTR0, + Priority::Priority3, + CpuInterrupt::Interrupt20, + ) + .unwrap(); + + Context { sw0_trigger_addr } } #[test] diff --git a/hil-test/tests/lcd_cam_i8080.rs b/hil-test/tests/lcd_cam_i8080.rs index 42563ad107e..4237335deb1 100644 --- a/hil-test/tests/lcd_cam_i8080.rs +++ b/hil-test/tests/lcd_cam_i8080.rs @@ -6,20 +6,15 @@ #![no_main] use esp_hal::{ - clock::{ClockControl, Clocks}, + clock::Clocks, dma::{Dma, DmaDescriptor, DmaPriority}, dma_buffers, gpio::DummyPin, lcd_cam::{ - lcd::{ - i8080, - i8080::{Command, TxEightBits, I8080}, - }, + lcd::i8080::{Command, Config, TxEightBits, I8080}, LcdCam, }, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; use hil_test as _; @@ -33,16 +28,19 @@ struct Context<'d> { tx_descriptors: &'static mut [DmaDescriptor], } -impl<'d> Context<'d> { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); +#[cfg(test)] +#[embedded_test::tests] +mod tests { + use super::*; + + #[init] + fn init() -> Context<'static> { + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let dma = Dma::new(peripherals.DMA); let lcd_cam = LcdCam::new(peripherals.LCD_CAM); let (tx_buffer, tx_descriptors, _, _) = dma_buffers!(DATA_SIZE, 0); - Self { + Context { lcd_cam, clocks, dma, @@ -50,17 +48,6 @@ impl<'d> Context<'d> { tx_descriptors, } } -} - -#[cfg(test)] -#[embedded_test::tests] -mod tests { - use super::*; - - #[init] - fn init() -> Context<'static> { - Context::init() - } #[test] fn test_i8080_8bit(ctx: Context<'static>) { @@ -83,7 +70,7 @@ mod tests { ctx.tx_descriptors, pins, 20.MHz(), - i8080::Config::default(), + Config::default(), &ctx.clocks, ); @@ -116,7 +103,7 @@ mod tests { ctx.tx_descriptors, pins, 20.MHz(), - i8080::Config::default(), + Config::default(), &ctx.clocks, ); diff --git a/hil-test/tests/lcd_cam_i8080_async.rs b/hil-test/tests/lcd_cam_i8080_async.rs index 6b89fb767b3..a5b2c9ef487 100644 --- a/hil-test/tests/lcd_cam_i8080_async.rs +++ b/hil-test/tests/lcd_cam_i8080_async.rs @@ -7,20 +7,15 @@ #![no_main] use esp_hal::{ - clock::{ClockControl, Clocks}, + clock::Clocks, dma::{Dma, DmaDescriptor, DmaPriority}, dma_buffers, gpio::DummyPin, lcd_cam::{ - lcd::{ - i8080, - i8080::{Command, TxEightBits, I8080}, - }, + lcd::i8080::{Command, Config, TxEightBits, I8080}, LcdCam, }, - peripherals::Peripherals, prelude::*, - system::SystemControl, }; use hil_test as _; @@ -34,16 +29,20 @@ struct Context<'d> { tx_descriptors: &'static mut [DmaDescriptor], } -impl<'d> Context<'d> { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); +#[cfg(test)] +#[embedded_test::tests(executor = esp_hal_embassy::Executor::new())] +mod tests { + use super::*; + + #[init] + async fn init() -> Context<'static> { + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let dma = Dma::new(peripherals.DMA); let lcd_cam = LcdCam::new_async(peripherals.LCD_CAM); let (tx_buffer, tx_descriptors, _, _) = dma_buffers!(DATA_SIZE, 0); - Self { + Context { lcd_cam, clocks, dma, @@ -51,17 +50,6 @@ impl<'d> Context<'d> { tx_descriptors, } } -} - -#[cfg(test)] -#[embedded_test::tests(executor = esp_hal_embassy::Executor::new())] -mod tests { - use super::*; - - #[init] - async fn init() -> Context<'static> { - Context::init() - } #[test] async fn test_i8080_8bit(ctx: Context<'static>) { @@ -83,7 +71,7 @@ mod tests { ctx.tx_descriptors, pins, 20.MHz(), - i8080::Config::default(), + Config::default(), &ctx.clocks, ); @@ -116,7 +104,7 @@ mod tests { ctx.tx_descriptors, pins, 20.MHz(), - i8080::Config::default(), + Config::default(), &ctx.clocks, ); diff --git a/hil-test/tests/pcnt.rs b/hil-test/tests/pcnt.rs index ec25dff4479..dbf806c17f3 100644 --- a/hil-test/tests/pcnt.rs +++ b/hil-test/tests/pcnt.rs @@ -7,7 +7,14 @@ #![no_std] #![no_main] -use esp_hal::{delay::Delay, gpio::GpioPin, pcnt::Pcnt}; +use esp_hal::{ + delay::Delay, + gpio::{GpioPin, Io, Level, Output, Pull}, + pcnt::{ + channel::{EdgeMode, PcntInputConfig, PcntSource}, + Pcnt, + }, +}; use hil_test as _; struct Context<'d> { @@ -20,22 +27,11 @@ struct Context<'d> { #[cfg(test)] #[embedded_test::tests] mod tests { - use esp_hal::{ - clock::ClockControl, - delay::Delay, - gpio::{Io, Level, Output, Pull}, - pcnt::channel::{EdgeMode, PcntInputConfig, PcntSource}, - peripherals::Peripherals, - system::SystemControl, - }; - use super::*; #[init] fn init() -> Context<'static> { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/hil-test/tests/qspi_read.rs b/hil-test/tests/qspi_read.rs index cae18ef39f7..6abeab451db 100644 --- a/hil-test/tests/qspi_read.rs +++ b/hil-test/tests/qspi_read.rs @@ -13,11 +13,10 @@ #![no_main] use esp_hal::{ - clock::{ClockControl, Clocks}, + clock::Clocks, dma::{Channel, Dma, DmaPriority, DmaRxBuf}, dma_buffers, gpio::{GpioPin, Io, Level, Output}, - peripherals::Peripherals, prelude::*, spi::{ master::{Address, Command, Spi, SpiDma}, @@ -25,7 +24,6 @@ use esp_hal::{ SpiDataMode, SpiMode, }, - system::SystemControl, Blocking, }; use hil_test as _; @@ -101,9 +99,7 @@ mod tests { #[init] fn init() -> Context { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let miso = io.pins.gpio2; diff --git a/hil-test/tests/qspi_write.rs b/hil-test/tests/qspi_write.rs index 70a35d411de..bc2b01f9273 100644 --- a/hil-test/tests/qspi_write.rs +++ b/hil-test/tests/qspi_write.rs @@ -15,7 +15,7 @@ #![no_main] use esp_hal::{ - clock::{ClockControl, Clocks}, + clock::Clocks, dma::{Channel, Dma, DmaPriority, DmaTxBuf}, dma_buffers, gpio::{Io, Pull}, @@ -24,7 +24,6 @@ use esp_hal::{ unit::Unit, Pcnt, }, - peripherals::Peripherals, prelude::*, spi::{ master::{Address, Command, Spi, SpiDma}, @@ -32,7 +31,6 @@ use esp_hal::{ SpiDataMode, SpiMode, }, - system::SystemControl, Blocking, }; use hil_test as _; @@ -112,9 +110,7 @@ mod tests { #[init] fn init() -> Context { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let mosi = io.pins.gpio2; diff --git a/hil-test/tests/qspi_write_read.rs b/hil-test/tests/qspi_write_read.rs index 4d98c7b9519..602a6a964f3 100644 --- a/hil-test/tests/qspi_write_read.rs +++ b/hil-test/tests/qspi_write_read.rs @@ -15,11 +15,10 @@ #![no_main] use esp_hal::{ - clock::{ClockControl, Clocks}, + clock::Clocks, dma::{Channel, Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{GpioPin, Io, Level, Output}, - peripherals::Peripherals, prelude::*, spi::{ master::{Address, Command, Spi, SpiDma}, @@ -27,7 +26,6 @@ use esp_hal::{ SpiDataMode, SpiMode, }, - system::SystemControl, Blocking, }; use hil_test as _; @@ -103,9 +101,7 @@ mod tests { #[init] fn init() -> Context { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let mosi = io.pins.gpio2; diff --git a/hil-test/tests/rmt.rs b/hil-test/tests/rmt.rs index 30359b3707e..722444a348a 100644 --- a/hil-test/tests/rmt.rs +++ b/hil-test/tests/rmt.rs @@ -8,12 +8,9 @@ #![no_main] use esp_hal::{ - clock::ClockControl, gpio::Io, - peripherals::Peripherals, prelude::*, rmt::{PulseCode, Rmt, RxChannel, RxChannelConfig, TxChannel, TxChannelConfig}, - system::SystemControl, }; use hil_test as _; @@ -28,9 +25,7 @@ mod tests { #[test] #[timeout(1)] fn rmt_loopback() { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/hil-test/tests/rsa.rs b/hil-test/tests/rsa.rs index c102dd025a5..389fc01df31 100644 --- a/hil-test/tests/rsa.rs +++ b/hil-test/tests/rsa.rs @@ -7,7 +7,6 @@ use crypto_bigint::{Uint, U1024, U512}; use esp_hal::{ - peripherals::Peripherals, prelude::*, rsa::{ operand_sizes::*, @@ -58,7 +57,7 @@ mod tests { #[init] fn init() -> Context<'static> { - let peripherals = Peripherals::take(); + let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let mut rsa = Rsa::new(peripherals.RSA); nb::block!(rsa.ready()).unwrap(); diff --git a/hil-test/tests/sha.rs b/hil-test/tests/sha.rs index bdaf699d7b7..adc7acc9190 100644 --- a/hil-test/tests/sha.rs +++ b/hil-test/tests/sha.rs @@ -13,12 +13,9 @@ use esp_hal::sha::{Sha384, Sha512}; #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] use esp_hal::sha::{Sha512_224, Sha512_256}; use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, prelude::*, rng::Rng, sha::{Sha, Sha1, Sha256}, - system::SystemControl, Blocking, }; use hil_test as _; @@ -86,6 +83,7 @@ fn assert_digest(input: &[u8]) { } } +#[allow(unused_mut)] fn with_random_data( mut rng: Rng, f: impl Fn( @@ -99,7 +97,6 @@ fn with_random_data( const BUFFER_LEN: usize = 256; let mut sha1_random = [0u8; BUFFER_LEN]; - #[cfg_attr(feature = "esp32", allow(unused_mut))] let mut sha224_random = [0u8; BUFFER_LEN]; let mut sha256_random = [0u8; BUFFER_LEN]; let mut sha384_random = [0u8; BUFFER_LEN]; @@ -159,23 +156,25 @@ fn with_random_data( #[cfg(test)] #[embedded_test::tests] mod tests { + #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] use defmt::assert_eq; use super::*; #[init] fn init() -> Rng { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); cfg_if::cfg_if! { if #[cfg(feature = "esp32")] { // FIXME: max speed fails...? - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let config = esp_hal::Config::default(); } else { - let _clocks = ClockControl::max(system.clock_control).freeze(); + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); } } + let (peripherals, _clocks) = esp_hal::init(config); + Rng::new(peripherals.RNG) } diff --git a/hil-test/tests/spi_full_duplex.rs b/hil-test/tests/spi_full_duplex.rs index 0502f0c1da2..e38ba9833b0 100644 --- a/hil-test/tests/spi_full_duplex.rs +++ b/hil-test/tests/spi_full_duplex.rs @@ -15,12 +15,9 @@ use embedded_hal::spi::SpiBus; use esp_hal::{ - clock::ClockControl, gpio::Io, - peripherals::Peripherals, prelude::*, spi::{master::Spi, FullDuplexMode, SpiMode}, - system::SystemControl, }; use hil_test as _; @@ -37,9 +34,7 @@ mod tests { #[init] fn init() -> Context { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; diff --git a/hil-test/tests/spi_full_duplex_dma.rs b/hil-test/tests/spi_full_duplex_dma.rs index 7810c4de7b2..e1ef46c05ef 100644 --- a/hil-test/tests/spi_full_duplex_dma.rs +++ b/hil-test/tests/spi_full_duplex_dma.rs @@ -14,18 +14,16 @@ #![no_main] use esp_hal::{ - clock::ClockControl, dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::Io, - peripherals::{Peripherals, SPI2}, + peripherals::SPI2, prelude::*, spi::{ master::{Spi, SpiDma}, FullDuplexMode, SpiMode, }, - system::SystemControl, Blocking, }; use hil_test as _; @@ -49,15 +47,12 @@ struct Context { #[embedded_test::tests] mod tests { use defmt::assert_eq; - use esp_hal::dma::{DmaRxBuf, DmaTxBuf}; use super::*; #[init] fn init() -> Context { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; diff --git a/hil-test/tests/spi_full_duplex_dma_async.rs b/hil-test/tests/spi_full_duplex_dma_async.rs index 3dd9bc45998..674ac477e7e 100644 --- a/hil-test/tests/spi_full_duplex_dma_async.rs +++ b/hil-test/tests/spi_full_duplex_dma_async.rs @@ -1,6 +1,6 @@ //! SPI Full Duplex DMA Test //! -//! Folowing pins are used: +//! Following pins are used: //! SCLK GPIO0 //! MOSI GPIO3 //! MISO GPIO6 @@ -22,7 +22,6 @@ use embedded_hal_async::spi::SpiBus; use esp_hal::{ - clock::ClockControl, dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{GpioPin, Io, Level, Output, Pull}, @@ -31,14 +30,13 @@ use esp_hal::{ unit::Unit, Pcnt, }, - peripherals::{Peripherals, SPI2}, + peripherals::SPI2, prelude::*, spi::{ master::{Spi, SpiDmaBus}, FullDuplexMode, SpiMode, }, - system::SystemControl, Async, }; use hil_test as _; @@ -72,9 +70,7 @@ mod tests { #[init] fn init() -> Context { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let pcnt = Pcnt::new(peripherals.PCNT); diff --git a/hil-test/tests/spi_full_duplex_dma_pcnt.rs b/hil-test/tests/spi_full_duplex_dma_pcnt.rs index 50e78fea918..0581e8e5746 100644 --- a/hil-test/tests/spi_full_duplex_dma_pcnt.rs +++ b/hil-test/tests/spi_full_duplex_dma_pcnt.rs @@ -18,7 +18,6 @@ #![no_main] use esp_hal::{ - clock::ClockControl, dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{GpioPin, Io, Level, Output, Pull}, @@ -27,14 +26,13 @@ use esp_hal::{ unit::Unit, Pcnt, }, - peripherals::{Peripherals, SPI2}, + peripherals::SPI2, prelude::*, spi::{ master::{Spi, SpiDma}, FullDuplexMode, SpiMode, }, - system::SystemControl, Blocking, }; use hil_test as _; @@ -66,9 +64,7 @@ mod tests { #[init] fn init() -> Context { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let 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 eda40ba5e55..b8892c79dd2 100644 --- a/hil-test/tests/spi_half_duplex_read.rs +++ b/hil-test/tests/spi_half_duplex_read.rs @@ -14,11 +14,10 @@ #![no_main] use esp_hal::{ - clock::ClockControl, dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{GpioPin, Io, Level, Output}, - peripherals::{Peripherals, SPI2}, + peripherals::SPI2, prelude::*, spi::{ master::{Address, Command, HalfDuplexReadWrite, Spi, SpiDma}, @@ -26,7 +25,6 @@ use esp_hal::{ SpiDataMode, SpiMode, }, - system::SystemControl, Blocking, }; use hil_test as _; @@ -56,9 +54,7 @@ mod tests { #[init] fn init() -> Context { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let 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 196bed37716..5d21e0297bd 100644 --- a/hil-test/tests/spi_half_duplex_write.rs +++ b/hil-test/tests/spi_half_duplex_write.rs @@ -14,7 +14,6 @@ #![no_main] use esp_hal::{ - clock::ClockControl, dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{GpioPin, Io, Pull}, @@ -23,7 +22,7 @@ use esp_hal::{ unit::Unit, Pcnt, }, - peripherals::{Peripherals, SPI2}, + peripherals::SPI2, prelude::*, spi::{ master::{Address, Command, HalfDuplexReadWrite, Spi, SpiDma}, @@ -31,7 +30,6 @@ use esp_hal::{ SpiDataMode, SpiMode, }, - system::SystemControl, Blocking, }; use hil_test as _; @@ -65,9 +63,7 @@ mod tests { #[init] fn init() -> Context { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; diff --git a/hil-test/tests/systimer.rs b/hil-test/tests/systimer.rs index e8360539d85..ffaf473814f 100644 --- a/hil-test/tests/systimer.rs +++ b/hil-test/tests/systimer.rs @@ -11,11 +11,9 @@ use core::cell::RefCell; use critical_section::Mutex; use embedded_hal::delay::DelayNs; use esp_hal::{ - clock::{ClockControl, Clocks}, + clock::Clocks, delay::Delay, - peripherals::Peripherals, prelude::*, - system::SystemControl, timer::systimer::{ Alarm, FrozenUnit, @@ -46,27 +44,6 @@ struct Context { clocks: Clocks<'static>, } -impl Context { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let systimer = SystemTimer::new(peripherals.SYSTIMER); - static UNIT0: StaticCell> = StaticCell::new(); - - let unit0 = UNIT0.init(systimer.unit0); - let frozen_unit = FrozenUnit::new(unit0); - - Context { - clocks, - unit: frozen_unit, - comparator0: systimer.comparator0, - comparator1: systimer.comparator1, - } - } -} - #[handler(priority = esp_hal::interrupt::Priority::min())] fn pass_test_if_called() { critical_section::with(|cs| { @@ -127,7 +104,20 @@ mod tests { #[init] fn init() -> Context { - Context::init() + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + + let systimer = SystemTimer::new(peripherals.SYSTIMER); + static UNIT0: StaticCell> = StaticCell::new(); + + let unit0 = UNIT0.init(systimer.unit0); + let frozen_unit = FrozenUnit::new(unit0); + + Context { + clocks, + unit: frozen_unit, + comparator0: systimer.comparator0, + comparator1: systimer.comparator1, + } } #[test] diff --git a/hil-test/tests/twai.rs b/hil-test/tests/twai.rs index c410c9fd590..fe193c60255 100644 --- a/hil-test/tests/twai.rs +++ b/hil-test/tests/twai.rs @@ -13,11 +13,9 @@ use embedded_hal_02::can::Frame; use esp_hal::{ - clock::ClockControl, gpio::Io, - peripherals::{Peripherals, TWAI0}, + peripherals::TWAI0, prelude::*, - system::SystemControl, twai::{self, filter::SingleStandardFilter, EspTwaiFrame, StandardId, TwaiMode}, Blocking, }; @@ -28,25 +26,28 @@ struct Context { twai: twai::Twai<'static, TWAI0, Blocking>, } -impl Context { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); +#[cfg(test)] +#[embedded_test::tests] +mod tests { + use defmt::assert_eq; + + use super::*; + + #[init] + fn init() -> Context { + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let can_tx_pin = io.pins.gpio2; let can_rx_pin = io.pins.gpio3; - const CAN_BAUDRATE: twai::BaudRate = twai::BaudRate::B1000K; - let mut config = twai::TwaiConfiguration::new( peripherals.TWAI0, can_tx_pin, can_rx_pin, &clocks, - CAN_BAUDRATE, + twai::BaudRate::B1000K, TwaiMode::SelfTest, ); @@ -58,19 +59,6 @@ impl Context { Context { twai } } -} - -#[cfg(test)] -#[embedded_test::tests] -mod tests { - use defmt::assert_eq; - - use super::*; - - #[init] - fn init() -> Context { - Context::init() - } #[test] #[timeout(3)] diff --git a/hil-test/tests/uart.rs b/hil-test/tests/uart.rs index cb87373ffad..f5e0e4e4f1d 100644 --- a/hil-test/tests/uart.rs +++ b/hil-test/tests/uart.rs @@ -13,11 +13,10 @@ use embedded_hal_02::serial::{Read, Write}; use esp_hal::{ - clock::{ClockControl, Clocks}, + clock::Clocks, gpio::Io, - peripherals::{Peripherals, UART1}, + peripherals::UART1, prelude::*, - system::SystemControl, uart::{ClockSource, Uart}, Blocking, }; @@ -29,20 +28,6 @@ struct Context { uart: Uart<'static, UART1, Blocking>, } -impl Context { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - - let uart = Uart::new(peripherals.UART1, &clocks, io.pins.gpio2, io.pins.gpio3).unwrap(); - - Context { clocks, uart } - } -} - #[cfg(test)] #[embedded_test::tests] mod tests { @@ -52,7 +37,13 @@ mod tests { #[init] fn init() -> Context { - Context::init() + let (peripherals, clocks) = esp_hal::init(esp_hal::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(); + + Context { clocks, uart } } #[test] diff --git a/hil-test/tests/uart_async.rs b/hil-test/tests/uart_async.rs index b3cb05612f2..8a5ef5b4cb7 100644 --- a/hil-test/tests/uart_async.rs +++ b/hil-test/tests/uart_async.rs @@ -12,34 +12,13 @@ #![no_std] #![no_main] -use esp_hal::{ - clock::ClockControl, - gpio::Io, - peripherals::{Peripherals, UART0}, - system::SystemControl, - uart::Uart, - Async, -}; +use esp_hal::{gpio::Io, peripherals::UART0, uart::Uart, Async}; use hil_test as _; struct Context { uart: Uart<'static, UART0, Async>, } -impl Context { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - - let uart = - Uart::new_async(peripherals.UART0, &clocks, io.pins.gpio2, io.pins.gpio3).unwrap(); - - Context { uart } - } -} - #[cfg(test)] #[embedded_test::tests(executor = esp_hal_embassy::Executor::new())] mod tests { @@ -49,7 +28,14 @@ mod tests { #[init] async fn init() -> Context { - Context::init() + let (peripherals, clocks) = esp_hal::init(esp_hal::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(); + + Context { uart } } #[test] diff --git a/hil-test/tests/uart_tx_rx.rs b/hil-test/tests/uart_tx_rx.rs index 67a56460663..a6ce3a7825c 100644 --- a/hil-test/tests/uart_tx_rx.rs +++ b/hil-test/tests/uart_tx_rx.rs @@ -12,11 +12,9 @@ #![no_main] use esp_hal::{ - clock::ClockControl, gpio::Io, - peripherals::{Peripherals, UART0, UART1}, + peripherals::{UART0, UART1}, prelude::*, - system::SystemControl, uart::{UartRx, UartTx}, Blocking, }; @@ -28,21 +26,6 @@ struct Context { rx: UartRx<'static, UART1, Blocking>, } -impl Context { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - 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(); - - Context { tx, rx } - } -} - #[cfg(test)] #[embedded_test::tests] mod tests { @@ -52,7 +35,14 @@ mod tests { #[init] fn init() -> Context { - Context::init() + let (peripherals, clocks) = esp_hal::init(esp_hal::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(); + + Context { tx, rx } } #[test] diff --git a/hil-test/tests/uart_tx_rx_async.rs b/hil-test/tests/uart_tx_rx_async.rs index 627cab28aa0..0209a58a06d 100644 --- a/hil-test/tests/uart_tx_rx_async.rs +++ b/hil-test/tests/uart_tx_rx_async.rs @@ -13,10 +13,8 @@ #![no_main] use esp_hal::{ - clock::ClockControl, gpio::Io, - peripherals::{Peripherals, UART0, UART1}, - system::SystemControl, + peripherals::{UART0, UART1}, uart::{UartRx, UartTx}, Async, }; @@ -27,21 +25,6 @@ struct Context { rx: UartRx<'static, UART1, Async>, } -impl Context { - pub fn init() -> Self { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - 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(); - - Context { tx, rx } - } -} - #[cfg(test)] #[embedded_test::tests(executor = esp_hal_embassy::Executor::new())] mod tests { @@ -51,7 +34,14 @@ mod tests { #[init] async fn init() -> Context { - Context::init() + let (peripherals, clocks) = esp_hal::init(esp_hal::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(); + + Context { tx, rx } } #[test] diff --git a/hil-test/tests/usb_serial_jtag.rs b/hil-test/tests/usb_serial_jtag.rs index f343f6023df..7e2216221a0 100644 --- a/hil-test/tests/usb_serial_jtag.rs +++ b/hil-test/tests/usb_serial_jtag.rs @@ -8,20 +8,12 @@ #[cfg(test)] #[embedded_test::tests] mod tests { - use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - system::SystemControl, - timer::timg::TimerGroup, - usb_serial_jtag::UsbSerialJtag, - }; + use esp_hal::{timer::timg::TimerGroup, usb_serial_jtag::UsbSerialJtag}; use hil_test as _; #[test] fn creating_peripheral_does_not_break_debug_connection() { - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); esp_hal_embassy::init(&clocks, timg0.timer0);