diff --git a/Cargo.lock b/Cargo.lock index 046b237c3..79df56125 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1085,6 +1085,7 @@ name = "rkyv-test-client" version = "0.1.0" dependencies = [ "com", + "keyboard", "log", "log-server", "rkyv-test-server", diff --git a/emulation/renode.svd b/emulation/renode.svd index 5ae8fd29e..70babeb36 100644 --- a/emulation/renode.svd +++ b/emulation/renode.svd @@ -1328,10 +1328,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x2a2abe5e + 0x8561717c 32 @@ -1348,7 +1348,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 - 0x0e + 0x0f 32 @@ -3056,7 +3056,7 @@ again until the interrupt is serviced.]]> SEED1 0x0000 - 0x4e903012 + 0x62e0ffce 32 @@ -3071,7 +3071,7 @@ again until the interrupt is serviced.]]> SEED0 0x0004 - 0x26a75168 + 0x629a6ab2 32 diff --git a/services/keyboard/src/api.rs b/services/keyboard/src/api.rs index a8f979e6a..4071c0c17 100644 --- a/services/keyboard/src/api.rs +++ b/services/keyboard/src/api.rs @@ -24,6 +24,10 @@ pub struct RowCol { pub r: u8, pub c: u8, } +/// RowColVec is implemented here instead of using heapless::Vec because we can't +/// derive the rkyv traits on heapless::Vec. By making a janky vector type here +/// our IPC doesn't rely on dangerous serialization techniques like casting to +/// raw u8 slices which rely on the implicit shape of packed structures... #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] pub struct RowColVec { storage: [Option; MAX_KEYS], diff --git a/services/keyboard/src/lib.rs b/services/keyboard/src/lib.rs index b52ef6244..e4c0ad62f 100644 --- a/services/keyboard/src/lib.rs +++ b/services/keyboard/src/lib.rs @@ -18,7 +18,7 @@ pub struct Keyboard { raw_cb_sid: Option, } impl Keyboard { - pub fn new(xns: xous_names::XousNames) -> Result { + pub fn new(xns: &xous_names::XousNames) -> Result { let conn = xns.request_connection_blocking(api::SERVER_NAME_KBD).expect("Can't connect to KBD"); Ok(Keyboard { conn, diff --git a/services/keyboard/src/main.rs b/services/keyboard/src/main.rs index eb2f92470..401597cea 100644 --- a/services/keyboard/src/main.rs +++ b/services/keyboard/src/main.rs @@ -874,8 +874,15 @@ fn xmain() -> ! { // send rawstates on to rawstate listeners send_rawstates(&mut raw_conns, &rawstates); - // TODO: refactor this Vec usage into an array (the Vec is from a previous implementation) - // for now, just copy the array over, inefficiently + // GROSS: we copy our IPC-compatible RowColVec type into a heapless::Vec for further processing + // this code can probably be cleaned up and improved quite a bit to reduce CPU time. + // We don't use heapless::Vec for the IPC because we can't serialize the object with a trait natively + // which leaves us with ugly/dangerous slice-of-u8 cast techniques and/or inefficient serialization + // methods that rely on effectively a substantially similar intermediate array-based implementation. + // We retain the use of the "Vec" type here because the Vec type has some nice functions like iterators, + // and push(), len() etc. which doesn't really make sense to re-implement. But, maybe someone much + // more clever than I could do extend RowColVec to have these feature and get rid of this ugly copy + // step and make the rest of this routine operate natively on RowColVec types.... let mut keyups_core: Vec = Vec::new(); let mut keydowns_core: Vec = Vec::new(); for i in 0..rawstates.keyups.len() { diff --git a/services/rkyv-test-client/Cargo.toml b/services/rkyv-test-client/Cargo.toml index 1617c2b51..ca0f195d1 100644 --- a/services/rkyv-test-client/Cargo.toml +++ b/services/rkyv-test-client/Cargo.toml @@ -14,5 +14,7 @@ xous = {path = "../../xous-rs"} com = {path = "../com"} xous-names = {path="../xous-names"} +keyboard = {path="../keyboard"} + [features] default = [] diff --git a/services/rkyv-test-client/src/main.rs b/services/rkyv-test-client/src/main.rs index 7e5a35b2c..a9ed7a16c 100644 --- a/services/rkyv-test-client/src/main.rs +++ b/services/rkyv-test-client/src/main.rs @@ -19,6 +19,14 @@ fn handle_battstats(bs: com::BattStats) { // 2. use an Atomic type to transfer primitive data types from the handler thread to the main thread } +fn handle_keyevents(keys: [char; 4]) { + for &k in keys.iter() { + if k != '\u{0000}' { + log::info!("KEYEVENT: {}", k); + } + } +} + #[xous::xous_main] fn rkyv_test_client() -> ! { log_server::init_wait().unwrap(); @@ -40,9 +48,11 @@ fn rkyv_test_client() -> ! { let mut message_string = xous::String::<64>::new(); let xns = xous_names::XousNames::new().unwrap(); - let mut com = com::Com::new(xns).unwrap(); + let mut com = com::Com::new(&xns).unwrap(); com.hook_batt_stats(handle_battstats).unwrap(); + let mut kbd = keyboard::Keyboard::new(&xns).unwrap(); + kbd.hook_keyboard_events(handle_keyevents).unwrap(); loop { log::info!("2 + {} = {}", idx, rkyv_test_server::add(2, idx).unwrap()); ticktimer.sleep_ms(500).ok(); diff --git a/svd2utra/examples/soc.svd b/svd2utra/examples/soc.svd index 5ae8fd29e..70babeb36 100644 --- a/svd2utra/examples/soc.svd +++ b/svd2utra/examples/soc.svd @@ -1328,10 +1328,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x2a2abe5e + 0x8561717c 32 @@ -1348,7 +1348,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 - 0x0e + 0x0f 32 @@ -3056,7 +3056,7 @@ again until the interrupt is serviced.]]> SEED1 0x0000 - 0x4e903012 + 0x62e0ffce 32 @@ -3071,7 +3071,7 @@ again until the interrupt is serviced.]]> SEED0 0x0004 - 0x26a75168 + 0x629a6ab2 32