aboutsummaryrefslogtreecommitdiff
path: root/examples/rp/src/bin
diff options
context:
space:
mode:
authorkalkyl <[email protected]>2024-04-30 09:59:06 +0200
committerkalkyl <[email protected]>2024-04-30 09:59:06 +0200
commit7896e8aba7d08b46700b370def152de2b03feaad (patch)
tree79521a40e94824770483eceb60087c11f91e0a86 /examples/rp/src/bin
parent56a7b10064b830b1be1933085a5845d0d6be5f2e (diff)
rp: WebUSB example - add Windows compatibility
Diffstat (limited to 'examples/rp/src/bin')
-rw-r--r--examples/rp/src/bin/usb_webusb.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/examples/rp/src/bin/usb_webusb.rs b/examples/rp/src/bin/usb_webusb.rs
index 09f2c1cfd..e73938ac9 100644
--- a/examples/rp/src/bin/usb_webusb.rs
+++ b/examples/rp/src/bin/usb_webusb.rs
@@ -25,6 +25,7 @@ use embassy_rp::peripherals::USB;
25use embassy_rp::usb::{Driver as UsbDriver, InterruptHandler}; 25use embassy_rp::usb::{Driver as UsbDriver, InterruptHandler};
26use embassy_usb::class::web_usb::{Config as WebUsbConfig, State, Url, WebUsb}; 26use embassy_usb::class::web_usb::{Config as WebUsbConfig, State, Url, WebUsb};
27use embassy_usb::driver::{Driver, Endpoint, EndpointIn, EndpointOut}; 27use embassy_usb::driver::{Driver, Endpoint, EndpointIn, EndpointOut};
28use embassy_usb::msos::{self, windows_version};
28use embassy_usb::{Builder, Config}; 29use embassy_usb::{Builder, Config};
29use {defmt_rtt as _, panic_probe as _}; 30use {defmt_rtt as _, panic_probe as _};
30 31
@@ -32,6 +33,9 @@ bind_interrupts!(struct Irqs {
32 USBCTRL_IRQ => InterruptHandler<USB>; 33 USBCTRL_IRQ => InterruptHandler<USB>;
33}); 34});
34 35
36// This is a randomly generated GUID to allow clients on Windows to find our device
37const DEVICE_INTERFACE_GUIDS: &[&str] = &["{AFB9A6FB-30BA-44BC-9232-806CFC875321}"];
38
35#[embassy_executor::main] 39#[embassy_executor::main]
36async fn main(_spawner: Spawner) { 40async fn main(_spawner: Spawner) {
37 let p = embassy_rp::init(Default::default()); 41 let p = embassy_rp::init(Default::default());
@@ -58,6 +62,7 @@ async fn main(_spawner: Spawner) {
58 let mut config_descriptor = [0; 256]; 62 let mut config_descriptor = [0; 256];
59 let mut bos_descriptor = [0; 256]; 63 let mut bos_descriptor = [0; 256];
60 let mut control_buf = [0; 64]; 64 let mut control_buf = [0; 64];
65 let mut msos_descriptor = [0; 256];
61 66
62 let webusb_config = WebUsbConfig { 67 let webusb_config = WebUsbConfig {
63 max_packet_size: 64, 68 max_packet_size: 64,
@@ -73,10 +78,23 @@ async fn main(_spawner: Spawner) {
73 config, 78 config,
74 &mut config_descriptor, 79 &mut config_descriptor,
75 &mut bos_descriptor, 80 &mut bos_descriptor,
76 &mut [], // no msos descriptors 81 &mut msos_descriptor,
77 &mut control_buf, 82 &mut control_buf,
78 ); 83 );
79 84
85 // Add the Microsoft OS Descriptor (MSOS/MOD) descriptor.
86 // We tell Windows that this entire device is compatible with the "WINUSB" feature,
87 // which causes it to use the built-in WinUSB driver automatically, which in turn
88 // can be used by libusb/rusb software without needing a custom driver or INF file.
89 // In principle you might want to call msos_feature() just on a specific function,
90 // if your device also has other functions that still use standard class drivers.
91 builder.msos_descriptor(windows_version::WIN8_1, 0);
92 builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
93 builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new(
94 "DeviceInterfaceGUIDs",
95 msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
96 ));
97
80 // Create classes on the builder (WebUSB just needs some setup, but doesn't return anything) 98 // Create classes on the builder (WebUSB just needs some setup, but doesn't return anything)
81 WebUsb::configure(&mut builder, &mut state, &webusb_config); 99 WebUsb::configure(&mut builder, &mut state, &webusb_config);
82 // Create some USB bulk endpoints for testing. 100 // Create some USB bulk endpoints for testing.