From 9ce5451e537a90426375ed19ab003a882a3e8ae2 Mon Sep 17 00:00:00 2001 From: Justin Beaurivage Date: Sun, 10 Dec 2023 21:39:41 -0500 Subject: [PATCH] Guart single/multiple interrupt sources in interrupt_binding macro --- hal/src/async_hal/interrupts.rs | 26 ++++++++++++++++++++++---- hal/src/async_hal/mod.rs | 10 +++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/hal/src/async_hal/interrupts.rs b/hal/src/async_hal/interrupts.rs index 78dcf3dfea7..802474ec758 100644 --- a/hal/src/async_hal/interrupts.rs +++ b/hal/src/async_hal/interrupts.rs @@ -1,11 +1,21 @@ -use core::mem; -use core::sync::atomic::{compiler_fence, Ordering}; -use cortex_m::interrupt::InterruptNumber; -use cortex_m::peripheral::NVIC; +use crate::typelevel::Sealed; +use core::{ + mem, + sync::atomic::{compiler_fence, Ordering}, +}; +use cortex_m::{interrupt::InterruptNumber, peripheral::NVIC}; use critical_section::CriticalSection; use paste::paste; use seq_macro::seq; +/// Marker trait indicating that an interrupt source has one binding and +/// one handler. +pub trait SingleInterruptSource: Sealed {} + +/// Marker trait indicating that an interrupt source has multiple bindings and +/// handlers. +pub trait MultipleInterruptSources: Sealed {} + macro_rules! declare_interrupts { ($($(#[$cfg:meta])* $irqs:ident),* $(,)?) => { $( @@ -14,12 +24,17 @@ macro_rules! declare_interrupts { #[doc=stringify!($irqs)] #[doc=" typelevel interrupt."] pub enum $irqs {} + $(#[$cfg])* impl $crate::typelevel::Sealed for $irqs{} + $(#[$cfg])* impl $crate::async_hal::interrupts::Interrupt for $irqs { const IRQ: crate::pac::Interrupt = crate::pac::Interrupt::$irqs; } + + $(#[$cfg])* + impl $crate::async_hal::interrupts::SingleInterruptSource for $irqs {} )* } } @@ -55,6 +70,9 @@ macro_rules! declare_multiple_interrupts { $($crate::pac::Interrupt::$irq.set_priority(prio);)+ } } + + $(#[$cfg])* + impl $crate::async_hal::interrupts::MultipleInterruptSources for $name {} } }; } diff --git a/hal/src/async_hal/mod.rs b/hal/src/async_hal/mod.rs index 333f6478170..84007d50b1f 100644 --- a/hal/src/async_hal/mod.rs +++ b/hal/src/async_hal/mod.rs @@ -15,7 +15,7 @@ pub mod timer; /// use atsamd_hal::bind_interrupts; /// /// bind_interrupts!(struct Irqs { -/// SERCOM0 => sercom::InterruptHandler; +/// SERCOM0 => artsamd_hal::sercom::i2c::InterruptHandler; /// }); /// ``` #[macro_export] @@ -34,7 +34,9 @@ macro_rules! bind_interrupts { } $( - unsafe impl $crate::async_hal::interrupts::Binding<$crate::async_hal::interrupts::$irq, $handler> for $name {} + unsafe impl $crate::async_hal::interrupts::Binding<$crate::async_hal::interrupts::$irq, $handler> for $name + where $crate::async_hal::interrupts::$irq: $crate::async_hal::interrupts::SingleInterruptSource + {} )* )* }; @@ -51,6 +53,8 @@ macro_rules! bind_interrupts { } )+ - unsafe impl $crate::async_hal::interrupts::Binding<$crate::async_hal::interrupts::$int_source, $handler> for $name {} + unsafe impl $crate::async_hal::interrupts::Binding<$crate::async_hal::interrupts::$int_source, $handler> for $name + where $crate::async_hal::interrupts::$int_source: $crate::async_hal::interrupts::MultipleInterruptSources + {} }; }