aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTimo Kröger <[email protected]>2024-03-07 09:17:05 +0100
committerTimo Kröger <[email protected]>2024-03-12 08:14:42 +0100
commita3b12226170d6b1a9ded47cc043cc09489cee278 (patch)
treea57c8c51effc1ab2850ed186e91c49592b3a1709 /examples
parentd99fcfd0c285be220c8f0004974567d7d4e2607b (diff)
[UCPD] Improve Type-C CC handling
* Improved interrupt handling: Clear flags in ISR, check state change in future * Disable pull-up/pull-down resistors and voltage monitor on drop * nightly rustfmt
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32g4/src/bin/usb_c_pd.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/examples/stm32g4/src/bin/usb_c_pd.rs b/examples/stm32g4/src/bin/usb_c_pd.rs
index c442ab0a7..7a0065087 100644
--- a/examples/stm32g4/src/bin/usb_c_pd.rs
+++ b/examples/stm32g4/src/bin/usb_c_pd.rs
@@ -3,10 +3,8 @@
3 3
4use defmt::{info, Format}; 4use defmt::{info, Format};
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_stm32::{ 6use embassy_stm32::ucpd::{self, CcPull, CcVState, Ucpd};
7 ucpd::{self, CcPull, CcVState, Ucpd}, 7use embassy_stm32::Config;
8 Config,
9};
10use embassy_time::{with_timeout, Duration}; 8use embassy_time::{with_timeout, Duration};
11use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
12 10
@@ -18,17 +16,17 @@ enum CableOrientation {
18} 16}
19 17
20// Returns true when the cable 18// Returns true when the cable
21async fn wait_attached<'d, T: ucpd::Instance>(ucpd: &mut Ucpd<'d, T>) -> CableOrientation { 19async fn wait_attached<T: ucpd::Instance>(ucpd: &mut Ucpd<'_, T>) -> CableOrientation {
22 loop { 20 loop {
23 let (cc1, cc2) = ucpd.cc_vstate(); 21 let (cc1, cc2) = ucpd.cc_vstate();
24 if cc1 == CcVState::LOWEST && cc2 == CcVState::LOWEST { 22 if cc1 == CcVState::LOWEST && cc2 == CcVState::LOWEST {
25 // Detached, wait until attached by monitoring the CC lines. 23 // Detached, wait until attached by monitoring the CC lines.
26 ucpd.wait_for_cc_change().await; 24 ucpd.wait_for_cc_vstate_change().await;
27 continue; 25 continue;
28 } 26 }
29 27
30 // 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).
31 if with_timeout(Duration::from_millis(100), ucpd.wait_for_cc_change()) 29 if with_timeout(Duration::from_millis(100), ucpd.wait_for_cc_vstate_change())
32 .await 30 .await
33 .is_ok() 31 .is_ok()
34 { 32 {