aboutsummaryrefslogtreecommitdiff
path: root/embassy-nxp/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-nxp/src/lib.rs')
-rw-r--r--embassy-nxp/src/lib.rs72
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.
4pub(crate) mod fmt; 4pub(crate) mod fmt;
5 5
6#[cfg(feature = "lpc55-core0")]
7pub mod dma;
6pub mod gpio; 8pub mod gpio;
7#[cfg(feature = "lpc55-core0")] 9#[cfg(feature = "lpc55-core0")]
8pub mod pint; 10pub 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")]
21mod chip; 23mod chip;
22 24
25// TODO: Remove when this module is implemented for other chips
26#[cfg(feature = "lpc55-core0")]
27pub use chip::interrupt;
23#[cfg(feature = "unstable-pac")] 28#[cfg(feature = "unstable-pac")]
24pub use chip::pac; 29pub use chip::pac;
25#[cfg(not(feature = "unstable-pac"))] 30#[cfg(not(feature = "unstable-pac"))]
@@ -27,6 +32,67 @@ pub(crate) use chip::pac;
27pub use chip::{peripherals, Peripherals}; 32pub use chip::{peripherals, Peripherals};
28pub use embassy_hal_internal::{Peri, PeripheralType}; 33pub 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]
54macro_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.
135pub struct Blocking; 204pub struct Blocking;
205/// Asynchronous mode.
206pub struct Async;
136 207
137impl_mode!(Blocking); 208impl_mode!(Blocking);
209impl_mode!(Async);