diff --git a/esp-hal/src/interrupt/software.rs b/esp-hal/src/interrupt/software.rs index 644bd25b9b..85c644516d 100644 --- a/esp-hal/src/interrupt/software.rs +++ b/esp-hal/src/interrupt/software.rs @@ -1,10 +1,11 @@ //! # Software Interrupts //! -//! The `SoftwareInterruptControl` struct gives access to the available 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. +//! The [`SoftwareInterrupt`] struct allows raising or resetting software +//! interrupts using the [`raise()`][SoftwareInterrupt::raise] and +//! [`reset()`][SoftwareInterrupt::reset] methods. //! //! ## Examples //! @@ -44,7 +45,7 @@ //! } //! ``` -use crate::{interrupt::InterruptHandler, peripherals::SYSTEM, InterruptConfigurable}; +use crate::{interrupt::InterruptHandler, InterruptConfigurable}; /// A software interrupt can be triggered by software. #[non_exhaustive] @@ -69,64 +70,54 @@ impl SoftwareInterrupt { /// 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 }; + 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()); - } + 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 }; + 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()); - } + 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!(), } } diff --git a/esp-hal/src/lib.rs b/esp-hal/src/lib.rs index a8cbe70882..3e46356f9e 100644 --- a/esp-hal/src/lib.rs +++ b/esp-hal/src/lib.rs @@ -102,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. //! @@ -642,6 +642,8 @@ use crate::{ }; /// Initialize the system. +/// +/// This function sets up the CPU clock and returns the peripherals and clocks. pub fn init(clock_config: CpuClock) -> (Peripherals, Clocks<'static>) { let peripherals = Peripherals::take(); let clocks = ClockControl::new(clock_config).freeze();