[UCPD] Improve example and defmt Format for enums
This commit is contained in:
parent
5e271ff31b
commit
b7972048a1
@ -30,6 +30,7 @@ use crate::rcc::RccPeripheral;
|
|||||||
|
|
||||||
/// Pull-up or Pull-down resistor state of both CC lines.
|
/// Pull-up or Pull-down resistor state of both CC lines.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub enum CcPull {
|
pub enum CcPull {
|
||||||
/// Analog PHY for CC pin disabled.
|
/// Analog PHY for CC pin disabled.
|
||||||
Disabled,
|
Disabled,
|
||||||
@ -209,6 +210,7 @@ impl<'d, T: Instance> Ucpd<'d, T> {
|
|||||||
|
|
||||||
/// Receive Error.
|
/// Receive Error.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub enum RxError {
|
pub enum RxError {
|
||||||
/// Incorrect CRC or truncated message (a line becoming static before EOP is met).
|
/// Incorrect CRC or truncated message (a line becoming static before EOP is met).
|
||||||
Crc,
|
Crc,
|
||||||
@ -219,6 +221,7 @@ pub enum RxError {
|
|||||||
|
|
||||||
/// Transmit Error.
|
/// Transmit Error.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub enum TxError {
|
pub enum TxError {
|
||||||
/// Concurrent receive in progress or excessive noise on the line.
|
/// Concurrent receive in progress or excessive noise on the line.
|
||||||
Discarded,
|
Discarded,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use defmt::{info, Format};
|
use defmt::{error, info, Format};
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_stm32::ucpd::{self, CcPull, CcSel, CcVState, Ucpd};
|
use embassy_stm32::ucpd::{self, CcPull, CcSel, CcVState, Ucpd};
|
||||||
use embassy_stm32::Config;
|
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);
|
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),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user