[UCPD] Improve example and defmt Format for enums

This commit is contained in:
Timo Kröger 2024-03-07 19:54:55 +01:00 committed by Timo Kröger
parent 5e271ff31b
commit b7972048a1
2 changed files with 12 additions and 2 deletions

View File

@ -30,6 +30,7 @@ use crate::rcc::RccPeripheral;
/// Pull-up or Pull-down resistor state of both CC lines.
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum CcPull {
/// Analog PHY for CC pin disabled.
Disabled,
@ -209,6 +210,7 @@ impl<'d, T: Instance> Ucpd<'d, T> {
/// Receive Error.
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum RxError {
/// Incorrect CRC or truncated message (a line becoming static before EOP is met).
Crc,
@ -219,6 +221,7 @@ pub enum RxError {
/// Transmit Error.
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum TxError {
/// Concurrent receive in progress or excessive noise on the line.
Discarded,

View File

@ -1,7 +1,7 @@
#![no_std]
#![no_main]
use defmt::{info, Format};
use defmt::{error, info, Format};
use embassy_executor::Spawner;
use embassy_stm32::ucpd::{self, CcPull, CcSel, CcVState, Ucpd};
use embassy_stm32::Config;
@ -69,5 +69,12 @@ async fn main(_spawner: Spawner) {
};
let mut pd_phy = ucpd.pd_phy(p.DMA1_CH1, p.DMA1_CH2, cc_sel);
loop {}
loop {
// Enough space for the longest non-extended data message.
let mut buf = [0_u8; 30];
match pd_phy.receive(buf.as_mut()).await {
Ok(n) => info!("USB PD RX: {=[u8]:?}", &buf[..n]),
Err(e) => error!("USB PD RX: {}", e),
}
}
}