Move interrupt related bits out of lib.rs and into the interrupt module (#2613)

* move interrupt related bits out of lib.rs and into the interrupt module

* changelog and migration guide

* review
This commit is contained in:
Scott Mabin 2024-11-27 10:29:32 +00:00 committed by GitHub
parent eec75c8f82
commit 7095576e6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 71 additions and 71 deletions

View File

@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `TimerGroup` `Timer`s are now type erased (#2581) - `TimerGroup` `Timer`s are now type erased (#2581)
- PSRAM is now initialized automatically if `quad-psram` or `octal-psram` is enabled (#2546) - PSRAM is now initialized automatically if `quad-psram` or `octal-psram` is enabled (#2546)
- DMA channels are now available via the `Peripherals` struct, and have been renamed accordingly. (#2545) - DMA channels are now available via the `Peripherals` struct, and have been renamed accordingly. (#2545)
- Moved interrupt related items from lib.rs, moved to the `interrupt` module (#2613)
### Fixed ### Fixed

View File

@ -184,3 +184,12 @@ Analogs of all traits from the above mentioned version are available in `embedde
You might also want to check the full official `embedded-hal` migration guide: You might also want to check the full official `embedded-hal` migration guide:
https://github.com/rust-embedded/embedded-hal/blob/master/docs/migrating-from-0.2-to-1.0.md https://github.com/rust-embedded/embedded-hal/blob/master/docs/migrating-from-0.2-to-1.0.md
## Interrupt related reshuffle
```diff
- use esp_hal::InterruptConfigurable;
- use esp_hal::DEFAULT_INTERRUPT_HANDLER;
+ use esp_hal::interrupt::InterruptConfigurable;
+ use esp_hal::interrupt::DEFAULT_INTERRUPT_HANDLER;
```

View File

@ -24,10 +24,9 @@
//! - This driver has only blocking API //! - This driver has only blocking API
use crate::{ use crate::{
interrupt::InterruptHandler, interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
peripherals::{Interrupt, ASSIST_DEBUG}, peripherals::{Interrupt, ASSIST_DEBUG},
InterruptConfigurable,
}; };
/// The debug assist driver instance. /// The debug assist driver instance.

View File

@ -28,12 +28,11 @@
use core::marker::PhantomData; use core::marker::PhantomData;
use crate::{ use crate::{
interrupt::InterruptHandler, interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
peripherals::{Interrupt, ECC}, peripherals::{Interrupt, ECC},
reg_access::{AlignmentHelper, SocDependentEndianess}, reg_access::{AlignmentHelper, SocDependentEndianess},
system::{self, GenericPeripheralGuard}, system::{self, GenericPeripheralGuard},
InterruptConfigurable,
}; };
/// The ECC Accelerator driver instance /// The ECC Accelerator driver instance

View File

@ -62,7 +62,13 @@ use procmacros::ram;
use crate::peripherals::gpio::{handle_rtcio, handle_rtcio_with_resistors}; use crate::peripherals::gpio::{handle_rtcio, handle_rtcio_with_resistors};
pub use crate::soc::gpio::*; pub use crate::soc::gpio::*;
use crate::{ use crate::{
interrupt::{self, InterruptHandler, Priority}, interrupt::{
self,
InterruptConfigurable,
InterruptHandler,
Priority,
DEFAULT_INTERRUPT_HANDLER,
},
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
peripherals::{ peripherals::{
gpio::{handle_gpio_input, handle_gpio_output, AnyPinInner}, gpio::{handle_gpio_input, handle_gpio_output, AnyPinInner},
@ -71,8 +77,6 @@ use crate::{
IO_MUX, IO_MUX,
}, },
private::{self, Sealed}, private::{self, Sealed},
InterruptConfigurable,
DEFAULT_INTERRUPT_HANDLER,
}; };
pub mod interconnect; pub mod interconnect;

View File

@ -51,7 +51,7 @@ use crate::{
asynch::AtomicWaker, asynch::AtomicWaker,
clock::Clocks, clock::Clocks,
gpio::{interconnect::PeripheralOutput, InputSignal, OutputSignal, Pull}, gpio::{interconnect::PeripheralOutput, InputSignal, OutputSignal, Pull},
interrupt::InterruptHandler, interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
peripherals::{ peripherals::{
i2c0::{RegisterBlock, COMD}, i2c0::{RegisterBlock, COMD},
@ -62,7 +62,6 @@ use crate::{
Async, Async,
Blocking, Blocking,
Cpu, Cpu,
InterruptConfigurable,
Mode, Mode,
}; };

View File

@ -99,12 +99,11 @@ use crate::{
WriteBuffer, WriteBuffer,
}, },
gpio::interconnect::PeripheralOutput, gpio::interconnect::PeripheralOutput,
interrupt::InterruptHandler, interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
system::PeripheralGuard, system::PeripheralGuard,
Async, Async,
Blocking, Blocking,
InterruptConfigurable,
Mode, Mode,
}; };

View File

@ -81,6 +81,38 @@ mod xtensa;
pub mod software; pub mod software;
#[cfg(xtensa)]
#[no_mangle]
extern "C" fn EspDefaultHandler(_level: u32, _interrupt: crate::peripherals::Interrupt) {
panic!("Unhandled level {} interrupt: {:?}", _level, _interrupt);
}
#[cfg(riscv)]
#[no_mangle]
extern "C" fn EspDefaultHandler(_interrupt: crate::peripherals::Interrupt) {
panic!("Unhandled interrupt: {:?}", _interrupt);
}
/// Default (unhandled) interrupt handler
pub const DEFAULT_INTERRUPT_HANDLER: InterruptHandler = InterruptHandler::new(
unsafe { core::mem::transmute::<*const (), extern "C" fn()>(EspDefaultHandler as *const ()) },
Priority::min(),
);
/// Trait implemented by drivers which allow the user to set an
/// [InterruptHandler]
pub trait InterruptConfigurable: crate::private::Sealed {
/// Set the interrupt handler
///
/// Note that this will replace any previously registered interrupt handler.
/// Some peripherals offer a shared interrupt handler for multiple purposes.
/// It's the users duty to honor this.
///
/// You can restore the default/unhandled interrupt handler by using
/// [DEFAULT_INTERRUPT_HANDLER]
fn set_interrupt_handler(&mut self, handler: InterruptHandler);
}
/// An interrupt handler /// An interrupt handler
#[cfg_attr( #[cfg_attr(
multi_core, multi_core,

View File

@ -45,7 +45,7 @@
//! } //! }
//! ``` //! ```
use crate::{interrupt::InterruptHandler, InterruptConfigurable}; use crate::interrupt::{InterruptConfigurable, InterruptHandler};
/// A software interrupt can be triggered by software. /// A software interrupt can be triggered by software.
#[non_exhaustive] #[non_exhaustive]

View File

@ -12,7 +12,7 @@ use core::marker::PhantomData;
use crate::{ use crate::{
asynch::AtomicWaker, asynch::AtomicWaker,
interrupt::InterruptHandler, interrupt::{InterruptConfigurable, InterruptHandler},
lcd_cam::{cam::Cam, lcd::Lcd}, lcd_cam::{cam::Cam, lcd::Lcd},
macros::handler, macros::handler,
peripheral::Peripheral, peripheral::Peripheral,
@ -21,7 +21,6 @@ use crate::{
Async, Async,
Blocking, Blocking,
Cpu, Cpu,
InterruptConfigurable,
}; };
/// Represents a combined LCD and Camera interface. /// Represents a combined LCD and Camera interface.

View File

@ -261,18 +261,6 @@ pub mod trapframe {
// be directly exposed. // be directly exposed.
mod soc; mod soc;
#[cfg(xtensa)]
#[no_mangle]
extern "C" fn EspDefaultHandler(_level: u32, _interrupt: peripherals::Interrupt) {
panic!("Unhandled level {} interrupt: {:?}", _level, _interrupt);
}
#[cfg(riscv)]
#[no_mangle]
extern "C" fn EspDefaultHandler(_interrupt: peripherals::Interrupt) {
panic!("Unhandled interrupt: {:?}", _interrupt);
}
/// A marker trait for initializing drivers in a specific mode. /// A marker trait for initializing drivers in a specific mode.
pub trait Mode: crate::private::Sealed {} pub trait Mode: crate::private::Sealed {}
@ -442,26 +430,6 @@ fn raw_core() -> usize {
(xtensa_lx::get_processor_id() & 0x2000) as usize (xtensa_lx::get_processor_id() & 0x2000) as usize
} }
/// Default (unhandled) interrupt handler
pub const DEFAULT_INTERRUPT_HANDLER: interrupt::InterruptHandler = interrupt::InterruptHandler::new(
unsafe { core::mem::transmute::<*const (), extern "C" fn()>(EspDefaultHandler as *const ()) },
crate::interrupt::Priority::min(),
);
/// Trait implemented by drivers which allow the user to set an
/// [interrupt::InterruptHandler]
pub trait InterruptConfigurable: private::Sealed {
/// Set the interrupt handler
///
/// Note that this will replace any previously registered interrupt handler.
/// Some peripherals offer a shared interrupt handler for multiple purposes.
/// It's the users duty to honor this.
///
/// You can restore the default/unhandled interrupt handler by using
/// [DEFAULT_INTERRUPT_HANDLER]
fn set_interrupt_handler(&mut self, handler: interrupt::InterruptHandler);
}
#[cfg(riscv)] #[cfg(riscv)]
#[export_name = "hal_main"] #[export_name = "hal_main"]
fn hal_main(a0: usize, a1: usize, a2: usize) -> ! { fn hal_main(a0: usize, a1: usize, a2: usize) -> ! {

View File

@ -156,13 +156,12 @@ use crate::{
interconnect::{InputConnection, OutputConnection, PeripheralInput, PeripheralOutput}, interconnect::{InputConnection, OutputConnection, PeripheralInput, PeripheralOutput},
NoPin, NoPin,
}, },
interrupt::InterruptHandler, interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{self, Peripheral}, peripheral::{self, Peripheral},
peripherals::{Interrupt, PARL_IO}, peripherals::{Interrupt, PARL_IO},
system::{self, GenericPeripheralGuard}, system::{self, GenericPeripheralGuard},
Async, Async,
Blocking, Blocking,
InterruptConfigurable,
Mode, Mode,
}; };

View File

@ -95,11 +95,10 @@
use self::unit::Unit; use self::unit::Unit;
use crate::{ use crate::{
interrupt::{self, InterruptHandler}, interrupt::{self, InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
peripherals::{self, Interrupt}, peripherals::{self, Interrupt},
system::GenericPeripheralGuard, system::GenericPeripheralGuard,
InterruptConfigurable,
}; };
pub mod channel; pub mod channel;

View File

@ -36,5 +36,5 @@ mod imp {
pub use crate::timer::timg::TimerGroupInstance as _esp_hal_timer_timg_TimerGroupInstance; pub use crate::timer::timg::TimerGroupInstance as _esp_hal_timer_timg_TimerGroupInstance;
#[cfg(any(systimer, timg0, timg1))] #[cfg(any(systimer, timg0, timg1))]
pub use crate::timer::Timer as _esp_hal_timer_Timer; pub use crate::timer::Timer as _esp_hal_timer_Timer;
pub use crate::{clock::CpuClock, entry, macros::*, InterruptConfigurable}; pub use crate::{clock::CpuClock, entry, interrupt::InterruptConfigurable, macros::*};
} }

View File

@ -228,6 +228,7 @@ use fugit::HertzU32;
use crate::{ use crate::{
asynch::AtomicWaker, asynch::AtomicWaker,
gpio::interconnect::{PeripheralInput, PeripheralOutput}, gpio::interconnect::{PeripheralInput, PeripheralOutput},
interrupt::InterruptConfigurable,
macros::handler, macros::handler,
peripheral::Peripheral, peripheral::Peripheral,
peripherals::Interrupt, peripherals::Interrupt,
@ -235,7 +236,6 @@ use crate::{
system::{self, GenericPeripheralGuard}, system::{self, GenericPeripheralGuard},
Async, Async,
Blocking, Blocking,
InterruptConfigurable,
}; };
/// Errors /// Errors

View File

@ -24,14 +24,13 @@
use core::{marker::PhantomData, ptr::copy_nonoverlapping}; use core::{marker::PhantomData, ptr::copy_nonoverlapping};
use crate::{ use crate::{
interrupt::InterruptHandler, interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
peripherals::{Interrupt, RSA}, peripherals::{Interrupt, RSA},
system::{GenericPeripheralGuard, Peripheral as PeripheralEnable}, system::{GenericPeripheralGuard, Peripheral as PeripheralEnable},
Async, Async,
Blocking, Blocking,
Cpu, Cpu,
InterruptConfigurable,
}; };
#[cfg_attr(esp32s2, path = "esp32sX.rs")] #[cfg_attr(esp32s2, path = "esp32sX.rs")]

View File

@ -49,7 +49,6 @@
//! # use esp_hal::rtc_cntl::Rtc; //! # use esp_hal::rtc_cntl::Rtc;
//! # use esp_hal::rtc_cntl::Rwdt; //! # use esp_hal::rtc_cntl::Rwdt;
//! # use esp_hal::rtc_cntl::RwdtStage; //! # use esp_hal::rtc_cntl::RwdtStage;
//! # use crate::esp_hal::InterruptConfigurable;
//! static RWDT: Mutex<RefCell<Option<Rwdt>>> = Mutex::new(RefCell::new(None)); //! static RWDT: Mutex<RefCell<Option<Rwdt>>> = Mutex::new(RefCell::new(None));
//! //!
//! let mut delay = Delay::new(); //! let mut delay = Delay::new();
@ -126,12 +125,11 @@ use crate::peripherals::{LP_AON, LP_TIMER, LP_WDT};
use crate::rtc_cntl::sleep::{RtcSleepConfig, WakeSource, WakeTriggers}; use crate::rtc_cntl::sleep::{RtcSleepConfig, WakeSource, WakeTriggers};
use crate::{ use crate::{
clock::Clock, clock::Clock,
interrupt::{self, InterruptHandler}, interrupt::{self, InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
peripherals::Interrupt, peripherals::Interrupt,
reset::{SleepSource, WakeupReason}, reset::{SleepSource, WakeupReason},
Cpu, Cpu,
InterruptConfigurable,
}; };
// only include sleep where it's been implemented // only include sleep where it's been implemented
#[cfg(any(esp32, esp32s3, esp32c3, esp32c6, esp32c2))] #[cfg(any(esp32, esp32s3, esp32c3, esp32c6, esp32c2))]

View File

@ -102,7 +102,7 @@ impl<'d> Sha<'d> {
impl crate::private::Sealed for Sha<'_> {} impl crate::private::Sealed for Sha<'_> {}
#[cfg(not(esp32))] #[cfg(not(esp32))]
impl crate::InterruptConfigurable for Sha<'_> { impl crate::interrupt::InterruptConfigurable for Sha<'_> {
fn set_interrupt_handler(&mut self, handler: crate::interrupt::InterruptHandler) { fn set_interrupt_handler(&mut self, handler: crate::interrupt::InterruptHandler) {
for core in crate::Cpu::other() { for core in crate::Cpu::other() {
crate::interrupt::disable(core, Interrupt::SHA); crate::interrupt::disable(core, Interrupt::SHA);

View File

@ -825,9 +825,9 @@ mod dma {
Rx, Rx,
Tx, Tx,
}, },
interrupt::InterruptConfigurable,
Async, Async,
Blocking, Blocking,
InterruptConfigurable,
}; };
/// A DMA capable SPI instance. /// A DMA capable SPI instance.

View File

@ -43,9 +43,8 @@
use fugit::{ExtU64, Instant, MicrosDurationU64}; use fugit::{ExtU64, Instant, MicrosDurationU64};
use crate::{ use crate::{
interrupt::InterruptHandler, interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
InterruptConfigurable,
}; };
#[cfg(systimer)] #[cfg(systimer)]

View File

@ -72,13 +72,12 @@ use super::Error;
use crate::soc::constants::TIMG_DEFAULT_CLK_SRC; use crate::soc::constants::TIMG_DEFAULT_CLK_SRC;
use crate::{ use crate::{
clock::Clocks, clock::Clocks,
interrupt::{self, InterruptHandler}, interrupt::{self, InterruptConfigurable, InterruptHandler},
peripheral::Peripheral, peripheral::Peripheral,
peripherals::{timg0::RegisterBlock, Interrupt, TIMG0}, peripherals::{timg0::RegisterBlock, Interrupt, TIMG0},
private::Sealed, private::Sealed,
sync::{lock, Lock}, sync::{lock, Lock},
system::PeripheralClockControl, system::PeripheralClockControl,
InterruptConfigurable,
}; };
const NUM_TIMG: usize = 1 + cfg!(timg1) as usize; const NUM_TIMG: usize = 1 + cfg!(timg1) as usize;

View File

@ -29,13 +29,13 @@ use core::marker::PhantomData;
use crate::{ use crate::{
gpio::TouchPin, gpio::TouchPin,
interrupt::InterruptConfigurable,
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
peripherals::{RTC_CNTL, SENS, TOUCH}, peripherals::{RTC_CNTL, SENS, TOUCH},
private::{Internal, Sealed}, private::{Internal, Sealed},
rtc_cntl::Rtc, rtc_cntl::Rtc,
Async, Async,
Blocking, Blocking,
InterruptConfigurable,
Mode, Mode,
}; };

View File

@ -131,14 +131,13 @@ use crate::{
OutputSignal, OutputSignal,
Pull, Pull,
}, },
interrupt::InterruptHandler, interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
peripherals::twai0::RegisterBlock, peripherals::twai0::RegisterBlock,
system::PeripheralGuard, system::PeripheralGuard,
twai::filter::SingleStandardFilter, twai::filter::SingleStandardFilter,
Async, Async,
Blocking, Blocking,
InterruptConfigurable,
}; };
pub mod filter; pub mod filter;

View File

@ -229,14 +229,13 @@ use crate::{
OutputSignal, OutputSignal,
Pull, Pull,
}, },
interrupt::InterruptHandler, interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
peripherals::{uart0::RegisterBlock, Interrupt}, peripherals::{uart0::RegisterBlock, Interrupt},
private::Internal, private::Internal,
system::{PeripheralClockControl, PeripheralGuard}, system::{PeripheralClockControl, PeripheralGuard},
Async, Async,
Blocking, Blocking,
InterruptConfigurable,
Mode, Mode,
}; };

View File

@ -132,13 +132,13 @@ use procmacros::handler;
use crate::{ use crate::{
asynch::AtomicWaker, asynch::AtomicWaker,
interrupt::InterruptConfigurable,
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
peripherals::{usb_device::RegisterBlock, Interrupt, USB_DEVICE}, peripherals::{usb_device::RegisterBlock, Interrupt, USB_DEVICE},
system::PeripheralClockControl, system::PeripheralClockControl,
Async, Async,
Blocking, Blocking,
Cpu, Cpu,
InterruptConfigurable,
Mode, Mode,
}; };

View File

@ -12,9 +12,9 @@ use critical_section::Mutex;
use esp_hal::{ use esp_hal::{
delay::Delay, delay::Delay,
gpio::{AnyPin, Input, Io, Level, Output, Pin, Pull}, gpio::{AnyPin, Input, Io, Level, Output, Pin, Pull},
interrupt::InterruptConfigurable,
macros::handler, macros::handler,
timer::timg::TimerGroup, timer::timg::TimerGroup,
InterruptConfigurable,
}; };
use hil_test as _; use hil_test as _;

View File

@ -14,9 +14,9 @@
use embassy_time::{Duration, Timer}; use embassy_time::{Duration, Timer};
use esp_hal::{ use esp_hal::{
gpio::{AnyPin, Input, Io, Level, Output, Pull}, gpio::{AnyPin, Input, Io, Level, Output, Pull},
interrupt::InterruptConfigurable,
macros::handler, macros::handler,
timer::timg::TimerGroup, timer::timg::TimerGroup,
InterruptConfigurable,
}; };
use hil_test as _; use hil_test as _;
use portable_atomic::{AtomicUsize, Ordering}; use portable_atomic::{AtomicUsize, Ordering};