clean code
This commit is contained in:
parent
321983b9e3
commit
9f32a4ec9b
@ -3,21 +3,18 @@
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use core::default::Default;
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
use defmt_rtt as _;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_usb::{
|
||||
class::cdc_acm::{CdcAcmClass, State},
|
||||
driver::EndpointError,
|
||||
Builder,
|
||||
};
|
||||
use futures::future::join;
|
||||
// use embassy_usb::{
|
||||
// class::cdc_acm::{CdcAcmClass, State},
|
||||
// driver::EndpointError,
|
||||
// Builder,
|
||||
// };
|
||||
// use stm32_metapac;
|
||||
|
||||
use u5_lib::{
|
||||
pwr::vddusb_monitor_up,
|
||||
usb_otg_hs::mod_new::{cdc_acm_ep2_read, power_up_init, setup_process},
|
||||
*,
|
||||
};
|
||||
@ -72,91 +69,91 @@ fn panic(_info: &PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
pub async fn usb_task() {
|
||||
let _ep_out_buffer = [0u8; 256];
|
||||
let mut config = usb_otg_hs::Config::default();
|
||||
config.vbus_detection = false;
|
||||
let driver = usb_otg_hs::Driver::new(config, gpio::USB_DM_PA11, gpio::USB_DP_PA12);
|
||||
// #[embassy_executor::task]
|
||||
// pub async fn usb_task() {
|
||||
// let _ep_out_buffer = [0u8; 256];
|
||||
// let mut config = usb_otg_hs::Config::default();
|
||||
// config.vbus_detection = false;
|
||||
// let driver = usb_otg_hs::Driver::new(config, gpio::USB_DM_PA11, gpio::USB_DP_PA12);
|
||||
//
|
||||
// // // Create embassy-usb Config
|
||||
// let mut config = embassy_usb::Config::new(0xaaaa, 0xefba);
|
||||
// config.manufacturer = Some("ggeta");
|
||||
// config.product = Some("USB-serial example");
|
||||
// config.serial_number = Some("12345678");
|
||||
//
|
||||
// config.device_class = 0xEF;
|
||||
// config.device_sub_class = 0x02;
|
||||
// config.device_protocol = 0x01;
|
||||
// config.composite_with_iads = true;
|
||||
//
|
||||
// let mut device_descriptor = [0; 512];
|
||||
// let mut config_descriptor = [0; 512];
|
||||
// let mut bos_descriptor = [0; 512];
|
||||
// let mut control_buf = [0; 64];
|
||||
// let mut msos_descriptor = [0; 512];
|
||||
//
|
||||
// let mut state = State::new();
|
||||
// // USART1.send("starting usb task new!\n\n".as_bytes());
|
||||
//
|
||||
// let mut builder = Builder::new(
|
||||
// driver,
|
||||
// config,
|
||||
// &mut device_descriptor,
|
||||
// &mut config_descriptor,
|
||||
// &mut bos_descriptor,
|
||||
// &mut msos_descriptor,
|
||||
// &mut control_buf,
|
||||
// );
|
||||
//
|
||||
// let mut class = CdcAcmClass::new(&mut builder, &mut state, 64);
|
||||
// // USART1.send("declare class success!\n".as_bytes());
|
||||
// // Build the builder.
|
||||
// let mut usb = builder.build();
|
||||
// // USART1.send("success!\n".as_bytes());
|
||||
// let usb_fut = usb.run(); // Run the USB device.
|
||||
// let handler_fut = async {
|
||||
// loop {
|
||||
// class.wait_connection().await;
|
||||
// defmt::info!("connected");
|
||||
// let _ = usb_handler(&mut class).await;
|
||||
// defmt::info!("disconnected");
|
||||
// }
|
||||
// };
|
||||
// // USART1.send("start usb task success!\n".as_bytes());
|
||||
// join(usb_fut, handler_fut).await; // Run everything concurrently.
|
||||
// }
|
||||
|
||||
// // Create embassy-usb Config
|
||||
let mut config = embassy_usb::Config::new(0xaaaa, 0xefba);
|
||||
config.manufacturer = Some("ggeta");
|
||||
config.product = Some("USB-serial example");
|
||||
config.serial_number = Some("12345678");
|
||||
// struct Disconnected {}
|
||||
|
||||
config.device_class = 0xEF;
|
||||
config.device_sub_class = 0x02;
|
||||
config.device_protocol = 0x01;
|
||||
config.composite_with_iads = true;
|
||||
|
||||
let mut device_descriptor = [0; 512];
|
||||
let mut config_descriptor = [0; 512];
|
||||
let mut bos_descriptor = [0; 512];
|
||||
let mut control_buf = [0; 64];
|
||||
let mut msos_descriptor = [0; 512];
|
||||
|
||||
let mut state = State::new();
|
||||
// USART1.send("starting usb task new!\n\n".as_bytes());
|
||||
|
||||
let mut builder = Builder::new(
|
||||
driver,
|
||||
config,
|
||||
&mut device_descriptor,
|
||||
&mut config_descriptor,
|
||||
&mut bos_descriptor,
|
||||
&mut msos_descriptor,
|
||||
&mut control_buf,
|
||||
);
|
||||
|
||||
let mut class = CdcAcmClass::new(&mut builder, &mut state, 64);
|
||||
// USART1.send("declare class success!\n".as_bytes());
|
||||
// Build the builder.
|
||||
let mut usb = builder.build();
|
||||
// USART1.send("success!\n".as_bytes());
|
||||
let usb_fut = usb.run(); // Run the USB device.
|
||||
let handler_fut = async {
|
||||
loop {
|
||||
class.wait_connection().await;
|
||||
defmt::info!("connected");
|
||||
let _ = usb_handler(&mut class).await;
|
||||
defmt::info!("disconnected");
|
||||
}
|
||||
};
|
||||
// USART1.send("start usb task success!\n".as_bytes());
|
||||
join(usb_fut, handler_fut).await; // Run everything concurrently.
|
||||
}
|
||||
|
||||
struct Disconnected {}
|
||||
|
||||
impl From<EndpointError> for Disconnected {
|
||||
fn from(val: EndpointError) -> Self {
|
||||
match val {
|
||||
EndpointError::BufferOverflow => panic!("Buffer overflow"),
|
||||
EndpointError::Disabled => Disconnected {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn usb_handler<'d>(
|
||||
class: &mut CdcAcmClass<'d, usb_otg_hs::Driver>,
|
||||
) -> Result<(), Disconnected> {
|
||||
let mut buf: [u8; 128] = [0; 128];
|
||||
// the maximum size of the command is 64 bytes
|
||||
defmt::info!("start usb handler");
|
||||
loop {
|
||||
// select(future1, future2)
|
||||
let ret = class.read_packet(&mut buf).await;
|
||||
match ret {
|
||||
Ok(n) => {
|
||||
defmt::info!("read {} bytes", n);
|
||||
class.write_packet(&buf[0..n]).await.unwrap();
|
||||
}
|
||||
Err(e) => {
|
||||
defmt::info!("error: {:?}", e);
|
||||
return Err(e.into());
|
||||
}
|
||||
}
|
||||
// class.write_packet(&buf[0..n]).await.unwrap();
|
||||
}
|
||||
}
|
||||
// impl From<EndpointError> for Disconnected {
|
||||
// fn from(val: EndpointError) -> Self {
|
||||
// match val {
|
||||
// EndpointError::BufferOverflow => panic!("Buffer overflow"),
|
||||
// EndpointError::Disabled => Disconnected {},
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// async fn usb_handler<'d>(
|
||||
// class: &mut CdcAcmClass<'d, usb_otg_hs::Driver>,
|
||||
// ) -> Result<(), Disconnected> {
|
||||
// let mut buf: [u8; 128] = [0; 128];
|
||||
// // the maximum size of the command is 64 bytes
|
||||
// defmt::info!("start usb handler");
|
||||
// loop {
|
||||
// // select(future1, future2)
|
||||
// let ret = class.read_packet(&mut buf).await;
|
||||
// match ret {
|
||||
// Ok(n) => {
|
||||
// defmt::info!("read {} bytes", n);
|
||||
// class.write_packet(&buf[0..n]).await.unwrap();
|
||||
// }
|
||||
// Err(e) => {
|
||||
// defmt::info!("error: {:?}", e);
|
||||
// return Err(e.into());
|
||||
// }
|
||||
// }
|
||||
// // class.write_packet(&buf[0..n]).await.unwrap();
|
||||
// }
|
||||
// }
|
||||
|
74
tmp.txt
Normal file
74
tmp.txt
Normal file
@ -0,0 +1,74 @@
|
||||
INFO setup led finished!
|
||||
└─ usb_hs::____embassy_main_task::{async_fn#0} @ src/bin/usb_hs.rs:37
|
||||
TRACE init
|
||||
└─ u5_lib::usb_otg_hs::mod_new::power_up_init @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:12
|
||||
TRACE USB power stabilized
|
||||
└─ u5_lib::usb_otg_hs::mod_new::power_up_init @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:56
|
||||
INFO restore_irqs
|
||||
└─ u5_lib::usb_otg_hs::restore_irqs @ /home/zong/Code/u5_new/src/usb_otg_hs/mod.rs:84
|
||||
TRACE USB IRQs start
|
||||
└─ u5_lib::usb_otg_hs::mod_new::power_up_init @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:91
|
||||
TRACE Core id 00005000
|
||||
└─ u5_lib::usb_otg_hs::mod_new::power_up_init @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:96
|
||||
INFO vddusb monitor finished!
|
||||
└─ usb_hs::____embassy_main_task::{async_fn#0} @ src/bin/usb_hs.rs:44
|
||||
INFO OTG_HS interrupt with ints 44000020 and mask c00c3814, and 40000000
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:557
|
||||
INFO srqint
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:581
|
||||
INFO usb init finished!
|
||||
└─ usb_hs::____embassy_main_task::{async_fn#0} @ src/bin/usb_hs.rs:50
|
||||
TRACE read start len=8
|
||||
└─ u5_lib::usb_otg_hs::mod_new::read0::{async_fn#0} @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:371
|
||||
INFO doepdma0: 20001a70
|
||||
└─ u5_lib::usb_otg_hs::mod_new::read0::{async_fn#0} @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:374
|
||||
INFO *************************************
|
||||
└─ u5_lib::usb_otg_hs::mod_new::read0::{async_fn#0} @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:376
|
||||
INFO doepctl0: 8000
|
||||
└─ u5_lib::usb_otg_hs::mod_new::read0::{async_fn#0} @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:377
|
||||
INFO doeptsiz0: 0
|
||||
└─ u5_lib::usb_otg_hs::mod_new::read0::{async_fn#0} @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:378
|
||||
INFO doepctl0: 8000
|
||||
└─ u5_lib::usb_otg_hs::mod_new::read0::{async_fn#0} @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:387
|
||||
INFO doepctl0: 8000
|
||||
└─ u5_lib::usb_otg_hs::mod_new::read0::{async_fn#0} @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:404
|
||||
INFO doeptsiz0: 20080000
|
||||
└─ u5_lib::usb_otg_hs::mod_new::read0::{async_fn#0} @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:405
|
||||
INFO OTG_HS interrupt with ints 04008c20 and mask c00c3814, and 00000800
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:557
|
||||
INFO usbsusp
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:566
|
||||
INFO OTG_HS interrupt with ints 04809420 and mask c00c3814, and 00001000
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:557
|
||||
INFO usbrst
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:585
|
||||
TRACE init_fifo
|
||||
└─ u5_lib::usb_otg_hs::mod_new::init_fifo @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:217
|
||||
INFO init_endpoints
|
||||
└─ u5_lib::usb_otg_hs::endpoint_new::init_endpoint @ /home/zong/Code/u5_new/src/usb_otg_hs/endpoint_new.rs:254
|
||||
INFO OTG_HS interrupt with ints 0480a420 and mask c00c3814, and 00002000
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:557
|
||||
INFO enumdne
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:570
|
||||
TRACE doepctl0: 28000
|
||||
└─ u5_lib::usb_otg_hs::mod_new::init_enumeration_done @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:258
|
||||
TRACE doepdma0: 20001a70
|
||||
└─ u5_lib::usb_otg_hs::mod_new::init_enumeration_done @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:259
|
||||
TRACE doeptsiz0: 60080000
|
||||
└─ u5_lib::usb_otg_hs::mod_new::init_enumeration_done @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:260
|
||||
TRACE irq mask 0: c00c3814
|
||||
└─ u5_lib::usb_otg_hs::mod_new::init_enumeration_done @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:261
|
||||
INFO OTG_HS interrupt with ints 04808438 and mask c00c3814, and 00000010
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:557
|
||||
INFO rxflvl with ep_num: 0, len: 8
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:600
|
||||
TRACE SETUP_DATA_RX, with data 1000680, 400000, [80, 6, 0, 1, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:611
|
||||
INFO rxflvl with ep_num: 0, len: 0
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:600
|
||||
TRACE OUT_DATA_DONE ep=0
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:632
|
||||
INFO rxflvl with ep_num: 0, len: 0
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:600
|
||||
TRACE SETUP_DATA_DONE ep=0
|
||||
└─ u5_lib::usb_otg_hs::mod_new::on_interrupt @ /home/zong/Code/u5_new/src/usb_otg_hs/mod_new.rs:636
|
Loading…
x
Reference in New Issue
Block a user