diff options
| author | Timo Kröger <[email protected]> | 2024-03-08 20:36:37 +0100 |
|---|---|---|
| committer | Timo Kröger <[email protected]> | 2024-03-12 08:14:42 +0100 |
| commit | 89504f51629d0ab81070db91c3eb5b96b1e41fcb (patch) | |
| tree | 0656fb3800905b20f85320306569b965f72ad6cc /examples/stm32g4/src/bin | |
| parent | 99854ff840fdd12d7562923f6a9ef2d39e1c9f17 (diff) | |
[UCPD] Split into CC and PD phy
PD3.0 spec requires concurrent control of CC resistors for collision avoidance.
Needed to introduce some "ref counting" (its just a bool) for drop code.
Diffstat (limited to 'examples/stm32g4/src/bin')
| -rw-r--r-- | examples/stm32g4/src/bin/usb_c_pd.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/examples/stm32g4/src/bin/usb_c_pd.rs b/examples/stm32g4/src/bin/usb_c_pd.rs index 14abd542f..0e80840df 100644 --- a/examples/stm32g4/src/bin/usb_c_pd.rs +++ b/examples/stm32g4/src/bin/usb_c_pd.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 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, CcPull, CcSel, CcVState, Ucpd}; | 6 | use embassy_stm32::ucpd::{self, CcPhy, CcPull, CcSel, CcVState, Ucpd}; |
| 7 | use embassy_stm32::Config; | 7 | use embassy_stm32::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 _}; |
| @@ -16,17 +16,17 @@ enum CableOrientation { | |||
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | // Returns true when the cable | 18 | // Returns true when the cable |
| 19 | async fn wait_attached<T: ucpd::Instance>(ucpd: &mut Ucpd<'_, T>) -> CableOrientation { | 19 | async fn wait_attached<T: ucpd::Instance>(cc_phy: &mut CcPhy<'_, T>) -> CableOrientation { |
| 20 | loop { | 20 | loop { |
| 21 | let (cc1, cc2) = ucpd.cc_vstate(); | 21 | let (cc1, cc2) = cc_phy.vstate(); |
| 22 | if cc1 == CcVState::LOWEST && cc2 == CcVState::LOWEST { | 22 | if cc1 == CcVState::LOWEST && cc2 == CcVState::LOWEST { |
| 23 | // Detached, wait until attached by monitoring the CC lines. | 23 | // Detached, wait until attached by monitoring the CC lines. |
| 24 | ucpd.wait_for_cc_vstate_change().await; | 24 | cc_phy.wait_for_vstate_change().await; |
| 25 | continue; | 25 | continue; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | // Attached, wait for CC lines to be stable for tCCDebounce (100..200ms). | 28 | // Attached, wait for CC lines to be stable for tCCDebounce (100..200ms). |
| 29 | if with_timeout(Duration::from_millis(100), ucpd.wait_for_cc_vstate_change()) | 29 | if with_timeout(Duration::from_millis(100), cc_phy.wait_for_vstate_change()) |
| 30 | .await | 30 | .await |
| 31 | .is_ok() | 31 | .is_ok() |
| 32 | { | 32 | { |
| @@ -50,10 +50,11 @@ async fn main(_spawner: Spawner) { | |||
| 50 | 50 | ||
| 51 | info!("Hello World!"); | 51 | info!("Hello World!"); |
| 52 | 52 | ||
| 53 | let mut ucpd = Ucpd::new(p.UCPD1, p.PB6, p.PB4, CcPull::Sink); | 53 | let mut ucpd = Ucpd::new(p.UCPD1, p.PB6, p.PB4); |
| 54 | ucpd.cc_phy().set_pull(CcPull::Sink); | ||
| 54 | 55 | ||
| 55 | info!("Waiting for USB connection..."); | 56 | info!("Waiting for USB connection..."); |
| 56 | let cable_orientation = wait_attached(&mut ucpd).await; | 57 | let cable_orientation = wait_attached(ucpd.cc_phy()).await; |
| 57 | info!("USB cable connected, orientation: {}", cable_orientation); | 58 | info!("USB cable connected, orientation: {}", cable_orientation); |
| 58 | 59 | ||
| 59 | let cc_sel = match cable_orientation { | 60 | let cc_sel = match cable_orientation { |
| @@ -67,7 +68,7 @@ async fn main(_spawner: Spawner) { | |||
| 67 | } | 68 | } |
| 68 | CableOrientation::DebugAccessoryMode => panic!("No PD communication in DAM"), | 69 | CableOrientation::DebugAccessoryMode => panic!("No PD communication in DAM"), |
| 69 | }; | 70 | }; |
| 70 | let mut pd_phy = ucpd.pd_phy(p.DMA1_CH1, p.DMA1_CH2, cc_sel); | 71 | let (_cc_phy, mut pd_phy) = ucpd.split_pd_phy(p.DMA1_CH1, p.DMA1_CH2, cc_sel); |
| 71 | 72 | ||
| 72 | loop { | 73 | loop { |
| 73 | // Enough space for the longest non-extended data message. | 74 | // Enough space for the longest non-extended data message. |
