2020-10-19 21:15:24 +02:00
|
|
|
extern crate proc_macro;
|
|
|
|
|
2021-05-12 01:00:43 +02:00
|
|
|
use proc_macro::TokenStream;
|
2021-04-14 09:25:10 +02:00
|
|
|
|
2022-02-12 00:11:15 +01:00
|
|
|
mod macros;
|
|
|
|
mod util;
|
|
|
|
use macros::*;
|
2020-10-19 21:15:24 +02:00
|
|
|
|
|
|
|
#[proc_macro_attribute]
|
|
|
|
pub fn task(args: TokenStream, item: TokenStream) -> TokenStream {
|
2022-02-12 00:11:15 +01:00
|
|
|
let args = syn::parse_macro_input!(args as syn::AttributeArgs);
|
|
|
|
let f = syn::parse_macro_input!(item as syn::ItemFn);
|
2020-10-19 21:15:24 +02:00
|
|
|
|
2022-02-12 00:11:15 +01:00
|
|
|
task::run(args, f).unwrap_or_else(|x| x).into()
|
2020-10-19 21:15:24 +02:00
|
|
|
}
|
2020-12-29 00:05:52 +01:00
|
|
|
|
2021-05-12 01:00:43 +02:00
|
|
|
#[proc_macro_attribute]
|
2022-02-12 00:11:15 +01:00
|
|
|
pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
|
|
|
|
let args = syn::parse_macro_input!(args as syn::AttributeArgs);
|
|
|
|
let f = syn::parse_macro_input!(item as syn::ItemFn);
|
|
|
|
main::run(args, f).unwrap_or_else(|x| x).into()
|
|
|
|
}
|
2021-05-12 01:00:43 +02:00
|
|
|
|
2022-02-12 00:11:15 +01:00
|
|
|
#[proc_macro_attribute]
|
2022-06-11 05:08:57 +02:00
|
|
|
pub fn cortex_m_interrupt(args: TokenStream, item: TokenStream) -> TokenStream {
|
2022-02-12 00:11:15 +01:00
|
|
|
let args = syn::parse_macro_input!(args as syn::AttributeArgs);
|
|
|
|
let f = syn::parse_macro_input!(item as syn::ItemFn);
|
2022-06-12 22:15:44 +02:00
|
|
|
cortex_m_interrupt::run(args, f).unwrap_or_else(|x| x).into()
|
2021-05-12 01:00:43 +02:00
|
|
|
}
|
|
|
|
|
2020-12-29 00:05:52 +01:00
|
|
|
#[proc_macro]
|
2022-06-11 05:08:57 +02:00
|
|
|
pub fn cortex_m_interrupt_declare(item: TokenStream) -> TokenStream {
|
2020-12-29 00:05:52 +01:00
|
|
|
let name = syn::parse_macro_input!(item as syn::Ident);
|
2022-06-12 22:15:44 +02:00
|
|
|
cortex_m_interrupt_declare::run(name).unwrap_or_else(|x| x).into()
|
2020-12-29 00:05:52 +01:00
|
|
|
}
|
2022-02-12 00:11:15 +01:00
|
|
|
|
2021-11-16 12:13:43 +01:00
|
|
|
/// # interrupt_take procedural macro
|
|
|
|
///
|
|
|
|
/// core::panic! is used as a default way to panic in this macro as there is no sensible way of enabling/disabling defmt for macro generation.
|
|
|
|
/// We are aware that this brings bloat in the form of core::fmt, but the bloat is already included with e.g. array indexing panics.
|
|
|
|
/// To get rid of this bloat, use the compiler flags `-Zbuild-std=core -Zbuild-std-features=panic_immediate_abort`.
|
2020-12-29 00:05:52 +01:00
|
|
|
#[proc_macro]
|
2022-06-11 05:08:57 +02:00
|
|
|
pub fn cortex_m_interrupt_take(item: TokenStream) -> TokenStream {
|
2020-12-29 00:05:52 +01:00
|
|
|
let name = syn::parse_macro_input!(item as syn::Ident);
|
2022-06-12 22:15:44 +02:00
|
|
|
cortex_m_interrupt_take::run(name).unwrap_or_else(|x| x).into()
|
2021-09-13 14:35:40 +02:00
|
|
|
}
|