From 876dd15cec222d180530367ace9d72b0a05eda47 Mon Sep 17 00:00:00 2001 From: James Munns Date: Wed, 11 Dec 2024 14:54:29 +0100 Subject: [PATCH] [host-client] Hardcode windows to use interface 0 for now (#64) * Hardcode windows to use interface 0 for now * Update lockfile --- example/firmware/Cargo.lock | 4 ++-- example/workbook-host/Cargo.lock | 4 ++-- .../postcard-rpc/src/host_client/raw_nusb.rs | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/example/firmware/Cargo.lock b/example/firmware/Cargo.lock index 7e0415c..8d8de2c 100644 --- a/example/firmware/Cargo.lock +++ b/example/firmware/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "accelerometer" @@ -1135,7 +1135,7 @@ dependencies = [ [[package]] name = "postcard-rpc" -version = "0.11.0" +version = "0.11.1" dependencies = [ "embassy-executor", "embassy-futures 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/example/workbook-host/Cargo.lock b/example/workbook-host/Cargo.lock index 54e0132..7c2fa43 100644 --- a/example/workbook-host/Cargo.lock +++ b/example/workbook-host/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -477,7 +477,7 @@ dependencies = [ [[package]] name = "postcard-rpc" -version = "0.11.0" +version = "0.11.1" dependencies = [ "heapless 0.8.0", "maitake-sync", diff --git a/source/postcard-rpc/src/host_client/raw_nusb.rs b/source/postcard-rpc/src/host_client/raw_nusb.rs index 216e1cd..7881e16 100644 --- a/source/postcard-rpc/src/host_client/raw_nusb.rs +++ b/source/postcard-rpc/src/host_client/raw_nusb.rs @@ -49,6 +49,13 @@ where /// /// This constructor is available when the `raw-nusb` feature is enabled. /// + /// ## Platform specific support + /// + /// When using Windows, the WinUSB driver does not allow enumerating interfaces. + /// When on windows, this method will ALWAYS try to connect to interface zero. + /// This limitation may be removed in the future, and if so, will be changed to + /// look for the first interface with the class of 0xFF. + /// /// ## Example /// /// ```rust,no_run @@ -85,10 +92,18 @@ where .map_err(|e| format!("Error listing devices: {e:?}"))? .find(func) .ok_or_else(|| String::from("Failed to find matching nusb device!"))?; + + // NOTE: We can't enumerate interfaces on Windows. For now, just use + // a hardcoded interface of zero instead of trying to find the right one + #[cfg(not(target_os = "windows"))] let interface_id = x .interfaces() .position(|i| i.class() == 0xFF) .ok_or_else(|| String::from("Failed to find matching interface!!"))?; + + #[cfg(target_os = "windows")] + let interface_id = 0; + let dev = x .open() .map_err(|e| format!("Failed opening device: {e:?}"))?; @@ -122,6 +137,12 @@ where /// /// This constructor is available when the `raw-nusb` feature is enabled. /// + /// ## Platform specific support + /// + /// When using Windows, the WinUSB driver does not allow enumerating interfaces. + /// Therefore, this constructor is not available on windows. This limitation may + /// be removed in the future. + /// /// ## Example /// /// ```rust,no_run @@ -150,6 +171,7 @@ where /// VarSeqKind::Seq1, /// ).unwrap(); /// ``` + #[cfg(not(target_os = "windows"))] pub fn try_new_raw_nusb_with_interface< F1: FnMut(&DeviceInfo) -> bool, F2: FnMut(&InterfaceInfo) -> bool,