From 62009150bd3655f36c3f6247d5d339258212cb2f Mon Sep 17 00:00:00 2001 From: Joshua Salzedo Date: Wed, 24 Mar 2021 12:36:29 -0700 Subject: [PATCH] Document embassy::util::InterruptFuture --- embassy/src/util/signal.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/embassy/src/util/signal.rs b/embassy/src/util/signal.rs index 41e27d4c..e3c5fad1 100644 --- a/embassy/src/util/signal.rs +++ b/embassy/src/util/signal.rs @@ -80,6 +80,25 @@ unsafe impl cortex_m::interrupt::Nr for NrWrap { } } +/// Creates a future that completes when the specified Interrupt is triggered. +/// +/// The input handler is unregistered when this Future is dropped. +/// +/// Example: +/// ``` no_compile +/// use embassy::traits::*; +/// use embassy::util::InterruptFuture; +/// use embassy::executor::task; +/// use embassy_stm32f4::interrupt; // Adjust this to your MCU's embassy HAL. +/// #[task] +/// async fn demo_interrupt_future() { +/// // Using STM32f446 interrupt names, adjust this to your application as necessary. +/// // Wait for TIM2 to tick. +/// let mut tim2_interrupt = interrupt::take!(TIM2); +/// InterruptFuture::new(&mut tim2_interrupt).await; +/// // TIM2 interrupt went off, do something... +/// } +/// ``` pub struct InterruptFuture<'a, I: Interrupt> { interrupt: &'a mut I, }