diff options
author | Brian Cully <bjc@kublai.com> | 2019-07-28 10:22:33 -0400 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2019-07-28 10:22:33 -0400 |
commit | f39e0425a67277556db1c55547574b4205ed03e9 (patch) | |
tree | 50e09062edde2db6ec593b0580ffda0c98a037ca /usbh/src/pipe.rs | |
parent | b1ef816d00ad5fb6048007611c5b091e2540c306 (diff) | |
download | samd21-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.rs | 12 |
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, }; |