Skip to content

Commit

Permalink
Make macOS build again
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatekii committed Dec 26, 2024
1 parent 87da2ca commit 59a7b3e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl Device {

let mut buf = vec![0; 4096];
let len = self.control_in_blocking(
Control {
crate::transfer::Control {
control_type: ControlType::Standard,
recipient: Recipient::Device,
request: STANDARD_REQUEST_GET_DESCRIPTOR,
Expand Down Expand Up @@ -402,10 +402,10 @@ impl Interface {
/// become an error in the future.
pub fn control_in_blocking(
&self,
control: Control,
control: crate::transfer::Control,
data: &mut [u8],
timeout: Duration,
) -> Result<usize, TransferError> {
) -> Result<usize, crate::transfer::TransferError> {
self.backend.control_in_blocking(control, data, timeout)
}

Expand All @@ -423,10 +423,10 @@ impl Interface {
/// become an error in the future.
pub fn control_out_blocking(
&self,
control: Control,
control: crate::transfer::Control,
data: &[u8],
timeout: Duration,
) -> Result<usize, TransferError> {
) -> Result<usize, crate::transfer::TransferError> {
self.backend.control_out_blocking(control, data, timeout)
}

Expand Down
8 changes: 4 additions & 4 deletions src/platform/linux_usbfs/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ impl LinuxDevice {
self.active_config.load(Ordering::SeqCst)
}

pub(crate) fn set_configuration(&self, configuration: u8) -> Result<(), Error> {
pub(crate) async fn set_configuration(&self, configuration: u8) -> Result<(), Error> {
usbfs::set_configuration(&self.fd, configuration)?;
self.active_config.store(configuration, Ordering::SeqCst);
Ok(())
}

pub(crate) fn reset(&self) -> Result<(), Error> {
pub(crate) async fn reset(&self) -> Result<(), Error> {
usbfs::reset(&self.fd)?;
Ok(())
}
Expand Down Expand Up @@ -454,7 +454,7 @@ impl LinuxInterface {
self.device.control_out_blocking(control, data, timeout)
}

pub fn set_alt_setting(&self, alt_setting: u8) -> Result<(), Error> {
pub async fn set_alt_setting(&self, alt_setting: u8) -> Result<(), Error> {
debug!(
"Set interface {} alt setting to {alt_setting}",
self.interface_number
Expand All @@ -466,7 +466,7 @@ impl LinuxInterface {
)?)
}

pub fn clear_halt(&self, endpoint: u8) -> Result<(), Error> {
pub async fn clear_halt(&self, endpoint: u8) -> Result<(), Error> {
debug!("Clear halt, endpoint {endpoint:02x}");
Ok(usbfs::clear_halt(&self.device.fd, endpoint)?)
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/linux_usbfs/usbfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ pub fn control<Fd: AsFd>(fd: Fd, transfer: CtrlTransfer) -> io::Result<usize> {
}
}

pub fn clear_halt<Fd: AsFd>(fd: Fd, endpoint: u8) -> io::Result<()> {
pub async fn clear_halt<Fd: AsFd>(fd: Fd, endpoint: u8) -> io::Result<()> {
unsafe {
let ctl =
ioctl::Setter::<ioctl::ReadOpcode<b'U', 21, c_uint>, c_uint>::new(endpoint.into());
Expand Down
8 changes: 4 additions & 4 deletions src/platform/macos_iokit/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl MacDevice {
Ok(())
}

pub(crate) fn set_configuration(&self, configuration: u8) -> Result<(), Error> {
pub(crate) async fn set_configuration(&self, configuration: u8) -> Result<(), Error> {
self.require_open_exclusive()?;
unsafe {
check_iokit_return(call_iokit_function!(
Expand All @@ -121,7 +121,7 @@ impl MacDevice {
Ok(())
}

pub(crate) fn reset(&self) -> Result<(), Error> {
pub(crate) async fn reset(&self) -> Result<(), Error> {
self.require_open_exclusive()?;
unsafe {
check_iokit_return(call_iokit_function!(
Expand Down Expand Up @@ -297,7 +297,7 @@ impl MacInterface {
self.device.control_out_blocking(control, data, timeout)
}

pub fn set_alt_setting(&self, alt_setting: u8) -> Result<(), Error> {
pub async fn set_alt_setting(&self, alt_setting: u8) -> Result<(), Error> {
debug!(
"Set interface {} alt setting to {alt_setting}",
self.interface_number
Expand All @@ -318,7 +318,7 @@ impl MacInterface {
Ok(())
}

pub fn clear_halt(&self, endpoint: u8) -> Result<(), Error> {
pub async fn clear_halt(&self, endpoint: u8) -> Result<(), Error> {
debug!("Clear halt, endpoint {endpoint:02x}");

let pipe_ref = {
Expand Down
8 changes: 4 additions & 4 deletions src/platform/windows_winusb/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl WindowsDevice {
self.config_descriptors.iter().map(|d| &d[..])
}

pub(crate) fn set_configuration(&self, _configuration: u8) -> Result<(), Error> {
pub(crate) async fn set_configuration(&self, _configuration: u8) -> Result<(), Error> {
Err(io::Error::new(
ErrorKind::Unsupported,
"set_configuration not supported by WinUSB",
Expand All @@ -101,7 +101,7 @@ impl WindowsDevice {
HubPort::by_child_devinst(self.devinst)?.get_descriptor(desc_type, desc_index, language_id)
}

pub(crate) fn reset(&self) -> Result<(), Error> {
pub(crate) async fn reset(&self) -> Result<(), Error> {
Err(io::Error::new(
ErrorKind::Unsupported,
"reset not supported by WinUSB",
Expand Down Expand Up @@ -456,7 +456,7 @@ impl WindowsInterface {
}
}

pub fn set_alt_setting(&self, alt_setting: u8) -> Result<(), Error> {
pub async fn set_alt_setting(&self, alt_setting: u8) -> Result<(), Error> {
unsafe {
let r = WinUsb_SetCurrentAlternateSetting(self.winusb_handle, alt_setting.into());
if r == TRUE {
Expand All @@ -467,7 +467,7 @@ impl WindowsInterface {
}
}

pub fn clear_halt(&self, endpoint: u8) -> Result<(), Error> {
pub async fn clear_halt(&self, endpoint: u8) -> Result<(), Error> {
debug!("Clear halt, endpoint {endpoint:02x}");
unsafe {
let r = WinUsb_ResetPipe(self.winusb_handle, endpoint);
Expand Down
2 changes: 2 additions & 0 deletions src/transfer/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum ControlType {
Vendor = 2,
}

#[cfg(target_arch = "wasm32")]
impl From<ControlType> for web_sys::UsbRequestType {
fn from(value: ControlType) -> Self {
match value {
Expand Down Expand Up @@ -52,6 +53,7 @@ pub enum Recipient {
Other = 3,
}

#[cfg(target_arch = "wasm32")]
impl From<Recipient> for web_sys::UsbRecipient {
fn from(value: Recipient) -> Self {
match value {
Expand Down
4 changes: 2 additions & 2 deletions src/transfer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ pub use control::{Control, ControlIn, ControlOut, ControlType, Direction, Recipi

mod internal;
pub(crate) use internal::{
notify_completion, PlatformSubmit, PlatformTransfer, TransferHandle, TransferInner,
TransferRequest,
notify_completion, PlatformSubmit, PlatformTransfer, TransferHandle, TransferRequest,
};

/// Endpoint type.
Expand Down Expand Up @@ -98,6 +97,7 @@ impl From<TransferError> for io::Error {
}
}

#[cfg(target_arch = "wasm32")]
pub(crate) fn web_to_nusb_status(status: web_sys::UsbTransferStatus) -> Result<(), TransferError> {
match status {
web_sys::UsbTransferStatus::Ok => Ok(()),
Expand Down

0 comments on commit 59a7b3e

Please sign in to comment.