mirror of
https://github.com/G2-Games/cross-usb.git
synced 2025-04-19 05:12:53 -05:00
Added more docs, moved some components
This commit is contained in:
parent
d9bf9a6a75
commit
062a8e367c
3 changed files with 25 additions and 4 deletions
|
@ -1,4 +1,3 @@
|
|||
use nusb;
|
||||
use std::error::Error;
|
||||
|
||||
use crate::usb::{ControlIn, ControlOut, ControlType, Device, Interface, Recipient};
|
||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -1,4 +1,3 @@
|
|||
#![warn(missing_docs)]
|
||||
//! Cross USB is a USB library which works seamlessly across native and WASM targets.
|
||||
//!
|
||||
//! The idea is the user only has to write one way to access USB devices, which can be compiled
|
||||
|
@ -31,11 +30,21 @@ pub mod usb;
|
|||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
#[path = "./backend/native.rs"]
|
||||
pub mod context;
|
||||
/// The context contains the platform specific implementation of the USB transfers
|
||||
mod context;
|
||||
|
||||
#[cfg(target_family = "wasm")]
|
||||
#[path = "./backend/wasm.rs"]
|
||||
pub mod context;
|
||||
/// The context contains the platform specific implementation of the USB transfers
|
||||
mod context;
|
||||
|
||||
#[doc(inline)]
|
||||
/// An implementation of a USB device
|
||||
pub use crate::context::UsbDevice;
|
||||
|
||||
#[doc(inline)]
|
||||
/// An implementation of a USB interface
|
||||
pub use crate::context::UsbInterface;
|
||||
|
||||
/// Gets a single device from the VendorID and ProductID
|
||||
#[doc(inline)]
|
||||
|
|
13
src/usb.rs
13
src/usb.rs
|
@ -1,10 +1,17 @@
|
|||
#![allow(async_fn_in_trait)]
|
||||
//! This module contains the traits and associated functions and
|
||||
//! structs which allow for USB communication.
|
||||
//!
|
||||
|
||||
use crate::context::UsbInterface;
|
||||
use std::error::Error;
|
||||
|
||||
/// A unique USB device
|
||||
pub trait Device {
|
||||
/// A unique USB Device
|
||||
type UsbDevice;
|
||||
|
||||
/// A unique Interface on a USB Device
|
||||
type UsbInterface;
|
||||
|
||||
/// Open a specific interface of the device
|
||||
|
@ -51,6 +58,7 @@ pub trait Interface<'a> {
|
|||
/// Returns a [Result] with the number of bytes transferred
|
||||
async fn bulk_out(&self, endpoint: u8, data: &[u8]) -> Result<usize, Box<dyn Error>>;
|
||||
|
||||
/* Interrupt transfers are a work in progress
|
||||
async fn interrupt_in(&self, _endpoint: u8, _buf: Vec<u8>) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
@ -58,14 +66,17 @@ pub trait Interface<'a> {
|
|||
async fn interrupt_out(&self, _endpoint: u8, _buf: Vec<u8>) {
|
||||
unimplemented!()
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/// The type of USB transfer
|
||||
pub enum ControlType {
|
||||
Standard = 0,
|
||||
Class = 1,
|
||||
Vendor = 2,
|
||||
}
|
||||
|
||||
/// The recipient of a USB transfer
|
||||
pub enum Recipient {
|
||||
Device = 0,
|
||||
Interface = 1,
|
||||
|
@ -73,6 +84,7 @@ pub enum Recipient {
|
|||
Other = 3,
|
||||
}
|
||||
|
||||
/// Parameters for [Interface::control_in]
|
||||
pub struct ControlIn {
|
||||
pub control_type: ControlType,
|
||||
pub recipient: Recipient,
|
||||
|
@ -82,6 +94,7 @@ pub struct ControlIn {
|
|||
pub length: u16,
|
||||
}
|
||||
|
||||
/// Parameters for [Interface::control_out]
|
||||
pub struct ControlOut<'a> {
|
||||
pub control_type: ControlType,
|
||||
pub recipient: Recipient,
|
||||
|
|
Loading…
Reference in a new issue