Skip to content

Commit

Permalink
[host-client] Hardcode windows to use interface 0 for now (#64)
Browse files Browse the repository at this point in the history
* Hardcode windows to use interface 0 for now

* Update lockfile
  • Loading branch information
jamesmunns authored Dec 11, 2024
1 parent 553ce5a commit 876dd15
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions example/firmware/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/workbook-host/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions source/postcard-rpc/src/host_client/raw_nusb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:?}"))?;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 876dd15

Please sign in to comment.