diff options
| author | Timo Kröger <[email protected]> | 2024-03-03 15:02:00 +0100 |
|---|---|---|
| committer | Timo Kröger <[email protected]> | 2024-03-12 08:14:41 +0100 |
| commit | aa1411e2c772fd332417ca258b58c75b35d5b7ac (patch) | |
| tree | b1cdb3adec43eb856362b0be60d81b831b37de33 | |
| parent | 8a255b375b7598c2825535cb0d0729311a7b882d (diff) | |
[UCPD] Prepare interrupt handle
| -rw-r--r-- | embassy-stm32/src/ucpd.rs | 33 |
1 files 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 @@ | |||
| 1 | //! USB Type-C/USB Power Delivery Interface (UCPD) | 1 | //! USB Type-C/USB Power Delivery Interface (UCPD) |
| 2 | 2 | ||
| 3 | use core::marker::PhantomData; | ||
| 4 | |||
| 5 | use crate::interrupt; | ||
| 3 | use crate::rcc::RccPeripheral; | 6 | use crate::rcc::RccPeripheral; |
| 7 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 8 | |||
| 9 | /// Interrupt handler. | ||
| 10 | pub struct InterruptHandler<T: Instance> { | ||
| 11 | _phantom: PhantomData<T>, | ||
| 12 | } | ||
| 13 | |||
| 14 | impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandler<T> { | ||
| 15 | unsafe fn on_interrupt() { | ||
| 16 | let sr = T::REGS.sr().read(); | ||
| 17 | |||
| 18 | // TODO: Disable interrupt which have fired. | ||
| 19 | |||
| 20 | // Wake the task to handle and re-enabled interrupts. | ||
| 21 | T::waker().wake(); | ||
| 22 | } | ||
| 23 | } | ||
| 4 | 24 | ||
| 5 | /// UCPD instance trait. | 25 | /// UCPD instance trait. |
| 6 | pub trait Instance: sealed::Instance + RccPeripheral {} | 26 | pub trait Instance: sealed::Instance + RccPeripheral {} |
| 7 | 27 | ||
| 8 | pub(crate) mod sealed { | 28 | pub(crate) mod sealed { |
| 9 | pub trait Instance { | 29 | pub trait Instance { |
| 30 | type Interrupt: crate::interrupt::typelevel::Interrupt; | ||
| 10 | const REGS: crate::pac::ucpd::Ucpd; | 31 | const REGS: crate::pac::ucpd::Ucpd; |
| 32 | fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker; | ||
| 11 | } | 33 | } |
| 12 | } | 34 | } |
| 13 | 35 | ||
| 14 | foreach_peripheral!( | 36 | foreach_interrupt!( |
| 15 | (ucpd, $inst:ident) => { | 37 | ($inst:ident, ucpd, UCPD, GLOBAL, $irq:ident) => { |
| 16 | impl sealed::Instance for crate::peripherals::$inst { | 38 | impl sealed::Instance for crate::peripherals::$inst { |
| 39 | type Interrupt = crate::interrupt::typelevel::$irq; | ||
| 40 | |||
| 17 | const REGS: crate::pac::ucpd::Ucpd = crate::pac::$inst; | 41 | const REGS: crate::pac::ucpd::Ucpd = crate::pac::$inst; |
| 42 | |||
| 43 | fn waker() -> &'static AtomicWaker { | ||
| 44 | static WAKER: AtomicWaker = AtomicWaker::new(); | ||
| 45 | &WAKER | ||
| 46 | } | ||
| 18 | } | 47 | } |
| 19 | 48 | ||
| 20 | impl Instance for crate::peripherals::$inst {} | 49 | impl Instance for crate::peripherals::$inst {} |
