embassy-stm32

Crates

git

Versions

stm32l162qc

Flavors

bind_interrupts

Macro bind_interrupts 

Source
macro_rules! bind_interrupts {
    ($(#[$outer:meta])* $vis:vis struct $name:ident {
        $(
            $(#[doc = $doc:literal])*
            $(#[cfg($cond_irq:meta)])?
            $irq:ident => $(
                $(#[cfg($cond_handler:meta)])?
                $handler:ty
            ),*;
        )*
    }) => { ... };
    (@inner $($t:tt)*) => { ... };
}
Expand description

Macro to bind interrupts to handlers.

This defines the right interrupt handlers, and creates a unit struct (like struct Irqs;) and implements the right Bindings for it. You can pass this struct to drivers to prove at compile-time that the right interrupts have been bound.

Example of how to bind one interrupt:

use embassy_stm32::{bind_interrupts, usb, peripherals};

bind_interrupts!(struct Irqs {
    OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>;
});

Example of how to bind multiple interrupts, and multiple handlers to each interrupt, in a single macro invocation:

use embassy_stm32::{bind_interrupts, i2c, peripherals};

bind_interrupts!(
    /// Binds the I2C interrupts.
    struct Irqs {
        I2C1 => i2c::EventInterruptHandler<peripherals::I2C1>, i2c::ErrorInterruptHandler<peripherals::I2C1>;
        I2C2_3 => i2c::EventInterruptHandler<peripherals::I2C2>, i2c::ErrorInterruptHandler<peripherals::I2C2>,
            i2c::EventInterruptHandler<peripherals::I2C3>, i2c::ErrorInterruptHandler<peripherals::I2C3>;
    }
);

Some chips collate multiple interrupt signals into a single interrupt vector. In the above example, I2C2_3 is a single vector which is activated by events and errors on both peripherals I2C2 and I2C3. Check your chip’s list of interrupt vectors if you get an unexpected compile error trying to bind the standard name.