From aa1411e2c772fd332417ca258b58c75b35d5b7ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Kro=CC=88ger?= Date: Sun, 3 Mar 2024 15:02:00 +0100 Subject: [PATCH] [UCPD] Prepare interrupt handle --- embassy-stm32/src/ucpd.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/src/ucpd.rs b/embassy-stm32/src/ucpd.rs index a2bac7611..a3f01c629 100644 --- a/embassy-stm32/src/ucpd.rs +++ b/embassy-stm32/src/ucpd.rs @@ -1,20 +1,49 @@ //! USB Type-C/USB Power Delivery Interface (UCPD) +use core::marker::PhantomData; + +use crate::interrupt; use crate::rcc::RccPeripheral; +use embassy_sync::waitqueue::AtomicWaker; + +/// Interrupt handler. +pub struct InterruptHandler { + _phantom: PhantomData, +} + +impl interrupt::typelevel::Handler for InterruptHandler { + unsafe fn on_interrupt() { + let sr = T::REGS.sr().read(); + + // TODO: Disable interrupt which have fired. + + // Wake the task to handle and re-enabled interrupts. + T::waker().wake(); + } +} /// UCPD instance trait. pub trait Instance: sealed::Instance + RccPeripheral {} pub(crate) mod sealed { pub trait Instance { + type Interrupt: crate::interrupt::typelevel::Interrupt; const REGS: crate::pac::ucpd::Ucpd; + fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker; } } -foreach_peripheral!( - (ucpd, $inst:ident) => { +foreach_interrupt!( + ($inst:ident, ucpd, UCPD, GLOBAL, $irq:ident) => { impl sealed::Instance for crate::peripherals::$inst { + type Interrupt = crate::interrupt::typelevel::$irq; + const REGS: crate::pac::ucpd::Ucpd = crate::pac::$inst; + + fn waker() -> &'static AtomicWaker { + static WAKER: AtomicWaker = AtomicWaker::new(); + &WAKER + } } impl Instance for crate::peripherals::$inst {}