diff --git a/src/main.rs b/src/main.rs index 40b6aa6a017661a1220f40479484df4218835b26..697355cae55f84612a5a2364839a2afe1a615768 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,7 +66,7 @@ async fn main() -> TockResult<()> { let timer = timer.init()?; // Setup USB driver. - if !usb_ctap_hid::setup() { + if !usb_ctap_hid::setup()? { panic!("Cannot setup USB driver"); } diff --git a/src/usb_ctap_hid.rs b/src/usb_ctap_hid.rs index 07152e1bcba87b9e04f3bc4ba77b6f020418c49a..7006748a772924c7e3e58e2b844db0af895513d5 100644 --- a/src/usb_ctap_hid.rs +++ b/src/usb_ctap_hid.rs @@ -17,7 +17,7 @@ use core::cell::Cell; use core::fmt::Write; #[cfg(feature = "debug_ctap")] use libtock::console::Console; -use libtock::result::{EALREADY, EBUSY, SUCCESS}; +use libtock::result::{EALREADY, EBUSY, SUCCESS, TockResult}; use libtock::syscalls; use libtock::timer::{Duration}; @@ -48,18 +48,18 @@ mod allow_nr { pub const TRANSMIT_OR_RECEIVE: usize = 3; } -pub fn setup() -> bool { - let result = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::CHECK, 0, 0) }; +pub fn setup() -> TockResult<bool> { + let result = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::CHECK, 0, 0)? }; if result != 0 { - return false; + return Ok(false); } - let result = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::CONNECT, 0, 0) }; + let result = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::CONNECT, 0, 0)? }; if result != 0 { - return false; + return Ok(false); } - true + Ok(true) } #[allow(dead_code)] @@ -76,7 +76,11 @@ pub fn recv(buf: &mut [u8; 64]) -> bool { return false; } - let result_code = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::RECEIVE, 0, 0) }; + let result_code = + match unsafe { syscalls::command(DRIVER_NUMBER, command_nr::RECEIVE, 0, 0) } { + Ok(x) => x, + Err(err) => panic!("Unexpected error error while executing command"), + }; if result_code != 0 { return false; } @@ -99,7 +103,11 @@ pub fn send(buf: &mut [u8; 64]) -> bool { return false; } - let result_code = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::TRANSMIT, 0, 0) }; + let result_code = + match unsafe { syscalls::command(DRIVER_NUMBER, command_nr::TRANSMIT, 0, 0) } { + Ok(x) => x, + Err(err) => panic!("Unexpected error error while executing command"), + }; if result_code != 0 { return false; } @@ -149,7 +157,10 @@ pub fn send_or_recv(buf: &mut [u8; 64]) -> SendOrRecvStatus { } let result_code = - unsafe { syscalls::command(DRIVER_NUMBER, command_nr::TRANSMIT_OR_RECEIVE, 0, 0) }; + match unsafe { syscalls::command(DRIVER_NUMBER, command_nr::TRANSMIT_OR_RECEIVE, 0, 0) } { + Ok(x) => x, + Err(err) => panic!("Unexpected error error while executing command"), + }; if result_code != 0 { return SendOrRecvStatus::Error; } @@ -256,7 +267,11 @@ fn recv_with_timeout_detail( }; // Trigger USB reception. - let result_code = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::RECEIVE, 0, 0) }; + let result_code = + match unsafe { syscalls::command(DRIVER_NUMBER, command_nr::RECEIVE, 0, 0) } { + Ok(x) => x, + Err(err) => panic!("Unexpected error error while executing command"), + }; if result_code != 0 { return Some(SendOrRecvStatus::Error); } @@ -357,7 +372,10 @@ fn send_or_recv_with_timeout_detail( // Trigger USB transmission. let result_code = - unsafe { syscalls::command(DRIVER_NUMBER, command_nr::TRANSMIT_OR_RECEIVE, 0, 0) }; + match unsafe { syscalls::command(DRIVER_NUMBER, command_nr::TRANSMIT_OR_RECEIVE, 0, 0) } { + Ok(x) => x, + Err(err) => panic!("Unexpected error error while executing command"), + }; if result_code != 0 { return Some(SendOrRecvStatus::Error); }