From 8b624b01363aca5a6379835eef89d613effb2b00 Mon Sep 17 00:00:00 2001 From: G2-Games Date: Wed, 31 Jan 2024 08:27:04 -0600 Subject: [PATCH] Finished implementing most functions --- src/backend/native.rs | 16 ++++++++++++++++ src/backend/wasm.rs | 16 ++++++++++++++++ src/usb.rs | 39 ++++++++++++++++++++++++++------------- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/backend/native.rs b/src/backend/native.rs index d195b3e..266c005 100644 --- a/src/backend/native.rs +++ b/src/backend/native.rs @@ -64,6 +64,22 @@ impl Device for UsbDevice { async fn product_id(&self) -> u16 { self.device_info.product_id() } + + async fn class(&self) -> u8 { + self.device_info.class() + } + + async fn subclass(&self) -> u8 { + self.device_info.subclass() + } + + async fn manufacturer_string(&self) -> Option { + self.device_info.manufacturer_string().map(str::to_string) + } + + async fn product_string(&self) -> Option { + self.device_info.product_string().map(str::to_string) + } } impl<'a> Interface<'a> for UsbInterface { diff --git a/src/backend/wasm.rs b/src/backend/wasm.rs index 3e623a5..16f2279 100644 --- a/src/backend/wasm.rs +++ b/src/backend/wasm.rs @@ -113,6 +113,22 @@ impl Device for UsbDevice { async fn product_id(&self) -> u16 { self.device.product_id() } + + async fn class(&self) -> u8 { + self.device.device_class() + } + + async fn subclass(&self) -> u8 { + self.device.device_subclass() + } + + async fn manufacturer_string(&self) -> Option { + self.device.manufacturer_name() + } + + async fn product_string(&self) -> Option { + self.device.product_name() + } } impl<'a> Interface<'a> for UsbInterface { diff --git a/src/usb.rs b/src/usb.rs index 5dba38e..9bdb820 100644 --- a/src/usb.rs +++ b/src/usb.rs @@ -7,32 +7,45 @@ pub trait Device { type UsbDevice; type UsbInterface; + /// Open a specific interface of the device async fn open_interface(&self, number: u8) -> Result>; + + /// Reset the device, which causes it to no longer be usable async fn reset(&self) -> Result<(), Box>; + + /// 16 bit device product ID async fn product_id(&self) -> u16; + + /// 16 bit device vendor ID async fn vendor_id(&self) -> u16; - //TODO: Implement these placeholders - async fn class(&self) -> u16 { - 0x00 - } - async fn subclass(&self) -> u16 { - 0x00 - } - async fn manufacturer_string(&self) -> Option<&str> { - None - } - async fn product_string(&self) -> Option<&str> { - None - } + /// Device standard class + async fn class(&self) -> u8; + + /// Device standard subclass + async fn subclass(&self) -> u8; + + /// Get the manufacturer string string of the device, if available without device IO + /// + /// Not available on Windows + async fn manufacturer_string(&self) -> Option; + + /// Get the product string of the device, if available without device IO + async fn product_string(&self) -> Option; } /// A specific interface of a USB device pub trait Interface<'a> { + /// A USB control in transfer (device to host) async fn control_in(&self, data: ControlIn) -> Result, Box>; + + /// A USB control out transfer (host to device) async fn control_out(&self, data: ControlOut<'a>) -> Result<(), Box>; + /// A USB bulk in transfer (device to host) async fn bulk_in(&self, endpoint: u8, length: usize) -> Result, Box>; + + /// A USB bulk out transfer (host to device) async fn bulk_out(&self, endpoint: u8, data: Vec) -> Result>; async fn interrupt_in(&self, _endpoint: u8, _buf: Vec) {