aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp/src/lib.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-06-08 16:08:40 +0200
committerDario Nieuwenhuis <[email protected]>2023-06-08 18:00:48 +0200
commit921780e6bfb9bcb2cd087b8aa8b094d792c99fa2 (patch)
treebd21fba9800471b860ca44e05567588dcc1afef7 /embassy-rp/src/lib.rs
parent87ad66f2b4a5bfd36dfc8d8aad5492e9e3f915e6 (diff)
Make interrupt module more standard.
- Move typelevel interrupts to a special-purpose mod: `embassy_xx::interrupt::typelevel`. - Reexport the PAC interrupt enum in `embassy_xx::interrupt`. This has a few advantages: - The `embassy_xx::interrupt` module is now more "standard". - It works with `cortex-m` functions for manipulating interrupts, for example. - It works with RTIC. - the interrupt enum allows holding value that can be "any interrupt at runtime", this can't be done with typelevel irqs. - When "const-generics on enums" is stable, we can remove the typelevel interrupts without disruptive changes to `embassy_xx::interrupt`.
Diffstat (limited to 'embassy-rp/src/lib.rs')
-rw-r--r--embassy-rp/src/lib.rs64
1 files changed, 62 insertions, 2 deletions
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs
index 4e4542d70..70a410ef9 100644
--- a/embassy-rp/src/lib.rs
+++ b/embassy-rp/src/lib.rs
@@ -16,7 +16,6 @@ pub mod flash;
16mod float; 16mod float;
17pub mod gpio; 17pub mod gpio;
18pub mod i2c; 18pub mod i2c;
19pub mod interrupt;
20pub mod multicore; 19pub mod multicore;
21pub mod pwm; 20pub mod pwm;
22mod reset; 21mod reset;
@@ -38,13 +37,74 @@ pub mod relocate;
38 37
39// Reexports 38// Reexports
40pub use embassy_cortex_m::executor; 39pub use embassy_cortex_m::executor;
41pub use embassy_cortex_m::interrupt::_export::interrupt;
42pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; 40pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
43#[cfg(feature = "unstable-pac")] 41#[cfg(feature = "unstable-pac")]
44pub use rp_pac as pac; 42pub use rp_pac as pac;
45#[cfg(not(feature = "unstable-pac"))] 43#[cfg(not(feature = "unstable-pac"))]
46pub(crate) use rp_pac as pac; 44pub(crate) use rp_pac as pac;
47 45
46embassy_cortex_m::interrupt_mod!(
47 TIMER_IRQ_0,
48 TIMER_IRQ_1,
49 TIMER_IRQ_2,
50 TIMER_IRQ_3,
51 PWM_IRQ_WRAP,
52 USBCTRL_IRQ,
53 XIP_IRQ,
54 PIO0_IRQ_0,
55 PIO0_IRQ_1,
56 PIO1_IRQ_0,
57 PIO1_IRQ_1,
58 DMA_IRQ_0,
59 DMA_IRQ_1,
60 IO_IRQ_BANK0,
61 IO_IRQ_QSPI,
62 SIO_IRQ_PROC0,
63 SIO_IRQ_PROC1,
64 CLOCKS_IRQ,
65 SPI0_IRQ,
66 SPI1_IRQ,
67 UART0_IRQ,
68 UART1_IRQ,
69 ADC_IRQ_FIFO,
70 I2C0_IRQ,
71 I2C1_IRQ,
72 RTC_IRQ,
73 SWI_IRQ_0,
74 SWI_IRQ_1,
75 SWI_IRQ_2,
76 SWI_IRQ_3,
77 SWI_IRQ_4,
78 SWI_IRQ_5,
79);
80
81/// Macro to bind interrupts to handlers.
82///
83/// This defines the right interrupt handlers, and creates a unit struct (like `struct Irqs;`)
84/// and implements the right [`Binding`]s for it. You can pass this struct to drivers to
85/// prove at compile-time that the right interrupts have been bound.
86// developer note: this macro can't be in `embassy-cortex-m` due to the use of `$crate`.
87#[macro_export]
88macro_rules! bind_interrupts {
89 ($vis:vis struct $name:ident { $($irq:ident => $($handler:ty),*;)* }) => {
90 $vis struct $name;
91
92 $(
93 #[allow(non_snake_case)]
94 #[no_mangle]
95 unsafe extern "C" fn $irq() {
96 $(
97 <$handler as $crate::interrupt::typelevel::Handler<$crate::interrupt::typelevel::$irq>>::on_interrupt();
98 )*
99 }
100
101 $(
102 unsafe impl $crate::interrupt::typelevel::Binding<$crate::interrupt::typelevel::$irq, $handler> for $name {}
103 )*
104 )*
105 };
106}
107
48embassy_hal_common::peripherals! { 108embassy_hal_common::peripherals! {
49 PIN_0, 109 PIN_0,
50 PIN_1, 110 PIN_1,