add the possibility to document bind_interrupts structs

the `bind_interrupts` macro creates a `struct` for the interrupts. it
was so far not possible to document those (except for STM32) and there
was no generic documentation being generated/added either, thus the
`missing_docs` lint was triggered for consumers which enabled it.

with this change it is now possible to manually add a comment on the
`struct` being defined in the macro invocation.

to show that this works one RP example has been modified accordingly.
This commit is contained in:
Ralph Ursprung 2025-05-15 17:53:31 +02:00
parent d1c2ce927a
commit 117eb45fa0
No known key found for this signature in database
GPG Key ID: 86CCE68A77D190D2
5 changed files with 38 additions and 20 deletions

View File

@ -54,16 +54,20 @@ pub use crate::pac::NVIC_PRIO_BITS;
/// ```rust,ignore
/// use embassy_imxrt::{bind_interrupts, flexspi, peripherals};
///
/// bind_interrupts!(struct Irqs {
/// FLEXSPI_IRQ => flexspi::InterruptHandler<peripherals::FLEXSPI>;
/// });
/// bind_interrupts!(
/// /// Binds the FLEXSPI interrupt.
/// struct Irqs {
/// FLEXSPI_IRQ => flexspi::InterruptHandler<peripherals::FLEXSPI>;
/// }
/// );
/// ```
///
// developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`.
#[macro_export]
macro_rules! bind_interrupts {
($vis:vis struct $name:ident { $($irq:ident => $($handler:ty),*;)* }) => {
($(#[$attr:meta])* $vis:vis struct $name:ident { $($irq:ident => $($handler:ty),*;)* }) => {
#[derive(Copy, Clone)]
$(#[$attr])*
$vis struct $name;
$(

View File

@ -200,9 +200,12 @@ mod chip;
/// ```rust,ignore
/// use embassy_nrf::{bind_interrupts, spim, peripherals};
///
/// bind_interrupts!(struct Irqs {
/// SPIM3 => spim::InterruptHandler<peripherals::SPI3>;
/// });
/// bind_interrupts!(
/// /// Binds the SPIM3 interrupt.
/// struct Irqs {
/// SPIM3 => spim::InterruptHandler<peripherals::SPI3>;
/// }
/// );
/// ```
///
/// Example of how to bind multiple interrupts in a single macro invocation:
@ -219,7 +222,7 @@ mod chip;
// developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`.
#[macro_export]
macro_rules! bind_interrupts {
($vis:vis struct $name:ident {
($(#[$attr:meta])* $vis:vis struct $name:ident {
$(
$(#[cfg($cond_irq:meta)])?
$irq:ident => $(
@ -229,6 +232,7 @@ macro_rules! bind_interrupts {
)*
}) => {
#[derive(Copy, Clone)]
$(#[$attr])*
$vis struct $name;
$(

View File

@ -160,15 +160,18 @@ embassy_hal_internal::interrupt_mod!(
/// ```rust,ignore
/// use embassy_rp::{bind_interrupts, usb, peripherals};
///
/// bind_interrupts!(struct Irqs {
/// USBCTRL_IRQ => usb::InterruptHandler<peripherals::USB>;
/// });
/// bind_interrupts!(
/// /// Binds the USB Interrupts.
/// struct Irqs {
/// USBCTRL_IRQ => usb::InterruptHandler<peripherals::USB>;
/// }
/// );
/// ```
///
// developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`.
#[macro_export]
macro_rules! bind_interrupts {
($vis:vis struct $name:ident {
($(#[$attr:meta])* $vis:vis struct $name:ident {
$(
$(#[cfg($cond_irq:meta)])?
$irq:ident => $(
@ -178,6 +181,7 @@ macro_rules! bind_interrupts {
)*
}) => {
#[derive(Copy, Clone)]
$(#[$attr])*
$vis struct $name;
$(

View File

@ -163,11 +163,14 @@ pub use crate::_generated::interrupt;
/// ```rust,ignore
/// use embassy_stm32::{bind_interrupts, i2c, peripherals};
///
/// bind_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>;
/// });
/// 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>;
/// }
/// );
/// ```
// developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`.

View File

@ -12,9 +12,12 @@ use embassy_rp::gpio::Pull;
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
ADC_IRQ_FIFO => InterruptHandler;
});
bind_interrupts!(
/// Binds the ADC interrupts.
struct Irqs {
ADC_IRQ_FIFO => InterruptHandler;
}
);
#[embassy_executor::main]
async fn main(_spawner: Spawner) {