From f4f6106b48a1cc8110db30541af7675a4c89a47b Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 4 Jun 2022 14:20:45 +0800 Subject: [PATCH 1/4] fix CI issues in github actions due to namespace collision of feature & package --- services/usb-device-xous/Cargo.toml | 4 ++-- services/usb-device-xous/src/main.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/services/usb-device-xous/Cargo.toml b/services/usb-device-xous/Cargo.toml index 1c41e60c9..04fdebabc 100644 --- a/services/usb-device-xous/Cargo.toml +++ b/services/usb-device-xous/Cargo.toml @@ -41,6 +41,6 @@ rand_chacha = "0.3.1" utralib = { path = "../../utralib"} [features] -keyboard = [] # handy for debugging composite device issues +emukbd = [] # handy for debugging composite device issues mjolnir = [] # the big hammer for debugging Spinal USB issues. A raw memory dump of config and descriptor space. Use with care. -default = ["keyboard"] +default = ["emukbd"] diff --git a/services/usb-device-xous/src/main.rs b/services/usb-device-xous/src/main.rs index 9f4a2496c..4fb4ad8a7 100644 --- a/services/usb-device-xous/src/main.rs +++ b/services/usb-device-xous/src/main.rs @@ -142,7 +142,7 @@ fn main() -> ! { let usb_alloc = UsbBusAllocator::new(usbdev); #[cfg(any(target_os = "none", target_os = "xous"))] let clock = EmbeddedClock::new(); - #[cfg(all(any(target_os = "none", target_os = "xous"), feature="keyboard"))] + #[cfg(all(any(target_os = "none", target_os = "xous"), feature="emukbd"))] let mut composite = UsbHidClassBuilder::new() .add_interface( NKROBootKeyboardInterface::default_config(&clock), @@ -151,7 +151,7 @@ fn main() -> ! { FidoInterface::default_config() ) .build(&usb_alloc); - #[cfg(all(any(target_os = "none", target_os = "xous"), not(feature="keyboard")))] + #[cfg(all(any(target_os = "none", target_os = "xous"), not(feature="emukbd")))] let mut composite = UsbHidClassBuilder::new() .add_interface( FidoInterface::default_config() @@ -164,7 +164,7 @@ fn main() -> ! { .product("Precursor") .serial_number(&serial_number) .build(); - #[cfg(all(any(target_os = "none", target_os = "xous"), feature="keyboard"))] + #[cfg(all(any(target_os = "none", target_os = "xous"), feature="emukbd"))] { let keyboard = composite.interface::, _>(); keyboard.write_report(&Vec::::new()).ok(); @@ -246,7 +246,7 @@ fn main() -> ! { Some(Opcode::UsbIrqHandler) => { #[cfg(any(target_os = "none", target_os = "xous"))] if usb_dev.poll(&mut [&mut composite]) { - #[cfg(feature="keyboard")] + #[cfg(feature="emukbd")] { let keyboard = composite.interface::, _>(); match keyboard.read_report() { @@ -361,7 +361,7 @@ fn main() -> ! { codes.push(Keyboard::from_primitive(code2 as u8)); } let auto_up = if autoup == 1 {true} else {false}; - #[cfg(feature="keyboard")] + #[cfg(feature="emukbd")] { let keyboard = composite.interface::, _>(); keyboard.write_report(&codes).ok(); @@ -397,7 +397,7 @@ fn main() -> ! { KeyMap::Dvorak => mappings::char_to_hid_code_dvorak(ch), _ => mappings::char_to_hid_code_us101(ch), }; - #[cfg(feature="keyboard")] + #[cfg(feature="emukbd")] { let keyboard = composite.interface::, _>(); keyboard.write_report(&codes).ok(); From 665292ce743d66653193fd5bce1b22e9b4e901ed Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 5 Jun 2022 13:34:26 +0800 Subject: [PATCH 2/4] absorb the correct package list for renode builds The manifest was being processed, but the package list was going back to the original base set, which would lead to a confusing situation of apps being listed but the binaries not being present. --- xtask/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 8f5b2ca93..a49f2498b 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -194,7 +194,7 @@ fn main() -> Result<(), Box> { pkgs.push(app); } generate_app_menus(&apps); - renode_image(false, &hw_pkgs, &[], None, None)? + renode_image(false, &pkgs, &[], None, None)? } Some("renode-test") => { let mut args = env::args(); From e589de1665c215ffcb72e90de28e82fad04fb631 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 5 Jun 2022 13:35:07 +0800 Subject: [PATCH 3/4] bump renode SVD file to be compatible with latest SoC changes --- emulation/soc/renode.svd | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/emulation/soc/renode.svd b/emulation/soc/renode.svd index 922ff3ac4..9146c1572 100644 --- a/emulation/soc/renode.svd +++ b/emulation/soc/renode.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1222,10 +1222,10 @@ register to disable individual events.]]> GIT_GITREV +``010b3183``, so this value is 17510787, which should be enough to check out the +exact git version used to build this firmware.]]> 0x0014 - 0xdf6ac783 + 0x10b3183 32 @@ -1242,7 +1242,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x12 + 0x16 32 @@ -3577,7 +3577,7 @@ inject too fast.]]> SEED1 0x0000 - 0x4616d7dd + 0x65ce43e3 32 @@ -3592,7 +3592,7 @@ inject too fast.]]> SEED0 0x0004 - 0x3c6bc921 + 0x28aafeae 32 @@ -7129,7 +7129,6 @@ of the PLL]]> - From 72996bc453342ac7b0d4c5f594ad6aa7e5efe1ba Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 5 Jun 2022 18:32:54 +0800 Subject: [PATCH 4/4] add a facility for a simple blocking keyboard listener --- services/keyboard/src/api.rs | 3 +++ services/keyboard/src/lib.rs | 23 ++++++++++++++++++++ services/keyboard/src/main.rs | 40 ++++++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/services/keyboard/src/api.rs b/services/keyboard/src/api.rs index a37140911..012e6eb64 100644 --- a/services/keyboard/src/api.rs +++ b/services/keyboard/src/api.rs @@ -74,6 +74,9 @@ pub(crate) enum Opcode { /// used to turn keyboard vibrate on and off Vibe, + /// a blocking key listener - blocks until a key is hit + BlockingKeyListener, + /// Suspend/resume callback SuspendResume, } diff --git a/services/keyboard/src/lib.rs b/services/keyboard/src/lib.rs index de17d8ba3..18b915a4e 100644 --- a/services/keyboard/src/lib.rs +++ b/services/keyboard/src/lib.rs @@ -69,6 +69,29 @@ impl Keyboard { _ => Err(xous::Error::InternalError) } } + /// Blocks until a key is hit. Does not block the keyboard server, just the caller. + /// Returns a `Vec::`, as the user can press more than one key at a time. + /// The specific order of a simultaneous key hit event is not defined. + pub fn get_keys_blocking(&self) -> Vec { + match send_message(self.conn, + Message::new_blocking_scalar( + Opcode::BlockingKeyListener.to_usize().unwrap(), + 0, 0, 0, 0 + ) + ) { + Ok(xous::Result::Scalar2(k1, k2)) => { + let mut ret = Vec::::new(); + if let Some(c) = core::char::from_u32(k1 as u32) { + ret.push(c) + } + if let Some(c) = core::char::from_u32(k2 as u32) { + ret.push(c) + } + ret + } + Ok(_) | Err(_) => panic!("internal error: Incorrect return type") + } + } #[cfg(not(any(target_os = "none", target_os = "xous")))] pub fn hostmode_inject_key(&self, c: char) { diff --git a/services/keyboard/src/main.rs b/services/keyboard/src/main.rs index 863360ad9..2b714540b 100644 --- a/services/keyboard/src/main.rs +++ b/services/keyboard/src/main.rs @@ -9,7 +9,7 @@ use log::info; use num_traits::*; use xous_ipc::Buffer; -use xous::{CID, msg_scalar_unpack, msg_blocking_scalar_unpack}; +use xous::{CID, msg_scalar_unpack, msg_blocking_scalar_unpack, MessageSender}; #[cfg(any(target_os = "none", target_os = "xous"))] mod implementation { use utralib::generated::*; @@ -764,6 +764,8 @@ fn main() -> ! { }*/ let mut esc_index: Option = None; let mut esc_chars = [0u8; 16]; + // storage for any blocking listeners + let mut blocking_listener = Vec::::new(); log::trace!("starting main loop"); loop { @@ -779,6 +781,11 @@ fn main() -> ! { if ena != 0 { vibe = true } else { vibe = false } }), + Some(Opcode::BlockingKeyListener) => { + // by simply storing the sender address and not returning a value, + // the sender will remain blocked until the return value is generated + blocking_listener.push(msg.sender); + }, Some(Opcode::RegisterListener) => { let buffer = unsafe{Buffer::from_memory_message(msg.body.memory_message().unwrap())}; let kr = buffer.as_flat::().unwrap(); @@ -893,6 +900,11 @@ fn main() -> ! { ).unwrap(); } } + for listener in blocking_listener.drain(..) { + // we must unblock anyways once the key is hit; even if the key is invalid, + // send the invalid key. The receiving library function will clean this up into a nil-response vector. + xous::return_scalar2(listener, key as u32 as usize, 0).unwrap(); + } }), Some(Opcode::HandlerTrigger) => { let rawstates = kbd.update(); @@ -927,6 +939,32 @@ fn main() -> ! { }; // send keys, if any + // handle the blocking listeners + if kc.len() > 0 { + for listener in blocking_listener.drain(..) { + xous::return_scalar2( + listener, + if kc.len() >= 1 { + kc[0] as u32 as usize + } else { + 0 + }, + if kc.len() >= 2 { + kc[1] as u32 as usize + } else { + 0 + }, + ).unwrap(); + if kc.len() > 2 { + log::warn!( + "Extra keys in multi-hit event went unreported: only 2 of {} total keys reported out of {:?}", + kc.len(), + &kc, + ); + } + } + } + // handle the true async listeners if kc.len() > 0 && listener_conn.is_some() && listener_op.is_some() { if vibe { llio.vibe(llio::VibePattern::Short).unwrap();