[UCPD] Take interrupt in constructor and enable it

This commit is contained in:
Timo Kröger 2024-03-12 20:38:37 +01:00
parent 30cdc6c9c5
commit e95e95ac7a
2 changed files with 12 additions and 2 deletions

View File

@ -24,6 +24,7 @@ use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef};
use crate::dma::{AnyChannel, Request, Transfer, TransferOptions}; use crate::dma::{AnyChannel, Request, Transfer, TransferOptions};
use crate::interrupt; use crate::interrupt;
use crate::interrupt::typelevel::Interrupt;
use crate::pac::ucpd::vals::{Anamode, Ccenable, PscUsbpdclk, Txmode}; use crate::pac::ucpd::vals::{Anamode, Ccenable, PscUsbpdclk, Txmode};
pub use crate::pac::ucpd::vals::{Phyccsel as CcSel, TypecVstateCc as CcVState}; pub use crate::pac::ucpd::vals::{Phyccsel as CcSel, TypecVstateCc as CcVState};
use crate::rcc::RccPeripheral; use crate::rcc::RccPeripheral;
@ -93,10 +94,13 @@ impl<'d, T: Instance> Ucpd<'d, T> {
/// Creates a new UCPD driver instance. /// Creates a new UCPD driver instance.
pub fn new( pub fn new(
_peri: impl Peripheral<P = T> + 'd, _peri: impl Peripheral<P = T> + 'd,
_irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
_cc1: impl Peripheral<P = impl Cc1Pin<T>> + 'd, _cc1: impl Peripheral<P = impl Cc1Pin<T>> + 'd,
_cc2: impl Peripheral<P = impl Cc2Pin<T>> + 'd, _cc2: impl Peripheral<P = impl Cc2Pin<T>> + 'd,
) -> Self { ) -> Self {
T::enable_and_reset(); T::enable_and_reset();
T::Interrupt::unpend();
unsafe { T::Interrupt::enable() };
let r = T::REGS; let r = T::REGS;
r.cfgr1().write(|w| { r.cfgr1().write(|w| {
@ -206,6 +210,7 @@ impl<'d, T: Instance> Drop for CcPhy<'d, T> {
} else { } else {
r.cfgr1().write(|w| w.set_ucpden(false)); r.cfgr1().write(|w| w.set_ucpden(false));
T::disable(); T::disable();
T::Interrupt::disable();
} }
} }
} }
@ -323,6 +328,7 @@ impl<'d, T: Instance> Drop for PdPhy<'d, T> {
} else { } else {
r.cfgr1().write(|w| w.set_ucpden(false)); r.cfgr1().write(|w| w.set_ucpden(false));
T::disable(); T::disable();
T::Interrupt::disable();
} }
} }
} }

View File

@ -4,10 +4,14 @@
use defmt::{error, info, Format}; use defmt::{error, info, Format};
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_stm32::ucpd::{self, CcPhy, CcPull, CcSel, CcVState, Ucpd}; use embassy_stm32::ucpd::{self, CcPhy, CcPull, CcSel, CcVState, Ucpd};
use embassy_stm32::Config; use embassy_stm32::{bind_interrupts, peripherals, Config};
use embassy_time::{with_timeout, Duration}; use embassy_time::{with_timeout, Duration};
use {defmt_rtt as _, panic_probe as _}; use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
UCPD1 => ucpd::InterruptHandler<peripherals::UCPD1>;
});
#[derive(Debug, Format)] #[derive(Debug, Format)]
enum CableOrientation { enum CableOrientation {
Normal, Normal,
@ -50,7 +54,7 @@ async fn main(_spawner: Spawner) {
info!("Hello World!"); info!("Hello World!");
let mut ucpd = Ucpd::new(p.UCPD1, p.PB6, p.PB4); let mut ucpd = Ucpd::new(p.UCPD1, Irqs {}, p.PB6, p.PB4);
ucpd.cc_phy().set_pull(CcPull::Sink); ucpd.cc_phy().set_pull(CcPull::Sink);
info!("Waiting for USB connection..."); info!("Waiting for USB connection...");