From 33e43aeb0ab8c5a7da92bc07a7c0c70d7ded2784 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 14 Jun 2024 16:13:43 +0800 Subject: [PATCH] add debug level api calls to USB stack --- services/usb-device-xous/src/api.rs | 27 +++++++++++++++++++++++++++ services/usb-device-xous/src/lib.rs | 9 +++++++++ 2 files changed, 36 insertions(+) diff --git a/services/usb-device-xous/src/api.rs b/services/usb-device-xous/src/api.rs index effcc879e..558b9dfa6 100644 --- a/services/usb-device-xous/src/api.rs +++ b/services/usb-device-xous/src/api.rs @@ -29,6 +29,8 @@ pub(crate) enum Opcode { SetAutotypeRate = 10, /// Register a USB event observer RegisterUsbObserver = 11, + /// Modify log level + SetLogLevel = 12, /// Send a U2F message U2fTx = 128, @@ -186,3 +188,28 @@ pub(crate) struct UsbListenerRegistration { pub server_name: xous_ipc::String<64>, pub listener_op_id: usize, } + +#[derive(Debug, Eq, PartialEq, Copy, Clone)] +#[repr(usize)] +pub enum LogLevel { + Trace = 0, + Debug = 1, + Info = 2, + Warn = 3, + Err = 4, +} + +impl TryFrom for LogLevel { + type Error = &'static str; + + fn try_from(value: usize) -> Result { + match value { + 0 => Ok(LogLevel::Trace), + 1 => Ok(LogLevel::Debug), + 2 => Ok(LogLevel::Info), + 3 => Ok(LogLevel::Warn), + 4 => Ok(LogLevel::Err), + _ => Err("Invalid LogLevel"), + } + } +} diff --git a/services/usb-device-xous/src/lib.rs b/services/usb-device-xous/src/lib.rs index 30a294b79..c96af2a90 100644 --- a/services/usb-device-xous/src/lib.rs +++ b/services/usb-device-xous/src/lib.rs @@ -448,6 +448,15 @@ impl UsbHid { Ok(()) } + + /// Attempts to set the logging level of the USB server + pub fn set_log_level(&self, level: LogLevel) { + send_message( + self.conn, + Message::new_scalar(Opcode::SetLogLevel.to_usize().unwrap(), level as usize, 0, 0, 0), + ) + .unwrap(); + } } use core::sync::atomic::{AtomicU32, Ordering};