Add some comments on the example.
This commit is contained in:
parent
0320500f0f
commit
9a6d11281d
@ -34,13 +34,18 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
while !power.usbregstatus.read().vbusdetect().is_vbus_present() {}
|
while !power.usbregstatus.read().vbusdetect().is_vbus_present() {}
|
||||||
info!("vbus OK");
|
info!("vbus OK");
|
||||||
|
|
||||||
|
// Create the driver, from the HAL.
|
||||||
let irq = interrupt::take!(USBD);
|
let irq = interrupt::take!(USBD);
|
||||||
let driver = Driver::new(p.USBD, irq);
|
let driver = Driver::new(p.USBD, irq);
|
||||||
|
|
||||||
|
// Create embassy-usb Config
|
||||||
let config = Config::new(0xc0de, 0xcafe);
|
let config = Config::new(0xc0de, 0xcafe);
|
||||||
|
|
||||||
|
// Create embassy-usb DeviceBuilder using the driver and config.
|
||||||
|
// It needs some buffers for building the descriptors.
|
||||||
let mut device_descriptor = [0; 256];
|
let mut device_descriptor = [0; 256];
|
||||||
let mut config_descriptor = [0; 256];
|
let mut config_descriptor = [0; 256];
|
||||||
let mut bos_descriptor = [0; 256];
|
let mut bos_descriptor = [0; 256];
|
||||||
|
|
||||||
let mut builder = UsbDeviceBuilder::new(
|
let mut builder = UsbDeviceBuilder::new(
|
||||||
driver,
|
driver,
|
||||||
config,
|
config,
|
||||||
@ -49,11 +54,16 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
&mut bos_descriptor,
|
&mut bos_descriptor,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Create classes on the builder.
|
||||||
let mut class = CdcAcmClass::new(&mut builder, 64);
|
let mut class = CdcAcmClass::new(&mut builder, 64);
|
||||||
|
|
||||||
|
// Build the builder.
|
||||||
let mut usb = builder.build();
|
let mut usb = builder.build();
|
||||||
|
|
||||||
|
// Run the USB device.
|
||||||
let fut1 = usb.run();
|
let fut1 = usb.run();
|
||||||
|
|
||||||
|
// Do stuff with the classes
|
||||||
let fut2 = async {
|
let fut2 = async {
|
||||||
let mut buf = [0; 64];
|
let mut buf = [0; 64];
|
||||||
loop {
|
loop {
|
||||||
@ -72,5 +82,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Run everything concurrently.
|
||||||
|
// If we had made everything `'static` above instead, we could do this using separate tasks instead.
|
||||||
join3(fut1, fut2, fut3).await;
|
join3(fut1, fut2, fut3).await;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user