[][src]Macro irq::scoped_interrupts

macro_rules! scoped_interrupts {
    (
        $( #[$enum_attr:meta] )*
        $v:vis enum $name:ident {
            $(
                $interrupt:ident
            ),+

            $(,)?
        }

        $(
            use $p:path;
        )*

        with $hook_macro:ident!(...)
    ) => { ... };
}

Hooks interrupts and makes them available to the scope API.

In order to hook the interrupts, you need to provide a macro to apply to the interrupt veneers. This is generally architecture- or even MCU-specific. On Cortex-M devices, this should usually be the #[interrupt] macro exported by the device-specific PAC.

It is not necessary to hook all interrupts. Only those that should be made available to the scope API are required. Since every hooked interrupt comes with a cost in code and data size, it is advisable to only hook the interrupts needed by the application.

Examples

In this example, an svd2rust-generated Peripheral Access Crate mock_pac provides the interrupts that can be hooked using the #[interrupt] macro:

// A macro taking `interrupt` and `function` arguments has to be provided:
macro_rules! hook {
    (
        interrupt = $name:ident;
        function = $f:item;
    ) => {
        #[interrupt]
        $f
    };
}

scoped_interrupts! {
    enum Interrupt {
        INT0,
    }

    use mock_pac::interrupt;

    with hook!(...)
}

Also refer to examples/mock-pac.rs for a standalone version with more comments.