mirror of
https://github.com/G2-Games/cross-usb.git
synced 2025-04-19 13:22: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 std::error::Error;
|
||||||
|
|
||||||
use crate::usb::{ControlIn, ControlOut, ControlType, Device, Interface, Recipient};
|
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.
|
//! 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
|
//! 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"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[path = "./backend/native.rs"]
|
#[path = "./backend/native.rs"]
|
||||||
pub mod context;
|
/// The context contains the platform specific implementation of the USB transfers
|
||||||
|
mod context;
|
||||||
|
|
||||||
#[cfg(target_family = "wasm")]
|
#[cfg(target_family = "wasm")]
|
||||||
#[path = "./backend/wasm.rs"]
|
#[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
|
/// Gets a single device from the VendorID and ProductID
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
|
|
13
src/usb.rs
13
src/usb.rs
|
@ -1,10 +1,17 @@
|
||||||
#![allow(async_fn_in_trait)]
|
#![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 crate::context::UsbInterface;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
/// A unique USB device
|
/// A unique USB device
|
||||||
pub trait Device {
|
pub trait Device {
|
||||||
|
/// A unique USB Device
|
||||||
type UsbDevice;
|
type UsbDevice;
|
||||||
|
|
||||||
|
/// A unique Interface on a USB Device
|
||||||
type UsbInterface;
|
type UsbInterface;
|
||||||
|
|
||||||
/// Open a specific interface of the device
|
/// Open a specific interface of the device
|
||||||
|
@ -51,6 +58,7 @@ pub trait Interface<'a> {
|
||||||
/// Returns a [Result] with the number of bytes transferred
|
/// Returns a [Result] with the number of bytes transferred
|
||||||
async fn bulk_out(&self, endpoint: u8, data: &[u8]) -> Result<usize, Box<dyn Error>>;
|
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>) {
|
async fn interrupt_in(&self, _endpoint: u8, _buf: Vec<u8>) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
@ -58,14 +66,17 @@ pub trait Interface<'a> {
|
||||||
async fn interrupt_out(&self, _endpoint: u8, _buf: Vec<u8>) {
|
async fn interrupt_out(&self, _endpoint: u8, _buf: Vec<u8>) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The type of USB transfer
|
||||||
pub enum ControlType {
|
pub enum ControlType {
|
||||||
Standard = 0,
|
Standard = 0,
|
||||||
Class = 1,
|
Class = 1,
|
||||||
Vendor = 2,
|
Vendor = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The recipient of a USB transfer
|
||||||
pub enum Recipient {
|
pub enum Recipient {
|
||||||
Device = 0,
|
Device = 0,
|
||||||
Interface = 1,
|
Interface = 1,
|
||||||
|
@ -73,6 +84,7 @@ pub enum Recipient {
|
||||||
Other = 3,
|
Other = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parameters for [Interface::control_in]
|
||||||
pub struct ControlIn {
|
pub struct ControlIn {
|
||||||
pub control_type: ControlType,
|
pub control_type: ControlType,
|
||||||
pub recipient: Recipient,
|
pub recipient: Recipient,
|
||||||
|
@ -82,6 +94,7 @@ pub struct ControlIn {
|
||||||
pub length: u16,
|
pub length: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parameters for [Interface::control_out]
|
||||||
pub struct ControlOut<'a> {
|
pub struct ControlOut<'a> {
|
||||||
pub control_type: ControlType,
|
pub control_type: ControlType,
|
||||||
pub recipient: Recipient,
|
pub recipient: Recipient,
|
||||||
|
|
Loading…
Reference in a new issue