From 062a8e367c3598b8d306e217f75a6a2e89400748 Mon Sep 17 00:00:00 2001 From: G2-Games Date: Wed, 31 Jan 2024 15:02:57 -0600 Subject: [PATCH] Added more docs, moved some components --- src/backend/native.rs | 1 - src/lib.rs | 15 ++++++++++++--- src/usb.rs | 13 +++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/backend/native.rs b/src/backend/native.rs index 9dbcbe3..aaf5efc 100644 --- a/src/backend/native.rs +++ b/src/backend/native.rs @@ -1,4 +1,3 @@ -use nusb; use std::error::Error; use crate::usb::{ControlIn, ControlOut, ControlType, Device, Interface, Recipient}; diff --git a/src/lib.rs b/src/lib.rs index f0393b9..5594ee6 100644 --- a/src/lib.rs +++ b/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)] diff --git a/src/usb.rs b/src/usb.rs index 2cee372..0cabaa2 100644 --- a/src/usb.rs +++ b/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>; + /* Interrupt transfers are a work in progress async fn interrupt_in(&self, _endpoint: u8, _buf: Vec) { unimplemented!() } @@ -58,14 +66,17 @@ pub trait Interface<'a> { async fn interrupt_out(&self, _endpoint: u8, _buf: Vec) { 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,