Skip to content

Commit

Permalink
Move interrupt related bits out of lib.rs and into the interrupt modu…
Browse files Browse the repository at this point in the history
…le (#2613)

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

* changelog and migration guide

* review
  • Loading branch information
MabezDev authored Nov 27, 2024
1 parent eec75c8 commit 7095576
Show file tree
Hide file tree
Showing 27 changed files with 71 additions and 71 deletions.
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- 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)
- Moved interrupt related items from lib.rs, moved to the `interrupt` module (#2613)

### Fixed

Expand Down
9 changes: 9 additions & 0 deletions esp-hal/MIGRATING-0.22.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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;
```
3 changes: 1 addition & 2 deletions esp-hal/src/assist_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
//! - This driver has only blocking API
use crate::{
interrupt::InterruptHandler,
interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef},
peripherals::{Interrupt, ASSIST_DEBUG},
InterruptConfigurable,
};

/// The debug assist driver instance.
Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
use core::marker::PhantomData;

use crate::{
interrupt::InterruptHandler,
interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef},
peripherals::{Interrupt, ECC},
reg_access::{AlignmentHelper, SocDependentEndianess},
system::{self, GenericPeripheralGuard},
InterruptConfigurable,
};

/// The ECC Accelerator driver instance
Expand Down
10 changes: 7 additions & 3 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ use procmacros::ram;
use crate::peripherals::gpio::{handle_rtcio, handle_rtcio_with_resistors};
pub use crate::soc::gpio::*;
use crate::{
interrupt::{self, InterruptHandler, Priority},
interrupt::{
self,
InterruptConfigurable,
InterruptHandler,
Priority,
DEFAULT_INTERRUPT_HANDLER,
},
peripheral::{Peripheral, PeripheralRef},
peripherals::{
gpio::{handle_gpio_input, handle_gpio_output, AnyPinInner},
Expand All @@ -71,8 +77,6 @@ use crate::{
IO_MUX,
},
private::{self, Sealed},
InterruptConfigurable,
DEFAULT_INTERRUPT_HANDLER,
};

pub mod interconnect;
Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/i2c/master/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use crate::{
asynch::AtomicWaker,
clock::Clocks,
gpio::{interconnect::PeripheralOutput, InputSignal, OutputSignal, Pull},
interrupt::InterruptHandler,
interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef},
peripherals::{
i2c0::{RegisterBlock, COMD},
Expand All @@ -62,7 +62,6 @@ use crate::{
Async,
Blocking,
Cpu,
InterruptConfigurable,
Mode,
};

Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/i2s/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ use crate::{
WriteBuffer,
},
gpio::interconnect::PeripheralOutput,
interrupt::InterruptHandler,
interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef},
system::PeripheralGuard,
Async,
Blocking,
InterruptConfigurable,
Mode,
};

Expand Down
32 changes: 32 additions & 0 deletions esp-hal/src/interrupt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,38 @@ mod xtensa;

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
#[cfg_attr(
multi_core,
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/interrupt/software.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
//! }
//! ```
use crate::{interrupt::InterruptHandler, InterruptConfigurable};
use crate::interrupt::{InterruptConfigurable, InterruptHandler};

/// A software interrupt can be triggered by software.
#[non_exhaustive]
Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/lcd_cam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use core::marker::PhantomData;

use crate::{
asynch::AtomicWaker,
interrupt::InterruptHandler,
interrupt::{InterruptConfigurable, InterruptHandler},
lcd_cam::{cam::Cam, lcd::Lcd},
macros::handler,
peripheral::Peripheral,
Expand All @@ -21,7 +21,6 @@ use crate::{
Async,
Blocking,
Cpu,
InterruptConfigurable,
};

/// Represents a combined LCD and Camera interface.
Expand Down
32 changes: 0 additions & 32 deletions esp-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,6 @@ pub mod trapframe {
// be directly exposed.
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.
pub trait Mode: crate::private::Sealed {}

Expand Down Expand Up @@ -442,26 +430,6 @@ fn raw_core() -> 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)]
#[export_name = "hal_main"]
fn hal_main(a0: usize, a1: usize, a2: usize) -> ! {
Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/parl_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,12 @@ use crate::{
interconnect::{InputConnection, OutputConnection, PeripheralInput, PeripheralOutput},
NoPin,
},
interrupt::InterruptHandler,
interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{self, Peripheral},
peripherals::{Interrupt, PARL_IO},
system::{self, GenericPeripheralGuard},
Async,
Blocking,
InterruptConfigurable,
Mode,
};

Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/pcnt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@
use self::unit::Unit;
use crate::{
interrupt::{self, InterruptHandler},
interrupt::{self, InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef},
peripherals::{self, Interrupt},
system::GenericPeripheralGuard,
InterruptConfigurable,
};

pub mod channel;
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ mod imp {
pub use crate::timer::timg::TimerGroupInstance as _esp_hal_timer_timg_TimerGroupInstance;
#[cfg(any(systimer, timg0, timg1))]
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::*};
}
2 changes: 1 addition & 1 deletion esp-hal/src/rmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ use fugit::HertzU32;
use crate::{
asynch::AtomicWaker,
gpio::interconnect::{PeripheralInput, PeripheralOutput},
interrupt::InterruptConfigurable,
macros::handler,
peripheral::Peripheral,
peripherals::Interrupt,
soc::constants,
system::{self, GenericPeripheralGuard},
Async,
Blocking,
InterruptConfigurable,
};

/// Errors
Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/rsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
use core::{marker::PhantomData, ptr::copy_nonoverlapping};

use crate::{
interrupt::InterruptHandler,
interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef},
peripherals::{Interrupt, RSA},
system::{GenericPeripheralGuard, Peripheral as PeripheralEnable},
Async,
Blocking,
Cpu,
InterruptConfigurable,
};

#[cfg_attr(esp32s2, path = "esp32sX.rs")]
Expand Down
4 changes: 1 addition & 3 deletions esp-hal/src/rtc_cntl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
//! # use esp_hal::rtc_cntl::Rtc;
//! # use esp_hal::rtc_cntl::Rwdt;
//! # use esp_hal::rtc_cntl::RwdtStage;
//! # use crate::esp_hal::InterruptConfigurable;
//! static RWDT: Mutex<RefCell<Option<Rwdt>>> = Mutex::new(RefCell::new(None));
//!
//! let mut delay = Delay::new();
Expand Down Expand Up @@ -126,12 +125,11 @@ use crate::peripherals::{LP_AON, LP_TIMER, LP_WDT};
use crate::rtc_cntl::sleep::{RtcSleepConfig, WakeSource, WakeTriggers};
use crate::{
clock::Clock,
interrupt::{self, InterruptHandler},
interrupt::{self, InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef},
peripherals::Interrupt,
reset::{SleepSource, WakeupReason},
Cpu,
InterruptConfigurable,
};
// only include sleep where it's been implemented
#[cfg(any(esp32, esp32s3, esp32c3, esp32c6, esp32c2))]
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/sha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<'d> Sha<'d> {
impl crate::private::Sealed for Sha<'_> {}

#[cfg(not(esp32))]
impl crate::InterruptConfigurable for Sha<'_> {
impl crate::interrupt::InterruptConfigurable for Sha<'_> {
fn set_interrupt_handler(&mut self, handler: crate::interrupt::InterruptHandler) {
for core in crate::Cpu::other() {
crate::interrupt::disable(core, Interrupt::SHA);
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/spi/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,9 +825,9 @@ mod dma {
Rx,
Tx,
},
interrupt::InterruptConfigurable,
Async,
Blocking,
InterruptConfigurable,
};

/// A DMA capable SPI instance.
Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/timer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@
use fugit::{ExtU64, Instant, MicrosDurationU64};

use crate::{
interrupt::InterruptHandler,
interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef},
InterruptConfigurable,
};

#[cfg(systimer)]
Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/timer/timg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ use super::Error;
use crate::soc::constants::TIMG_DEFAULT_CLK_SRC;
use crate::{
clock::Clocks,
interrupt::{self, InterruptHandler},
interrupt::{self, InterruptConfigurable, InterruptHandler},
peripheral::Peripheral,
peripherals::{timg0::RegisterBlock, Interrupt, TIMG0},
private::Sealed,
sync::{lock, Lock},
system::PeripheralClockControl,
InterruptConfigurable,
};

const NUM_TIMG: usize = 1 + cfg!(timg1) as usize;
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ use core::marker::PhantomData;

use crate::{
gpio::TouchPin,
interrupt::InterruptConfigurable,
peripheral::{Peripheral, PeripheralRef},
peripherals::{RTC_CNTL, SENS, TOUCH},
private::{Internal, Sealed},
rtc_cntl::Rtc,
Async,
Blocking,
InterruptConfigurable,
Mode,
};

Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/twai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,13 @@ use crate::{
OutputSignal,
Pull,
},
interrupt::InterruptHandler,
interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef},
peripherals::twai0::RegisterBlock,
system::PeripheralGuard,
twai::filter::SingleStandardFilter,
Async,
Blocking,
InterruptConfigurable,
};

pub mod filter;
Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,13 @@ use crate::{
OutputSignal,
Pull,
},
interrupt::InterruptHandler,
interrupt::{InterruptConfigurable, InterruptHandler},
peripheral::{Peripheral, PeripheralRef},
peripherals::{uart0::RegisterBlock, Interrupt},
private::Internal,
system::{PeripheralClockControl, PeripheralGuard},
Async,
Blocking,
InterruptConfigurable,
Mode,
};

Expand Down
Loading

0 comments on commit 7095576

Please sign in to comment.