Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn on RAW_IO on Windows #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,12 @@ impl Interface {
///
/// * An IN endpoint address must have the top (`0x80`) bit set.
pub fn bulk_in_queue(&self, endpoint: u8) -> Queue<RequestBuffer> {
Queue::new(self.backend.clone(), endpoint, EndpointType::Bulk)
let interface = self.backend.clone();

#[cfg(target_os = "windows")]
interface.enable_raw_io(endpoint);

Queue::new(interface, endpoint, EndpointType::Bulk)
}

/// Create a queue for managing multiple **OUT (device-to-host)** transfers on a **bulk** endpoint.
Expand Down Expand Up @@ -512,7 +517,12 @@ impl Interface {
///
/// * An IN endpoint address must have the top (`0x80`) bit set.
pub fn interrupt_in_queue(&self, endpoint: u8) -> Queue<RequestBuffer> {
Queue::new(self.backend.clone(), endpoint, EndpointType::Interrupt)
let interface = self.backend.clone();

#[cfg(target_os = "windows")]
interface.enable_raw_io(endpoint);

Queue::new(interface, endpoint, EndpointType::Interrupt)
}

/// Create a queue for managing multiple **OUT (device-to-host)** transfers on an **interrupt** endpoint.
Expand Down
22 changes: 21 additions & 1 deletion src/platform/windows_winusb/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use log::{debug, error, info, warn};
use windows_sys::Win32::{
Devices::Usb::{
WinUsb_ControlTransfer, WinUsb_Free, WinUsb_Initialize, WinUsb_ResetPipe,
WinUsb_SetCurrentAlternateSetting, WinUsb_SetPipePolicy, PIPE_TRANSFER_TIMEOUT,
WinUsb_SetCurrentAlternateSetting, WinUsb_SetPipePolicy, PIPE_TRANSFER_TIMEOUT, RAW_IO,
WINUSB_INTERFACE_HANDLE, WINUSB_SETUP_PACKET,
},
Foundation::{GetLastError, FALSE, TRUE},
Expand Down Expand Up @@ -289,6 +289,26 @@ impl WindowsInterface {
}
}
}

pub(crate) fn enable_raw_io(&self, endpoint: u8) {
let enable: u32 = 1;
unsafe {
let r = WinUsb_SetPipePolicy(
self.winusb_handle,
endpoint,
RAW_IO,
size_of_val(&enable) as u32,
&enable as *const u32 as *const c_void,
);
if r == 1 {
debug!(
"WinUsb_SetPipePolicy succeeded to enable RAW_IO on endpoint 0x{endpoint:02X}"
);
} else {
warn!("WinUsb_SetPipePolicy failed to enable RAW_IO on endpoint 0x{endpoint:02X}");
}
}
}
}

impl Drop for WindowsInterface {
Expand Down
Loading