mirror of
https://github.com/G2-Games/cross-usb.git
synced 2025-04-19 13:22:53 -05:00
Finished implementing most functions
This commit is contained in:
parent
3ca83e5f8c
commit
8b624b0136
3 changed files with 58 additions and 13 deletions
|
@ -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<String> {
|
||||
self.device_info.manufacturer_string().map(str::to_string)
|
||||
}
|
||||
|
||||
async fn product_string(&self) -> Option<String> {
|
||||
self.device_info.product_string().map(str::to_string)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Interface<'a> for UsbInterface {
|
||||
|
|
|
@ -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<String> {
|
||||
self.device.manufacturer_name()
|
||||
}
|
||||
|
||||
async fn product_string(&self) -> Option<String> {
|
||||
self.device.product_name()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Interface<'a> for UsbInterface {
|
||||
|
|
39
src/usb.rs
39
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<UsbInterface, Box<dyn Error>>;
|
||||
|
||||
/// Reset the device, which causes it to no longer be usable
|
||||
async fn reset(&self) -> Result<(), Box<dyn Error>>;
|
||||
|
||||
/// 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<String>;
|
||||
|
||||
/// Get the product string of the device, if available without device IO
|
||||
async fn product_string(&self) -> Option<String>;
|
||||
}
|
||||
|
||||
/// 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<Vec<u8>, Box<dyn Error>>;
|
||||
|
||||
/// A USB control out transfer (host to device)
|
||||
async fn control_out(&self, data: ControlOut<'a>) -> Result<(), Box<dyn Error>>;
|
||||
|
||||
/// A USB bulk in transfer (device to host)
|
||||
async fn bulk_in(&self, endpoint: u8, length: usize) -> Result<Vec<u8>, Box<dyn Error>>;
|
||||
|
||||
/// A USB bulk out transfer (host to device)
|
||||
async fn bulk_out(&self, endpoint: u8, data: Vec<u8>) -> Result<usize, Box<dyn Error>>;
|
||||
|
||||
async fn interrupt_in(&self, _endpoint: u8, _buf: Vec<u8>) {
|
||||
|
|
Loading…
Reference in a new issue