aboutsummaryrefslogtreecommitdiffstats
path: root/usb-host
diff options
context:
space:
mode:
Diffstat (limited to 'usb-host')
-rwxr-xr-x[-rw-r--r--]usb-host/src/lib.rs38
1 files changed, 26 insertions, 12 deletions
diff --git a/usb-host/src/lib.rs b/usb-host/src/lib.rs
index 831a67c..551824a 100644..100755
--- a/usb-host/src/lib.rs
+++ b/usb-host/src/lib.rs
@@ -1,10 +1,13 @@
+#![no_std]
+
mod descriptor;
mod setup;
pub use descriptor::*;
pub use setup::*;
-pub enum Error {
+#[derive(Debug)]
+pub enum TransferError {
Retry(&'static str),
Permanent(&'static str),
}
@@ -18,11 +21,15 @@ pub trait USBHost {
w_value: WValue,
w_index: u16,
buf: Option<&mut [u8]>,
- ) -> Result<usize, Error>;
+ ) -> Result<usize, TransferError>;
- fn in_transfer(&mut self, ep: &mut dyn Endpoint, buf: &mut [u8]) -> Result<usize, Error>;
+ fn in_transfer(
+ &mut self,
+ ep: &mut dyn Endpoint,
+ buf: &mut [u8],
+ ) -> Result<usize, TransferError>;
- fn out_transfer(&mut self, ep: &mut dyn Endpoint, buf: &[u8]) -> Result<usize, Error>;
+ fn out_transfer(&mut self, ep: &mut dyn Endpoint, buf: &[u8]) -> Result<usize, TransferError>;
}
// cf ยง9.6.6 of USB 2.0
@@ -40,6 +47,7 @@ pub enum Direction {
Out,
In,
}
+
pub trait Endpoint {
fn address(&self) -> u8;
@@ -60,17 +68,23 @@ pub trait Endpoint {
fn set_out_toggle(&mut self, toggle: bool);
}
-pub trait Driver {
+#[derive(Copy, Clone, Debug)]
+pub enum DriverError {
+ Retry(u8, &'static str),
+ Permanent(u8, &'static str),
+}
+pub trait Driver: core::fmt::Debug {
fn want_device(&self, device: &DeviceDescriptor) -> bool;
- fn add_device(&mut self, device: DeviceDescriptor, address: u8) -> Result<(), Error>;
+ fn add_device(&mut self, device: DeviceDescriptor, address: u8) -> Result<(), DriverError>;
fn remove_device(&mut self, address: u8);
- fn tick_device(
- &mut self,
- address: u8,
- millis: usize,
- usbhost: &mut dyn USBHost,
- ) -> Result<(), Error>;
+ fn tick(&mut self, millis: usize, usbhost: &mut dyn USBHost) -> Result<(), DriverError>;
}
+
+// TODO: There needs to be a per-interface/function driver trait, as
+// well, since that's how most drivers will actually work.
+//
+// As a result, the host driver has to at least get the full
+// configuration.