aboutsummaryrefslogtreecommitdiffstats
path: root/bootkbd/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bootkbd/src/lib.rs')
-rwxr-xr-x[-rw-r--r--]bootkbd/src/lib.rs40
1 files changed, 21 insertions, 19 deletions
diff --git a/bootkbd/src/lib.rs b/bootkbd/src/lib.rs
index c143512..dde9e71 100644..100755
--- a/bootkbd/src/lib.rs
+++ b/bootkbd/src/lib.rs
@@ -1,8 +1,10 @@
+#![no_std]
+
use log::{debug, error, info};
use usb_host::{
- ConfigurationDescriptor, DescriptorType, DeviceDescriptor, Direction, Driver, Endpoint,
- Error as USBError, RequestCode, RequestDirection, RequestKind, RequestRecipient, RequestType,
- TransferType, USBHost, WValue,
+ ConfigurationDescriptor, DescriptorType, DeviceDescriptor, Direction, Driver, DriverError,
+ Endpoint, RequestCode, RequestDirection, RequestKind, RequestRecipient, RequestType,
+ TransferError, TransferType, USBHost, WValue,
};
use core::mem::{self, MaybeUninit};
@@ -21,6 +23,11 @@ const MAX_ENDPOINTS: usize = 2;
pub struct BootKeyboard {
devices: [Option<Device>; MAX_DEVICES],
}
+impl core::fmt::Debug for BootKeyboard {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ write!(f, "BootKeyboard")
+ }
+}
impl BootKeyboard {
pub fn new() -> Self {
@@ -35,14 +42,14 @@ impl Driver for BootKeyboard {
true
}
- fn add_device(&mut self, _device: DeviceDescriptor, address: u8) -> Result<(), USBError> {
+ fn add_device(&mut self, _device: DeviceDescriptor, address: u8) -> Result<(), DriverError> {
for i in 0..self.devices.len() {
if self.devices[i].is_none() {
self.devices[i] = Some(Device::new(address));
return Ok(());
}
}
- Err(USBError::Permanent("out of devices"))
+ Err(DriverError::Permanent(address, "out of devices"))
}
fn remove_device(&mut self, address: u8) {
@@ -56,20 +63,15 @@ impl Driver for BootKeyboard {
}
}
- fn tick_device(
- &mut self,
- address: u8,
- millis: usize,
- host: &mut dyn USBHost,
- ) -> Result<(), USBError> {
- for i in 0..self.devices.len() {
- if let Some(ref mut dev) = self.devices[i] {
- if dev.addr == address {
- return dev.fsm(millis, host);
+ fn tick(&mut self, millis: usize, host: &mut dyn USBHost) -> Result<(), DriverError> {
+ for d in &mut self.devices[..] {
+ if let Some(ref mut dev) = d {
+ if let Err(TransferError::Permanent(e)) = dev.fsm(millis, host) {
+ return Err(DriverError::Permanent(dev.addr, e));
}
}
}
- Err(USBError::Permanent("no device at address"))
+ Ok(())
}
}
@@ -110,7 +112,7 @@ impl Device {
}
}
- fn fsm(&mut self, millis: usize, host: &mut dyn USBHost) -> Result<(), USBError> {
+ fn fsm(&mut self, millis: usize, host: &mut dyn USBHost) -> Result<(), TransferError> {
// TODO: either we need another `control_transfer` that
// doesn't take data, or this `none` value needs to be put in
// the usb-host layer. None of these options are good.
@@ -252,8 +254,8 @@ impl Device {
let mut buf: [u8; 8] = [0; 8];
if let Some(ref mut ep) = self.endpoints[0] {
match host.in_transfer(ep, &mut buf) {
- Err(USBError::Permanent(msg)) => error!("reading report: {}", msg),
- Err(USBError::Retry(_)) => return Ok(()),
+ Err(TransferError::Permanent(msg)) => error!("reading report: {}", msg),
+ Err(TransferError::Retry(_)) => return Ok(()),
Ok(len) => info!("report: {} - {:?}", len, buf),
}
}