diff options
| author | Ralph Ursprung <[email protected]> | 2025-05-15 17:53:31 +0200 |
|---|---|---|
| committer | Ralph Ursprung <[email protected]> | 2025-05-15 18:27:40 +0200 |
| commit | 117eb45fa0829239da9152b9cf54c3cf706dc76d (patch) | |
| tree | 86eb9a1c2fdcba1efae1705299adbaeaa87884af | |
| parent | d1c2ce927ac41a3f81de0f47e0468523d562d1d1 (diff) | |
add the possibility to document `bind_interrupts` `struct`s
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.
| -rw-r--r-- | embassy-imxrt/src/lib.rs | 12 | ||||
| -rw-r--r-- | embassy-nrf/src/lib.rs | 12 | ||||
| -rw-r--r-- | embassy-rp/src/lib.rs | 12 | ||||
| -rw-r--r-- | embassy-stm32/src/lib.rs | 13 | ||||
| -rw-r--r-- | examples/rp/src/bin/adc.rs | 9 |
5 files changed, 38 insertions, 20 deletions
diff --git a/embassy-imxrt/src/lib.rs b/embassy-imxrt/src/lib.rs index b1183d8fc..5b7341fbd 100644 --- a/embassy-imxrt/src/lib.rs +++ b/embassy-imxrt/src/lib.rs | |||
| @@ -54,16 +54,20 @@ pub use crate::pac::NVIC_PRIO_BITS; | |||
| 54 | /// ```rust,ignore | 54 | /// ```rust,ignore |
| 55 | /// use embassy_imxrt::{bind_interrupts, flexspi, peripherals}; | 55 | /// use embassy_imxrt::{bind_interrupts, flexspi, peripherals}; |
| 56 | /// | 56 | /// |
| 57 | /// bind_interrupts!(struct Irqs { | 57 | /// bind_interrupts!( |
| 58 | /// FLEXSPI_IRQ => flexspi::InterruptHandler<peripherals::FLEXSPI>; | 58 | /// /// Binds the FLEXSPI interrupt. |
| 59 | /// }); | 59 | /// struct Irqs { |
| 60 | /// FLEXSPI_IRQ => flexspi::InterruptHandler<peripherals::FLEXSPI>; | ||
| 61 | /// } | ||
| 62 | /// ); | ||
| 60 | /// ``` | 63 | /// ``` |
| 61 | /// | 64 | /// |
| 62 | // developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`. | 65 | // developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`. |
| 63 | #[macro_export] | 66 | #[macro_export] |
| 64 | macro_rules! bind_interrupts { | 67 | macro_rules! bind_interrupts { |
| 65 | ($vis:vis struct $name:ident { $($irq:ident => $($handler:ty),*;)* }) => { | 68 | ($(#[$attr:meta])* $vis:vis struct $name:ident { $($irq:ident => $($handler:ty),*;)* }) => { |
| 66 | #[derive(Copy, Clone)] | 69 | #[derive(Copy, Clone)] |
| 70 | $(#[$attr])* | ||
| 67 | $vis struct $name; | 71 | $vis struct $name; |
| 68 | 72 | ||
| 69 | $( | 73 | $( |
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 7d86e1218..0c5dd059d 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -200,9 +200,12 @@ mod chip; | |||
| 200 | /// ```rust,ignore | 200 | /// ```rust,ignore |
| 201 | /// use embassy_nrf::{bind_interrupts, spim, peripherals}; | 201 | /// use embassy_nrf::{bind_interrupts, spim, peripherals}; |
| 202 | /// | 202 | /// |
| 203 | /// bind_interrupts!(struct Irqs { | 203 | /// bind_interrupts!( |
| 204 | /// SPIM3 => spim::InterruptHandler<peripherals::SPI3>; | 204 | /// /// Binds the SPIM3 interrupt. |
| 205 | /// }); | 205 | /// struct Irqs { |
| 206 | /// SPIM3 => spim::InterruptHandler<peripherals::SPI3>; | ||
| 207 | /// } | ||
| 208 | /// ); | ||
| 206 | /// ``` | 209 | /// ``` |
| 207 | /// | 210 | /// |
| 208 | /// Example of how to bind multiple interrupts in a single macro invocation: | 211 | /// Example of how to bind multiple interrupts in a single macro invocation: |
| @@ -219,7 +222,7 @@ mod chip; | |||
| 219 | // developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`. | 222 | // developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`. |
| 220 | #[macro_export] | 223 | #[macro_export] |
| 221 | macro_rules! bind_interrupts { | 224 | macro_rules! bind_interrupts { |
| 222 | ($vis:vis struct $name:ident { | 225 | ($(#[$attr:meta])* $vis:vis struct $name:ident { |
| 223 | $( | 226 | $( |
| 224 | $(#[cfg($cond_irq:meta)])? | 227 | $(#[cfg($cond_irq:meta)])? |
| 225 | $irq:ident => $( | 228 | $irq:ident => $( |
| @@ -229,6 +232,7 @@ macro_rules! bind_interrupts { | |||
| 229 | )* | 232 | )* |
| 230 | }) => { | 233 | }) => { |
| 231 | #[derive(Copy, Clone)] | 234 | #[derive(Copy, Clone)] |
| 235 | $(#[$attr])* | ||
| 232 | $vis struct $name; | 236 | $vis struct $name; |
| 233 | 237 | ||
| 234 | $( | 238 | $( |
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index f549446bc..f3c5a35bb 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs | |||
| @@ -160,15 +160,18 @@ embassy_hal_internal::interrupt_mod!( | |||
| 160 | /// ```rust,ignore | 160 | /// ```rust,ignore |
| 161 | /// use embassy_rp::{bind_interrupts, usb, peripherals}; | 161 | /// use embassy_rp::{bind_interrupts, usb, peripherals}; |
| 162 | /// | 162 | /// |
| 163 | /// bind_interrupts!(struct Irqs { | 163 | /// bind_interrupts!( |
| 164 | /// USBCTRL_IRQ => usb::InterruptHandler<peripherals::USB>; | 164 | /// /// Binds the USB Interrupts. |
| 165 | /// }); | 165 | /// struct Irqs { |
| 166 | /// USBCTRL_IRQ => usb::InterruptHandler<peripherals::USB>; | ||
| 167 | /// } | ||
| 168 | /// ); | ||
| 166 | /// ``` | 169 | /// ``` |
| 167 | /// | 170 | /// |
| 168 | // developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`. | 171 | // developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`. |
| 169 | #[macro_export] | 172 | #[macro_export] |
| 170 | macro_rules! bind_interrupts { | 173 | macro_rules! bind_interrupts { |
| 171 | ($vis:vis struct $name:ident { | 174 | ($(#[$attr:meta])* $vis:vis struct $name:ident { |
| 172 | $( | 175 | $( |
| 173 | $(#[cfg($cond_irq:meta)])? | 176 | $(#[cfg($cond_irq:meta)])? |
| 174 | $irq:ident => $( | 177 | $irq:ident => $( |
| @@ -178,6 +181,7 @@ macro_rules! bind_interrupts { | |||
| 178 | )* | 181 | )* |
| 179 | }) => { | 182 | }) => { |
| 180 | #[derive(Copy, Clone)] | 183 | #[derive(Copy, Clone)] |
| 184 | $(#[$attr])* | ||
| 181 | $vis struct $name; | 185 | $vis struct $name; |
| 182 | 186 | ||
| 183 | $( | 187 | $( |
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index f8d09413d..973acc9bb 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -163,11 +163,14 @@ pub use crate::_generated::interrupt; | |||
| 163 | /// ```rust,ignore | 163 | /// ```rust,ignore |
| 164 | /// use embassy_stm32::{bind_interrupts, i2c, peripherals}; | 164 | /// use embassy_stm32::{bind_interrupts, i2c, peripherals}; |
| 165 | /// | 165 | /// |
| 166 | /// bind_interrupts!(struct Irqs { | 166 | /// bind_interrupts!( |
| 167 | /// I2C1 => i2c::EventInterruptHandler<peripherals::I2C1>, i2c::ErrorInterruptHandler<peripherals::I2C1>; | 167 | /// /// Binds the I2C interrupts. |
| 168 | /// I2C2_3 => i2c::EventInterruptHandler<peripherals::I2C2>, i2c::ErrorInterruptHandler<peripherals::I2C2>, | 168 | /// struct Irqs { |
| 169 | /// i2c::EventInterruptHandler<peripherals::I2C3>, i2c::ErrorInterruptHandler<peripherals::I2C3>; | 169 | /// I2C1 => i2c::EventInterruptHandler<peripherals::I2C1>, i2c::ErrorInterruptHandler<peripherals::I2C1>; |
| 170 | /// }); | 170 | /// I2C2_3 => i2c::EventInterruptHandler<peripherals::I2C2>, i2c::ErrorInterruptHandler<peripherals::I2C2>, |
| 171 | /// i2c::EventInterruptHandler<peripherals::I2C3>, i2c::ErrorInterruptHandler<peripherals::I2C3>; | ||
| 172 | /// } | ||
| 173 | /// ); | ||
| 171 | /// ``` | 174 | /// ``` |
| 172 | 175 | ||
| 173 | // developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`. | 176 | // developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`. |
diff --git a/examples/rp/src/bin/adc.rs b/examples/rp/src/bin/adc.rs index 1bb7c2249..015915586 100644 --- a/examples/rp/src/bin/adc.rs +++ b/examples/rp/src/bin/adc.rs | |||
| @@ -12,9 +12,12 @@ use embassy_rp::gpio::Pull; | |||
| 12 | use embassy_time::Timer; | 12 | use embassy_time::Timer; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| 15 | bind_interrupts!(struct Irqs { | 15 | bind_interrupts!( |
| 16 | ADC_IRQ_FIFO => InterruptHandler; | 16 | /// Binds the ADC interrupts. |
| 17 | }); | 17 | struct Irqs { |
| 18 | ADC_IRQ_FIFO => InterruptHandler; | ||
| 19 | } | ||
| 20 | ); | ||
| 18 | 21 | ||
| 19 | #[embassy_executor::main] | 22 | #[embassy_executor::main] |
| 20 | async fn main(_spawner: Spawner) { | 23 | async fn main(_spawner: Spawner) { |
