aboutsummaryrefslogtreecommitdiffstats
path: root/usbh/src/pipe.rs
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2019-07-28 10:22:33 -0400
committerBrian Cully <bjc@kublai.com>2019-07-28 10:22:33 -0400
commitf39e0425a67277556db1c55547574b4205ed03e9 (patch)
tree50e09062edde2db6ec593b0580ffda0c98a037ca /usbh/src/pipe.rs
parentb1ef816d00ad5fb6048007611c5b091e2540c306 (diff)
downloadsamd21-demo-f39e0425a67277556db1c55547574b4205ed03e9.tar.gz
samd21-demo-f39e0425a67277556db1c55547574b4205ed03e9.zip
Use TryFrom where possible, instead of panicking.
Diffstat (limited to 'usbh/src/pipe.rs')
-rw-r--r--usbh/src/pipe.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/usbh/src/pipe.rs b/usbh/src/pipe.rs
index 936aa23..0a8503b 100644
--- a/usbh/src/pipe.rs
+++ b/usbh/src/pipe.rs
@@ -41,8 +41,14 @@ pub(crate) enum PipeErr {
HWTimeout,
DataToggle,
SWTimeout,
- Other,
+ Other(&'static str),
}
+impl From<&'static str> for PipeErr {
+ fn from(v: &'static str) -> Self {
+ Self::Other(v)
+ }
+}
+
pub(crate) struct PipeTable {
tbl: [PipeDesc; MAX_PIPES],
}
@@ -135,7 +141,7 @@ impl Pipe<'_, '_> {
if let Some(b) = buf {
// TODO: data stage, has up to 5,000ms (in 500ms
// per-packet chunks) to complete. cf ยง9.2.6.4 of USB 2.0.
- match bm_request_type.direction() {
+ match bm_request_type.direction()? {
USBSetupDirection::DeviceToHost => {
trace!("buf0: {:?}", &b);
self.in_transfer(&b, NAK_LIMIT, millis)?;
@@ -159,7 +165,7 @@ impl Pipe<'_, '_> {
unsafe { w.multi_packet_size().bits(0) }
});
- let token = match bm_request_type.direction() {
+ let token = match bm_request_type.direction()? {
USBSetupDirection::DeviceToHost => USBToken::Out,
USBSetupDirection::HostToDevice => USBToken::In,
};