From 28a9d5bca77a977af98287dd2cc12cf2f856a774 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 6 Jun 2022 03:56:05 +0800 Subject: [PATCH] add hooks so unsafe C-FFI calls can connect to the keyboard - Opcodes are mapped to static IDs - connection ID is now visible to someone who already owns the keyboard object. This can then be shared with the FFI interface to do calls to the keyboard server. --- services/keyboard/src/api.rs | 23 ++++++++++++----------- services/keyboard/src/lib.rs | 2 ++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/services/keyboard/src/api.rs b/services/keyboard/src/api.rs index 012e6eb64..9c1c278e1 100644 --- a/services/keyboard/src/api.rs +++ b/services/keyboard/src/api.rs @@ -47,38 +47,39 @@ impl Into for KeyMap { } } +// Opcodes are pinned down to allow for unsafe FFI extraction of key hits #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] pub(crate) enum Opcode { /// set which keyboard mapping is present - SelectKeyMap, //(KeyMap), - GetKeyMap, + SelectKeyMap = 0, //(KeyMap), + GetKeyMap = 1, /// request for ScanCodes - RegisterListener, + RegisterListener = 2, /// request for raw keyups/downs - RegisterRawListener, + RegisterRawListener = 3, /// set repeat delay, rate; both in ms - SetRepeat, //(u32, u32), + SetRepeat = 4, //(u32, u32), /// set chording interval (how long to wait for all keydowns to happen before interpreting as a chord), in ms (for braille keyboards) - SetChordInterval, //(u32), + SetChordInterval = 5, //(u32), /// used by host mode emulation and debug UART to inject keys - InjectKey, //(char), + InjectKey = 6, //(char), /// used by the interrupt handler to transfer results to the main loop - HandlerTrigger, + HandlerTrigger = 7, /// used to turn keyboard vibrate on and off - Vibe, + Vibe = 8, /// a blocking key listener - blocks until a key is hit - BlockingKeyListener, + BlockingKeyListener = 9, /// Suspend/resume callback - SuspendResume, + SuspendResume = 10, } // this structure is used to register a keyboard listener. Currently, we only accept diff --git a/services/keyboard/src/lib.rs b/services/keyboard/src/lib.rs index 18b915a4e..5f0046bf8 100644 --- a/services/keyboard/src/lib.rs +++ b/services/keyboard/src/lib.rs @@ -92,6 +92,8 @@ impl Keyboard { Ok(_) | Err(_) => panic!("internal error: Incorrect return type") } } + /// Reveal the connection ID for use with unsafe FFI calls + pub fn conn(&self) -> xous::CID { self.conn } #[cfg(not(any(target_os = "none", target_os = "xous")))] pub fn hostmode_inject_key(&self, c: char) {