diff options
| -rw-r--r-- | embassy-stm32/src/ucpd.rs | 6 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/usb_c_pd.rs | 8 |
2 files changed, 12 insertions, 2 deletions
diff --git a/embassy-stm32/src/ucpd.rs b/embassy-stm32/src/ucpd.rs index 51cfe4a24..b7af877b7 100644 --- a/embassy-stm32/src/ucpd.rs +++ b/embassy-stm32/src/ucpd.rs | |||
| @@ -24,6 +24,7 @@ use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; | |||
| 24 | 24 | ||
| 25 | use crate::dma::{AnyChannel, Request, Transfer, TransferOptions}; | 25 | use crate::dma::{AnyChannel, Request, Transfer, TransferOptions}; |
| 26 | use crate::interrupt; | 26 | use crate::interrupt; |
| 27 | use crate::interrupt::typelevel::Interrupt; | ||
| 27 | use crate::pac::ucpd::vals::{Anamode, Ccenable, PscUsbpdclk, Txmode}; | 28 | use crate::pac::ucpd::vals::{Anamode, Ccenable, PscUsbpdclk, Txmode}; |
| 28 | pub use crate::pac::ucpd::vals::{Phyccsel as CcSel, TypecVstateCc as CcVState}; | 29 | pub use crate::pac::ucpd::vals::{Phyccsel as CcSel, TypecVstateCc as CcVState}; |
| 29 | use crate::rcc::RccPeripheral; | 30 | use crate::rcc::RccPeripheral; |
| @@ -93,10 +94,13 @@ impl<'d, T: Instance> Ucpd<'d, T> { | |||
| 93 | /// Creates a new UCPD driver instance. | 94 | /// Creates a new UCPD driver instance. |
| 94 | pub fn new( | 95 | pub fn new( |
| 95 | _peri: impl Peripheral<P = T> + 'd, | 96 | _peri: impl Peripheral<P = T> + 'd, |
| 97 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | ||
| 96 | _cc1: impl Peripheral<P = impl Cc1Pin<T>> + 'd, | 98 | _cc1: impl Peripheral<P = impl Cc1Pin<T>> + 'd, |
| 97 | _cc2: impl Peripheral<P = impl Cc2Pin<T>> + 'd, | 99 | _cc2: impl Peripheral<P = impl Cc2Pin<T>> + 'd, |
| 98 | ) -> Self { | 100 | ) -> Self { |
| 99 | T::enable_and_reset(); | 101 | T::enable_and_reset(); |
| 102 | T::Interrupt::unpend(); | ||
| 103 | unsafe { T::Interrupt::enable() }; | ||
| 100 | 104 | ||
| 101 | let r = T::REGS; | 105 | let r = T::REGS; |
| 102 | r.cfgr1().write(|w| { | 106 | r.cfgr1().write(|w| { |
| @@ -206,6 +210,7 @@ impl<'d, T: Instance> Drop for CcPhy<'d, T> { | |||
| 206 | } else { | 210 | } else { |
| 207 | r.cfgr1().write(|w| w.set_ucpden(false)); | 211 | r.cfgr1().write(|w| w.set_ucpden(false)); |
| 208 | T::disable(); | 212 | T::disable(); |
| 213 | T::Interrupt::disable(); | ||
| 209 | } | 214 | } |
| 210 | } | 215 | } |
| 211 | } | 216 | } |
| @@ -323,6 +328,7 @@ impl<'d, T: Instance> Drop for PdPhy<'d, T> { | |||
| 323 | } else { | 328 | } else { |
| 324 | r.cfgr1().write(|w| w.set_ucpden(false)); | 329 | r.cfgr1().write(|w| w.set_ucpden(false)); |
| 325 | T::disable(); | 330 | T::disable(); |
| 331 | T::Interrupt::disable(); | ||
| 326 | } | 332 | } |
| 327 | } | 333 | } |
| 328 | } | 334 | } |
diff --git a/examples/stm32g4/src/bin/usb_c_pd.rs b/examples/stm32g4/src/bin/usb_c_pd.rs index 0e80840df..c850b2753 100644 --- a/examples/stm32g4/src/bin/usb_c_pd.rs +++ b/examples/stm32g4/src/bin/usb_c_pd.rs | |||
| @@ -4,10 +4,14 @@ | |||
| 4 | use defmt::{error, info, Format}; | 4 | use defmt::{error, info, Format}; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::ucpd::{self, CcPhy, CcPull, CcSel, CcVState, Ucpd}; | 6 | use embassy_stm32::ucpd::{self, CcPhy, CcPull, CcSel, CcVState, Ucpd}; |
| 7 | use embassy_stm32::Config; | 7 | use embassy_stm32::{bind_interrupts, peripherals, Config}; |
| 8 | use embassy_time::{with_timeout, Duration}; | 8 | use embassy_time::{with_timeout, Duration}; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 10 | ||
| 11 | bind_interrupts!(struct Irqs { | ||
| 12 | UCPD1 => ucpd::InterruptHandler<peripherals::UCPD1>; | ||
| 13 | }); | ||
| 14 | |||
| 11 | #[derive(Debug, Format)] | 15 | #[derive(Debug, Format)] |
| 12 | enum CableOrientation { | 16 | enum CableOrientation { |
| 13 | Normal, | 17 | Normal, |
| @@ -50,7 +54,7 @@ async fn main(_spawner: Spawner) { | |||
| 50 | 54 | ||
| 51 | info!("Hello World!"); | 55 | info!("Hello World!"); |
| 52 | 56 | ||
| 53 | let mut ucpd = Ucpd::new(p.UCPD1, p.PB6, p.PB4); | 57 | let mut ucpd = Ucpd::new(p.UCPD1, Irqs {}, p.PB6, p.PB4); |
| 54 | ucpd.cc_phy().set_pull(CcPull::Sink); | 58 | ucpd.cc_phy().set_pull(CcPull::Sink); |
| 55 | 59 | ||
| 56 | info!("Waiting for USB connection..."); | 60 | info!("Waiting for USB connection..."); |
