diff --git a/macros/src/check.rs b/macros/src/check.rs index ab86461612..4adc2c1756 100644 --- a/macros/src/check.rs +++ b/macros/src/check.rs @@ -106,12 +106,8 @@ pub fn app(app: &App) -> parse::Result<()> { } // Check that free interrupts are not being used - for (name, interrupt) in &app.interrupts { - let name = if let Some(ref binds) = interrupt.args.binds { - binds - } else { - name - }; + for (handler, interrupt) in &app.interrupts { + let name = interrupt.args.binds(handler); if app.free_interrupts.contains_key(name) { return Err(parse::Error::new( diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 0e25e8a7a6..1d201c0866 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -468,12 +468,8 @@ fn post_init(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::Tok // the device into compile errors let device = &app.args.device; let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS); - for (name, exception) in &app.exceptions { - let name = if let Some(ref binds) = exception.args.binds { - binds - } else { - name - }; + for (handler, exception) in &app.exceptions { + let name = exception.args.binds(handler); let priority = exception.args.priority; exprs.push(quote!(assert!(#priority <= (1 << #nvic_prio_bits)))); exprs.push(quote!(p.SCB.set_priority( @@ -1128,7 +1124,7 @@ fn exceptions(ctxt: &mut Context, app: &App, analysis: &Analysis) -> Vec proc_macro2::Toke // the device into compile errors let device = &app.args.device; let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS); - for (name, interrupt) in &app.interrupts { - let name = if let Some(ref binds) = interrupt.args.binds { - binds - } else { - name - }; + for (handler, interrupt) in &app.interrupts { + let name = interrupt.args.binds(handler); let priority = interrupt.args.priority; exprs.push(quote!(p.NVIC.enable(#device::Interrupt::#name);)); exprs.push(quote!(assert!(#priority <= (1 << #nvic_prio_bits));)); diff --git a/macros/src/syntax.rs b/macros/src/syntax.rs index 23981d98d0..7f87f6339e 100644 --- a/macros/src/syntax.rs +++ b/macros/src/syntax.rs @@ -731,13 +731,20 @@ pub struct Exception { } pub struct ExceptionArgs { - pub binds: Option, + binds: Option, pub priority: u8, pub resources: Idents, pub schedule: Idents, pub spawn: Idents, } +impl ExceptionArgs { + /// Returns the name of the exception / interrupt this handler binds to + pub fn binds<'a>(&'a self, handler: &'a Ident) -> &'a Ident { + self.binds.as_ref().unwrap_or(handler) + } +} + impl Parse for ExceptionArgs { fn parse(input: ParseStream<'_>) -> parse::Result { parse_args(input, /* binds */ true, /* capacity */ false).map(