diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-06-08 16:08:40 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-06-08 18:00:48 +0200 |
| commit | 921780e6bfb9bcb2cd087b8aa8b094d792c99fa2 (patch) | |
| tree | bd21fba9800471b860ca44e05567588dcc1afef7 /embassy-rp/src/lib.rs | |
| parent | 87ad66f2b4a5bfd36dfc8d8aad5492e9e3f915e6 (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.rs | 64 |
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; | |||
| 16 | mod float; | 16 | mod float; |
| 17 | pub mod gpio; | 17 | pub mod gpio; |
| 18 | pub mod i2c; | 18 | pub mod i2c; |
| 19 | pub mod interrupt; | ||
| 20 | pub mod multicore; | 19 | pub mod multicore; |
| 21 | pub mod pwm; | 20 | pub mod pwm; |
| 22 | mod reset; | 21 | mod reset; |
| @@ -38,13 +37,74 @@ pub mod relocate; | |||
| 38 | 37 | ||
| 39 | // Reexports | 38 | // Reexports |
| 40 | pub use embassy_cortex_m::executor; | 39 | pub use embassy_cortex_m::executor; |
| 41 | pub use embassy_cortex_m::interrupt::_export::interrupt; | ||
| 42 | pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; | 40 | pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; |
| 43 | #[cfg(feature = "unstable-pac")] | 41 | #[cfg(feature = "unstable-pac")] |
| 44 | pub use rp_pac as pac; | 42 | pub use rp_pac as pac; |
| 45 | #[cfg(not(feature = "unstable-pac"))] | 43 | #[cfg(not(feature = "unstable-pac"))] |
| 46 | pub(crate) use rp_pac as pac; | 44 | pub(crate) use rp_pac as pac; |
| 47 | 45 | ||
| 46 | embassy_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] | ||
| 88 | macro_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 | |||
| 48 | embassy_hal_common::peripherals! { | 108 | embassy_hal_common::peripherals! { |
| 49 | PIN_0, | 109 | PIN_0, |
| 50 | PIN_1, | 110 | PIN_1, |
