Finished implementing most functions

This commit is contained in:
G2-Games 2024-01-31 08:27:04 -06:00
parent 3ca83e5f8c
commit 8b624b0136
3 changed files with 58 additions and 13 deletions

View file

@ -64,6 +64,22 @@ impl Device for UsbDevice {
async fn product_id(&self) -> u16 { async fn product_id(&self) -> u16 {
self.device_info.product_id() 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 { impl<'a> Interface<'a> for UsbInterface {

View file

@ -113,6 +113,22 @@ impl Device for UsbDevice {
async fn product_id(&self) -> u16 { async fn product_id(&self) -> u16 {
self.device.product_id() 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 { impl<'a> Interface<'a> for UsbInterface {

View file

@ -7,32 +7,45 @@ pub trait Device {
type UsbDevice; type UsbDevice;
type UsbInterface; type UsbInterface;
/// Open a specific interface of the device
async fn open_interface(&self, number: u8) -> Result<UsbInterface, Box<dyn Error>>; 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>>; async fn reset(&self) -> Result<(), Box<dyn Error>>;
/// 16 bit device product ID
async fn product_id(&self) -> u16; async fn product_id(&self) -> u16;
/// 16 bit device vendor ID
async fn vendor_id(&self) -> u16; async fn vendor_id(&self) -> u16;
//TODO: Implement these placeholders /// Device standard class
async fn class(&self) -> u16 { async fn class(&self) -> u8;
0x00
} /// Device standard subclass
async fn subclass(&self) -> u16 { async fn subclass(&self) -> u8;
0x00
} /// Get the manufacturer string string of the device, if available without device IO
async fn manufacturer_string(&self) -> Option<&str> { ///
None /// Not available on Windows
} async fn manufacturer_string(&self) -> Option<String>;
async fn product_string(&self) -> Option<&str> {
None /// 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 /// A specific interface of a USB device
pub trait Interface<'a> { 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>>; 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>>; 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>>; 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 bulk_out(&self, endpoint: u8, data: Vec<u8>) -> Result<usize, Box<dyn Error>>;
async fn interrupt_in(&self, _endpoint: u8, _buf: Vec<u8>) { async fn interrupt_in(&self, _endpoint: u8, _buf: Vec<u8>) {