diff options
| author | Timo Kröger <[email protected]> | 2024-03-07 09:17:05 +0100 |
|---|---|---|
| committer | Timo Kröger <[email protected]> | 2024-03-12 08:14:42 +0100 |
| commit | a3b12226170d6b1a9ded47cc043cc09489cee278 (patch) | |
| tree | a57c8c51effc1ab2850ed186e91c49592b3a1709 /examples | |
| parent | d99fcfd0c285be220c8f0004974567d7d4e2607b (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.rs | 12 |
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 | ||
| 4 | use defmt::{info, Format}; | 4 | use defmt::{info, Format}; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::{ | 6 | use embassy_stm32::ucpd::{self, CcPull, CcVState, Ucpd}; |
| 7 | ucpd::{self, CcPull, CcVState, Ucpd}, | 7 | use embassy_stm32::Config; |
| 8 | Config, | ||
| 9 | }; | ||
| 10 | use embassy_time::{with_timeout, Duration}; | 8 | use embassy_time::{with_timeout, Duration}; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {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 |
| 21 | async fn wait_attached<'d, T: ucpd::Instance>(ucpd: &mut Ucpd<'d, T>) -> CableOrientation { | 19 | async 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 | { |
