fix + allow both conditions on the irq and the handlers

This commit is contained in:
Dinu Blanovschi 2024-10-22 15:43:28 +02:00
parent 3279c19eee
commit ccd635f0dc

View File

@ -165,22 +165,31 @@ pub use crate::_generated::interrupt;
// developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`. // developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`.
#[macro_export] #[macro_export]
macro_rules! bind_interrupts { macro_rules! bind_interrupts {
($vis:vis struct $name:ident { $($(#[cfg($cond:meta)])? $irq:ident => $($handler:ty),*;)* }) => { ($vis:vis struct $name:ident {
$(
$(#[cfg($cond_irq:meta)])?
$irq:ident => $(
$(#[cfg($cond_handler:meta)])?
$handler:ty
),*;
)*
}) => {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
$vis struct $name; $vis struct $name;
$( $(
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[no_mangle] #[no_mangle]
$(#[cfg($cond_irq)])?
unsafe extern "C" fn $irq() { unsafe extern "C" fn $irq() {
$( $(
$(#[cfg($cond)])? $(#[cfg($cond_handler)])?
<$handler as $crate::interrupt::typelevel::Handler<$crate::interrupt::typelevel::$irq>>::on_interrupt(); <$handler as $crate::interrupt::typelevel::Handler<$crate::interrupt::typelevel::$irq>>::on_interrupt();
)* )*
} }
$( $(
$(#[cfg($cond)])? $(#[cfg(all($cond_irq, $cond_handler))])?
unsafe impl $crate::interrupt::typelevel::Binding<$crate::interrupt::typelevel::$irq, $handler> for $name {} unsafe impl $crate::interrupt::typelevel::Binding<$crate::interrupt::typelevel::$irq, $handler> for $name {}
)* )*
)* )*