diff options
| author | Matteo Meluzzi <[email protected]> | 2025-10-02 10:53:31 +0200 |
|---|---|---|
| committer | Matteo Meluzzi <[email protected]> | 2025-10-02 10:53:31 +0200 |
| commit | 828a8df18d04877df1f55f04354980b28ff2f2f8 (patch) | |
| tree | c4fa405f5eba7a14b6d435d6cc746c9e0dc52632 /embassy-nxp/src/lib.rs | |
| parent | 176649e71ad442ca9856af6c11989b0b2f228c4b (diff) | |
| parent | 194a721d0eab929a2af0a2a4e45ca8e70e0d3f0a (diff) | |
Merge branch 'main' into 17-add-support-for-boot-protocol
Diffstat (limited to 'embassy-nxp/src/lib.rs')
| -rw-r--r-- | embassy-nxp/src/lib.rs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/embassy-nxp/src/lib.rs b/embassy-nxp/src/lib.rs index 74142a10b..f0f0afb6c 100644 --- a/embassy-nxp/src/lib.rs +++ b/embassy-nxp/src/lib.rs | |||
| @@ -3,6 +3,8 @@ | |||
| 3 | // This mod MUST go first, so that the others see its macros. | 3 | // This mod MUST go first, so that the others see its macros. |
| 4 | pub(crate) mod fmt; | 4 | pub(crate) mod fmt; |
| 5 | 5 | ||
| 6 | #[cfg(feature = "lpc55-core0")] | ||
| 7 | pub mod dma; | ||
| 6 | pub mod gpio; | 8 | pub mod gpio; |
| 7 | #[cfg(feature = "lpc55-core0")] | 9 | #[cfg(feature = "lpc55-core0")] |
| 8 | pub mod pint; | 10 | pub mod pint; |
| @@ -20,6 +22,9 @@ mod time_driver; | |||
| 20 | #[cfg_attr(feature = "mimxrt1062", path = "chips/mimxrt1062.rs")] | 22 | #[cfg_attr(feature = "mimxrt1062", path = "chips/mimxrt1062.rs")] |
| 21 | mod chip; | 23 | mod chip; |
| 22 | 24 | ||
| 25 | // TODO: Remove when this module is implemented for other chips | ||
| 26 | #[cfg(feature = "lpc55-core0")] | ||
| 27 | pub use chip::interrupt; | ||
| 23 | #[cfg(feature = "unstable-pac")] | 28 | #[cfg(feature = "unstable-pac")] |
| 24 | pub use chip::pac; | 29 | pub use chip::pac; |
| 25 | #[cfg(not(feature = "unstable-pac"))] | 30 | #[cfg(not(feature = "unstable-pac"))] |
| @@ -27,6 +32,67 @@ pub(crate) use chip::pac; | |||
| 27 | pub use chip::{peripherals, Peripherals}; | 32 | pub use chip::{peripherals, Peripherals}; |
| 28 | pub use embassy_hal_internal::{Peri, PeripheralType}; | 33 | pub use embassy_hal_internal::{Peri, PeripheralType}; |
| 29 | 34 | ||
| 35 | /// Macro to bind interrupts to handlers. | ||
| 36 | /// (Copied from `embassy-rp`) | ||
| 37 | /// This defines the right interrupt handlers, and creates a unit struct (like `struct Irqs;`) | ||
| 38 | /// and implements the right [`Binding`]s for it. You can pass this struct to drivers to | ||
| 39 | /// prove at compile-time that the right interrupts have been bound. | ||
| 40 | /// | ||
| 41 | /// Example of how to bind one interrupt: | ||
| 42 | /// | ||
| 43 | /// ```rust,ignore | ||
| 44 | /// use embassy_nxp::{bind_interrupts, usart, peripherals}; | ||
| 45 | /// | ||
| 46 | /// bind_interrupts!( | ||
| 47 | /// /// Binds the USART Interrupts. | ||
| 48 | /// struct Irqs { | ||
| 49 | /// FLEXCOMM0 => usart::InterruptHandler<peripherals::USART0>; | ||
| 50 | /// } | ||
| 51 | /// ); | ||
| 52 | /// ``` | ||
| 53 | #[macro_export] | ||
| 54 | macro_rules! bind_interrupts { | ||
| 55 | ($(#[$attr:meta])* $vis:vis struct $name:ident { | ||
| 56 | $( | ||
| 57 | $(#[cfg($cond_irq:meta)])? | ||
| 58 | $irq:ident => $( | ||
| 59 | $(#[cfg($cond_handler:meta)])? | ||
| 60 | $handler:ty | ||
| 61 | ),*; | ||
| 62 | )* | ||
| 63 | }) => { | ||
| 64 | #[derive(Copy, Clone)] | ||
| 65 | $(#[$attr])* | ||
| 66 | $vis struct $name; | ||
| 67 | |||
| 68 | $( | ||
| 69 | #[allow(non_snake_case)] | ||
| 70 | #[no_mangle] | ||
| 71 | $(#[cfg($cond_irq)])? | ||
| 72 | unsafe extern "C" fn $irq() { | ||
| 73 | unsafe { | ||
| 74 | $( | ||
| 75 | $(#[cfg($cond_handler)])? | ||
| 76 | <$handler as $crate::interrupt::typelevel::Handler<$crate::interrupt::typelevel::$irq>>::on_interrupt(); | ||
| 77 | |||
| 78 | )* | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | $(#[cfg($cond_irq)])? | ||
| 83 | $crate::bind_interrupts!(@inner | ||
| 84 | $( | ||
| 85 | $(#[cfg($cond_handler)])? | ||
| 86 | unsafe impl $crate::interrupt::typelevel::Binding<$crate::interrupt::typelevel::$irq, $handler> for $name {} | ||
| 87 | )* | ||
| 88 | ); | ||
| 89 | )* | ||
| 90 | }; | ||
| 91 | (@inner $($t:tt)*) => { | ||
| 92 | $($t)* | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 30 | /// Initialize the `embassy-nxp` HAL with the provided configuration. | 96 | /// Initialize the `embassy-nxp` HAL with the provided configuration. |
| 31 | /// | 97 | /// |
| 32 | /// This returns the peripheral singletons that can be used for creating drivers. | 98 | /// This returns the peripheral singletons that can be used for creating drivers. |
| @@ -92,6 +158,9 @@ pub fn init(_config: config::Config) -> Peripherals { | |||
| 92 | #[cfg(feature = "_time_driver")] | 158 | #[cfg(feature = "_time_driver")] |
| 93 | time_driver::init(); | 159 | time_driver::init(); |
| 94 | 160 | ||
| 161 | #[cfg(feature = "lpc55-core0")] | ||
| 162 | dma::init(); | ||
| 163 | |||
| 95 | peripherals | 164 | peripherals |
| 96 | } | 165 | } |
| 97 | 166 | ||
| @@ -133,5 +202,8 @@ macro_rules! impl_mode { | |||
| 133 | 202 | ||
| 134 | /// Blocking mode. | 203 | /// Blocking mode. |
| 135 | pub struct Blocking; | 204 | pub struct Blocking; |
| 205 | /// Asynchronous mode. | ||
| 206 | pub struct Async; | ||
| 136 | 207 | ||
| 137 | impl_mode!(Blocking); | 208 | impl_mode!(Blocking); |
| 209 | impl_mode!(Async); | ||
