From 8080c1db221a0717fc232bc41abee598578deab0 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 3 Feb 2022 03:26:18 +0800 Subject: [PATCH] split mappings into separate files, and add azerty/qwertz mappings totally untested, i'm sure I messed up a character or two. I'm sure there will be opinions. Pull requests welcome! --- services/keyboard/src/main.rs | 153 +---------------------- services/keyboard/src/mappings.rs | 8 ++ services/keyboard/src/mappings/azerty.rs | 73 +++++++++++ services/keyboard/src/mappings/dvorak.rs | 72 +++++++++++ services/keyboard/src/mappings/qwerty.rs | 73 +++++++++++ services/keyboard/src/mappings/qwertz.rs | 73 +++++++++++ 6 files changed, 303 insertions(+), 149 deletions(-) create mode 100644 services/keyboard/src/mappings.rs create mode 100644 services/keyboard/src/mappings/azerty.rs create mode 100644 services/keyboard/src/mappings/dvorak.rs create mode 100644 services/keyboard/src/mappings/qwerty.rs create mode 100644 services/keyboard/src/mappings/qwertz.rs diff --git a/services/keyboard/src/main.rs b/services/keyboard/src/main.rs index c0780d804..335b342e5 100644 --- a/services/keyboard/src/main.rs +++ b/services/keyboard/src/main.rs @@ -3,165 +3,18 @@ mod api; use api::*; +mod mappings; use log::info; use num_traits::*; use xous_ipc::Buffer; use xous::{CID, msg_scalar_unpack, msg_blocking_scalar_unpack}; - -/// Compute the dvorak key mapping of row/col to key tuples -#[allow(dead_code)] -fn map_dvorak(code: RowCol) -> ScanCode { - let rc = (code.r, code.c); - - match rc { - (0, 0) => ScanCode{key: Some('1'), shift: Some('1'), hold: None, alt: None}, - (0, 1) => ScanCode{key: Some('2'), shift: Some('2'), hold: None, alt: None}, - (0, 2) => ScanCode{key: Some('3'), shift: Some('3'), hold: None, alt: None}, - (0, 3) => ScanCode{key: Some('4'), shift: Some('4'), hold: None, alt: None}, - (0, 4) => ScanCode{key: Some('5'), shift: Some('5'), hold: None, alt: None}, - (4, 5) => ScanCode{key: Some('6'), shift: Some('6'), hold: None, alt: None}, - (4, 6) => ScanCode{key: Some('7'), shift: Some('7'), hold: None, alt: None}, - (4, 7) => ScanCode{key: Some('8'), shift: Some('8'), hold: None, alt: None}, - (4, 8) => ScanCode{key: Some('9'), shift: Some('9'), hold: None, alt: None}, - (4, 9) => ScanCode{key: Some('0'), shift: Some('0'), hold: None, alt: None}, - - (1, 0) => ScanCode{key: Some(0x8_u8.into()), shift: Some(0x8_u8.into()), hold: None /* hold of none -> repeat */, alt: Some(0x8_u8.into())}, // backspace - (1, 1) => ScanCode{key: Some('\''), shift: Some('\''), hold: Some('@'), alt: None}, - (1, 2) => ScanCode{key: Some('p'), shift: Some('P'), hold: Some('#'), alt: None}, - (1, 3) => ScanCode{key: Some('y'), shift: Some('Y'), hold: Some('&'), alt: None}, - (1, 4) => ScanCode{key: Some('f'), shift: Some('F'), hold: Some('*'), alt: None}, - (5, 5) => ScanCode{key: Some('g'), shift: Some('G'), hold: Some('-'), alt: None}, - (5, 6) => ScanCode{key: Some('c'), shift: Some('C'), hold: Some('+'), alt: None}, - (5, 7) => ScanCode{key: Some('r'), shift: Some('R'), hold: Some('('), alt: None}, - (5, 8) => ScanCode{key: Some('l'), shift: Some('L'), hold: Some(')'), alt: None}, - (5, 9) => ScanCode{key: Some('?'), shift: Some('?'), hold: Some('!'), alt: None}, - - (2, 0) => ScanCode{key: Some('a'), shift: Some('A'), hold: Some('\\'), alt: None}, - (2, 1) => ScanCode{key: Some('o'), shift: Some('O'), hold: Some('`'), alt: None}, - (2, 2) => ScanCode{key: Some('e'), shift: Some('E'), hold: Some('~'), alt: None}, - (2, 3) => ScanCode{key: Some('u'), shift: Some('U'), hold: Some('|'), alt: None}, - (2, 4) => ScanCode{key: Some('i'), shift: Some('I'), hold: Some('['), alt: None}, - (6, 5) => ScanCode{key: Some('d'), shift: Some('D'), hold: Some(']'), alt: None}, - (6, 6) => ScanCode{key: Some('h'), shift: Some('H'), hold: Some('<'), alt: None}, - (6, 7) => ScanCode{key: Some('t'), shift: Some('T'), hold: Some('>'), alt: None}, - (6, 8) => ScanCode{key: Some('n'), shift: Some('N'), hold: Some('{'), alt: None}, - (6, 9) => ScanCode{key: Some('s'), shift: Some('S'), hold: Some('}'), alt: None}, - - (3, 0) => ScanCode{key: Some('q'), shift: Some('Q'), hold: Some('_'), alt: None}, - (3, 1) => ScanCode{key: Some('j'), shift: Some('J'), hold: Some('$'), alt: None}, - (3, 2) => ScanCode{key: Some('k'), shift: Some('K'), hold: Some('"'), alt: None}, - (3, 3) => ScanCode{key: Some('x'), shift: Some('X'), hold: Some(':'), alt: None}, - (3, 4) => ScanCode{key: Some('b'), shift: Some('B'), hold: Some(';'), alt: None}, - (7, 5) => ScanCode{key: Some('m'), shift: Some('M'), hold: Some('/'), alt: None}, - (7, 6) => ScanCode{key: Some('w'), shift: Some('W'), hold: Some('^'), alt: None}, - (7, 7) => ScanCode{key: Some('v'), shift: Some('V'), hold: Some('='), alt: None}, - (7, 8) => ScanCode{key: Some('z'), shift: Some('Z'), hold: Some('%'), alt: None}, - (7, 9) => ScanCode{key: Some(0xd_u8.into()), shift: Some(0xd_u8.into()), hold: Some(0xd_u8.into()), alt: Some(0xd_u8.into())}, // carriage return - - (8, 5) => ScanCode{key: Some(0xf_u8.into()), shift: Some(0xf_u8.into()), hold: Some(0xf_u8.into()), alt: Some(0xf_u8.into())}, // shift in (blue shift) - (8, 6) => ScanCode{key: Some(','), shift: Some(0xe_u8.into()), hold: Some(0xe_u8.into()), alt: None}, // 0xe is shift out (sym) - (8, 7) => ScanCode{key: Some(' '), shift: Some(' '), hold: None /* hold of none -> repeat */, alt: None}, - (8, 8) => ScanCode{key: Some('.'), shift: Some('😊'), hold: Some('😊'), alt: None}, - (8, 9) => ScanCode{key: Some(0xf_u8.into()), shift: Some(0xf_u8.into()), hold: Some(0xf_u8.into()), alt: Some(0xf_u8.into())}, // shift in (blue shift) - - // the F0/tab key also doubles as a secondary power key (can't do UP5K UART rx at same time) - (8, 0) => ScanCode{key: Some(0x11_u8.into()), shift: Some(0x11_u8.into()), hold: Some(0x11_u8.into()), alt: Some(0x11_u8.into())}, // DC1 (F1) - (8, 1) => ScanCode{key: Some(0x12_u8.into()), shift: Some(0x12_u8.into()), hold: Some(0x12_u8.into()), alt: Some(0x12_u8.into())}, // DC2 (F2) - (3, 8) => ScanCode{key: Some(0x13_u8.into()), shift: Some(0x13_u8.into()), hold: Some(0x13_u8.into()), alt: Some(0x13_u8.into())}, // DC3 (F3) - // the F4/ctrl key also doubles as a power key - (3, 9) => ScanCode{key: Some(0x14_u8.into()), shift: Some(0x14_u8.into()), hold: Some(0x14_u8.into()), alt: Some(0x14_u8.into())}, // DC4 (F4) - (8, 3) => ScanCode{key: Some('←'), shift: Some('←'), hold: None, alt: Some('←')}, - (3, 6) => ScanCode{key: Some('β†’'), shift: Some('β†’'), hold: None, alt: Some('β†’')}, - (6, 4) => ScanCode{key: Some('↑'), shift: Some('↑'), hold: None, alt: Some('↑')}, - (8, 2) => ScanCode{key: Some('↓'), shift: Some('↓'), hold: None, alt: Some('↓')}, - // this one is OK - (5, 2) => ScanCode{key: Some('∴'), shift: Some('∴'), hold: None, alt: Some('∴')}, - - _ => ScanCode {key: None, shift: None, hold: None, alt: None} - } -} - - -/// Compute the dvorak key mapping of row/col to key tuples -#[allow(dead_code)] -fn map_qwerty(code: RowCol) -> ScanCode { - let rc = (code.r, code.c); - - match rc { - (0, 0) => ScanCode{key: Some('1'), shift: Some('1'), hold: None, alt: None}, - (0, 1) => ScanCode{key: Some('2'), shift: Some('2'), hold: None, alt: None}, - (0, 2) => ScanCode{key: Some('3'), shift: Some('3'), hold: None, alt: None}, - (0, 3) => ScanCode{key: Some('4'), shift: Some('4'), hold: None, alt: None}, - (0, 4) => ScanCode{key: Some('5'), shift: Some('5'), hold: None, alt: None}, - (4, 5) => ScanCode{key: Some('6'), shift: Some('6'), hold: None, alt: None}, - (4, 6) => ScanCode{key: Some('7'), shift: Some('7'), hold: None, alt: None}, - (4, 7) => ScanCode{key: Some('8'), shift: Some('8'), hold: None, alt: None}, - (4, 8) => ScanCode{key: Some('9'), shift: Some('9'), hold: None, alt: None}, - (4, 9) => ScanCode{key: Some('0'), shift: Some('0'), hold: None, alt: None}, - - (1, 0) => ScanCode{key: Some('q'), shift: Some('Q'), hold: Some('%'), alt: None}, - (1, 1) => ScanCode{key: Some('w'), shift: Some('W'), hold: Some('^'), alt: None}, - (1, 2) => ScanCode{key: Some('e'), shift: Some('E'), hold: Some('~'), alt: None}, - (1, 3) => ScanCode{key: Some('r'), shift: Some('R'), hold: Some('|'), alt: None}, - (1, 4) => ScanCode{key: Some('t'), shift: Some('T'), hold: Some('['), alt: None}, - (5, 5) => ScanCode{key: Some('y'), shift: Some('Y'), hold: Some(']'), alt: None}, - (5, 6) => ScanCode{key: Some('u'), shift: Some('U'), hold: Some('<'), alt: None}, - (5, 7) => ScanCode{key: Some('i'), shift: Some('I'), hold: Some('>'), alt: None}, - (5, 8) => ScanCode{key: Some('o'), shift: Some('O'), hold: Some('{'), alt: None}, - (5, 9) => ScanCode{key: Some('p'), shift: Some('P'), hold: Some('}'), alt: None}, - - (2, 0) => ScanCode{key: Some('a'), shift: Some('A'), hold: Some('@'), alt: None}, - (2, 1) => ScanCode{key: Some('s'), shift: Some('S'), hold: Some('#'), alt: None}, - (2, 2) => ScanCode{key: Some('d'), shift: Some('D'), hold: Some('&'), alt: None}, - (2, 3) => ScanCode{key: Some('f'), shift: Some('F'), hold: Some('*'), alt: None}, - (2, 4) => ScanCode{key: Some('g'), shift: Some('G'), hold: Some('-'), alt: None}, - (6, 5) => ScanCode{key: Some('h'), shift: Some('H'), hold: Some('+'), alt: None}, - (6, 6) => ScanCode{key: Some('j'), shift: Some('J'), hold: Some('='), alt: None}, - (6, 7) => ScanCode{key: Some('k'), shift: Some('K'), hold: Some('('), alt: None}, - (6, 8) => ScanCode{key: Some('l'), shift: Some('L'), hold: Some(')'), alt: None}, - (6, 9) => ScanCode{key: Some(0x8_u8.into()), shift: Some(0x8_u8.into()), hold: None /* hold of none -> repeat */, alt: Some(0x8_u8.into())}, // backspace - - (3, 0) => ScanCode{key: Some('!'), shift: Some('!'), hold: Some('`'), alt: None}, - (3, 1) => ScanCode{key: Some('z'), shift: Some('Z'), hold: Some('_'), alt: None}, - (3, 2) => ScanCode{key: Some('x'), shift: Some('X'), hold: Some('$'), alt: None}, - (3, 3) => ScanCode{key: Some('c'), shift: Some('C'), hold: Some('"'), alt: None}, - (3, 4) => ScanCode{key: Some('v'), shift: Some('V'), hold: Some('\''), alt: None}, - (7, 5) => ScanCode{key: Some('b'), shift: Some('B'), hold: Some(':'), alt: None}, - (7, 6) => ScanCode{key: Some('n'), shift: Some('N'), hold: Some(';'), alt: None}, - (7, 7) => ScanCode{key: Some('m'), shift: Some('M'), hold: Some('/'), alt: None}, - (7, 8) => ScanCode{key: Some('?'), shift: Some('?'), hold: Some('\\'), alt: None}, - (7, 9) => ScanCode{key: Some(0xd_u8.into()), shift: Some(0xd_u8.into()), hold: Some(0xd_u8.into()), alt: Some(0xd_u8.into())}, // carriage return - - (8, 5) => ScanCode{key: Some(0xf_u8.into()), shift: Some(0xf_u8.into()), hold: Some(0xf_u8.into()), alt: Some(0xf_u8.into())}, // shift in (blue shift) - (8, 6) => ScanCode{key: Some(','), shift: Some(0xe_u8.into()), hold: Some('福'), alt: None}, // 0xe is shift out (sym) '富' -> just for testing hanzi plane - (8, 7) => ScanCode{key: Some(' '), shift: Some(' '), hold: None /* hold of none -> repeat */, alt: None}, - (8, 8) => ScanCode{key: Some('.'), shift: Some('😊'), hold: Some('😊'), alt: None}, - (8, 9) => ScanCode{key: Some(0xf_u8.into()), shift: Some(0xf_u8.into()), hold: Some(0xf_u8.into()), alt: Some(0xf_u8.into())}, // shift in (blue shift) - - // the F0/tab key also doubles as a secondary power key (can't do UP5K UART rx at same time) - (8, 0) => ScanCode{key: Some(0x11_u8.into()), shift: Some(0x11_u8.into()), hold: Some(0x11_u8.into()), alt: Some(0x11_u8.into())}, // DC1 (F1) - (8, 1) => ScanCode{key: Some(0x12_u8.into()), shift: Some(0x12_u8.into()), hold: Some(0x12_u8.into()), alt: Some(0x12_u8.into())}, // DC2 (F2) - (3, 8) => ScanCode{key: Some(0x13_u8.into()), shift: Some(0x13_u8.into()), hold: Some(0x13_u8.into()), alt: Some(0x13_u8.into())}, // DC3 (F3) - // the F4/ctrl key also doubles as a power key - (3, 9) => ScanCode{key: Some(0x14_u8.into()), shift: Some(0x14_u8.into()), hold: Some(0x14_u8.into()), alt: Some(0x14_u8.into())}, // DC4 (F4) - (8, 3) => ScanCode{key: Some('←'), shift: Some('←'), hold: None, alt: Some('←')}, - (3, 6) => ScanCode{key: Some('β†’'), shift: Some('β†’'), hold: None, alt: Some('β†’')}, - (6, 4) => ScanCode{key: Some('↑'), shift: Some('↑'), hold: None, alt: Some('↑')}, - (8, 2) => ScanCode{key: Some('↓'), shift: Some('↓'), hold: None, alt: Some('↓')}, - // this one is OK - (5, 2) => ScanCode{key: Some('∴'), shift: Some('∴'), hold: None, alt: Some('∴')}, - - _ => ScanCode {key: None, shift: None, hold: None, alt: None} - } -} - #[cfg(any(target_os = "none", target_os = "xous"))] mod implementation { use utralib::generated::*; use crate::{RowCol, KeyRawStates, api::*}; - use crate::{map_dvorak, map_qwerty}; + use crate::mappings::*; use ticktimer_server::Ticktimer; use xous::CID; use num_traits::ToPrimitive; @@ -679,6 +532,8 @@ mod implementation { let code = match self.map { KeyMap::Qwerty => map_qwerty(rc), KeyMap::Dvorak => map_dvorak(rc), + KeyMap::Azerty => map_azerty(rc), + KeyMap::Qwertz => map_qwertz(rc), _ => ScanCode {key: None, shift: None, hold: None, alt: None}, }; if code.hold == None { // if there isn't a pre-defined meaning if the key is held, it's a repeating key diff --git a/services/keyboard/src/mappings.rs b/services/keyboard/src/mappings.rs new file mode 100644 index 000000000..2a9d3b93a --- /dev/null +++ b/services/keyboard/src/mappings.rs @@ -0,0 +1,8 @@ +mod qwerty; +pub (crate) use qwerty::*; +mod qwertz; +pub (crate) use qwertz::*; +mod azerty; +pub (crate) use azerty::*; +mod dvorak; +pub (crate) use dvorak::*; diff --git a/services/keyboard/src/mappings/azerty.rs b/services/keyboard/src/mappings/azerty.rs new file mode 100644 index 000000000..f47c3f6a2 --- /dev/null +++ b/services/keyboard/src/mappings/azerty.rs @@ -0,0 +1,73 @@ +use crate::{RowCol, ScanCode}; + +/// Compute the azerty key mapping of row/col to key tuples +pub(crate) fn map_azerty(code: RowCol) -> ScanCode { + let rc = (code.r, code.c); + + match rc { + (0, 0) => ScanCode{key: Some('1'), shift: Some('1'), hold: Some('Γ '), alt: Some('Β§')}, + (0, 1) => ScanCode{key: Some('2'), shift: Some('2'), hold: Some('Γ©'), alt: None}, + (0, 2) => ScanCode{key: Some('3'), shift: Some('3'), hold: Some('Γ¨'), alt: None}, + (0, 3) => ScanCode{key: Some('4'), shift: Some('4'), hold: Some('Γͺ'), alt: None}, + (0, 4) => ScanCode{key: Some('5'), shift: Some('5'), hold: Some('('), alt: Some('[')}, + (4, 5) => ScanCode{key: Some('6'), shift: Some('6'), hold: Some(')'), alt: Some(']')}, + (4, 6) => ScanCode{key: Some('7'), shift: Some('7'), hold: Some('&'), alt: None}, + (4, 7) => ScanCode{key: Some('8'), shift: Some('8'), hold: Some('*'), alt: Some('_')}, + (4, 8) => ScanCode{key: Some('9'), shift: Some('9'), hold: Some('Β«'), alt: Some('\'')}, + (4, 9) => ScanCode{key: Some('0'), shift: Some('0'), hold: Some('Β»'), alt: Some('"')}, + + (1, 0) => ScanCode{key: Some('a'), shift: Some('A'), hold: Some('Γ¦'), alt: None}, + (1, 1) => ScanCode{key: Some('z'), shift: Some('Z'), hold: Some('Β£'), alt: None}, + (1, 2) => ScanCode{key: Some('e'), shift: Some('E'), hold: Some('€'), alt: None}, + (1, 3) => ScanCode{key: Some('r'), shift: Some('R'), hold: Some('`'), alt: None}, + (1, 4) => ScanCode{key: Some('t'), shift: Some('T'), hold: Some('{'), alt: None}, + (5, 5) => ScanCode{key: Some('y'), shift: Some('Y'), hold: Some('}'), alt: None}, + (5, 6) => ScanCode{key: Some('u'), shift: Some('U'), hold: Some('ΓΉ'), alt: None}, + (5, 7) => ScanCode{key: Some('i'), shift: Some('I'), hold: Some('Γ―'), alt: None}, + (5, 8) => ScanCode{key: Some('o'), shift: Some('O'), hold: Some('Ε“'), alt: None}, + (5, 9) => ScanCode{key: Some('p'), shift: Some('P'), hold: Some('%'), alt: None}, + + (2, 0) => ScanCode{key: Some('q'), shift: Some('Q'), hold: Some('@'), alt: None}, + (2, 1) => ScanCode{key: Some('s'), shift: Some('S'), hold: Some('ß'), alt: None}, + (2, 2) => ScanCode{key: Some('d'), shift: Some('D'), hold: Some('$'), alt: None}, + (2, 3) => ScanCode{key: Some('f'), shift: Some('F'), hold: Some('Β€'), alt: None}, + (2, 4) => ScanCode{key: Some('g'), shift: Some('G'), hold: Some('Β΅'), alt: None}, + (6, 5) => ScanCode{key: Some('h'), shift: Some('H'), hold: Some('-'), alt: None}, + (6, 6) => ScanCode{key: Some('j'), shift: Some('J'), hold: Some('+'), alt: None}, + (6, 7) => ScanCode{key: Some('k'), shift: Some('K'), hold: Some('/'), alt: Some('\\')}, + (6, 8) => ScanCode{key: Some('l'), shift: Some('L'), hold: Some('|'), alt: None}, + (6, 9) => ScanCode{key: Some('m'), shift: Some('M'), hold: Some('#'), alt: None}, + + (3, 0) => ScanCode{key: Some(0x8_u8.into()), shift: Some(0x8_u8.into()), hold: None /* hold of none -> repeat */, alt: Some(0x8_u8.into())}, // backspace + (3, 1) => ScanCode{key: Some('w'), shift: Some('W'), hold: Some('<'), alt: None}, + (3, 2) => ScanCode{key: Some('x'), shift: Some('X'), hold: Some('>'), alt: None}, + (3, 3) => ScanCode{key: Some('c'), shift: Some('C'), hold: Some('Γ§'), alt: None}, + (3, 4) => ScanCode{key: Some('v'), shift: Some('V'), hold: Some('^'), alt: None}, + (7, 5) => ScanCode{key: Some('b'), shift: Some('B'), hold: Some('='), alt: None}, + (7, 6) => ScanCode{key: Some('n'), shift: Some('N'), hold: Some('~'), alt: None}, + (7, 7) => ScanCode{key: Some(':'), shift: Some(':'), hold: Some('?'), alt: Some('ΒΏ')}, + (7, 8) => ScanCode{key: Some(';'), shift: Some(';'), hold: Some('!'), alt: Some('Β‘')}, + (7, 9) => ScanCode{key: Some(0xd_u8.into()), shift: Some(0xd_u8.into()), hold: Some(0xd_u8.into()), alt: Some(0xd_u8.into())}, // carriage return + + (8, 5) => ScanCode{key: Some(0xf_u8.into()), shift: Some(0xf_u8.into()), hold: Some(0xf_u8.into()), alt: Some(0xf_u8.into())}, // shift in (orange shift) + (8, 6) => ScanCode{key: Some(','), shift: Some(0xe_u8.into()), hold: Some('福'), alt: None}, // 0xe is shift out (sym) '富' -> just for testing hanzi plane + (8, 7) => ScanCode{key: Some(' '), shift: Some(' '), hold: None /* hold of none -> repeat */, alt: None}, + (8, 8) => ScanCode{key: Some('.'), shift: Some('😊'), hold: Some('😊'), alt: None}, + (8, 9) => ScanCode{key: Some(0xf_u8.into()), shift: Some(0xf_u8.into()), hold: Some(0xf_u8.into()), alt: Some(0xf_u8.into())}, // shift in (blue shift) + + // the F0/tab key also doubles as a secondary power key (can't do UP5K UART rx at same time) + (8, 0) => ScanCode{key: Some(0x11_u8.into()), shift: Some(0x11_u8.into()), hold: Some('\t'), alt: Some(0x11_u8.into())}, // DC1 (F1) + (8, 1) => ScanCode{key: Some(0x12_u8.into()), shift: Some(0x12_u8.into()), hold: Some(0x12_u8.into()), alt: Some(0x12_u8.into())}, // DC2 (F2) + (3, 8) => ScanCode{key: Some(0x13_u8.into()), shift: Some(0x13_u8.into()), hold: Some(0x13_u8.into()), alt: Some(0x13_u8.into())}, // DC3 (F3) + // the F4/ctrl key also doubles as a power key + (3, 9) => ScanCode{key: Some(0x14_u8.into()), shift: Some(0x14_u8.into()), hold: Some(0x14_u8.into()), alt: Some(0x14_u8.into())}, // DC4 (F4) + (8, 3) => ScanCode{key: Some('←'), shift: Some('←'), hold: None, alt: Some('←')}, + (3, 6) => ScanCode{key: Some('β†’'), shift: Some('β†’'), hold: None, alt: Some('β†’')}, + (6, 4) => ScanCode{key: Some('↑'), shift: Some('↑'), hold: None, alt: Some('↑')}, + (8, 2) => ScanCode{key: Some('↓'), shift: Some('↓'), hold: None, alt: Some('↓')}, + // this one is OK + (5, 2) => ScanCode{key: Some('∴'), shift: Some('∴'), hold: None, alt: Some('∴')}, + + _ => ScanCode {key: None, shift: None, hold: None, alt: None} + } +} \ No newline at end of file diff --git a/services/keyboard/src/mappings/dvorak.rs b/services/keyboard/src/mappings/dvorak.rs new file mode 100644 index 000000000..dde975bb0 --- /dev/null +++ b/services/keyboard/src/mappings/dvorak.rs @@ -0,0 +1,72 @@ +use crate::{RowCol, ScanCode}; +/// Compute the dvorak key mapping of row/col to key tuples +pub(crate) fn map_dvorak(code: RowCol) -> ScanCode { + let rc = (code.r, code.c); + + match rc { + (0, 0) => ScanCode{key: Some('1'), shift: Some('1'), hold: None, alt: None}, + (0, 1) => ScanCode{key: Some('2'), shift: Some('2'), hold: None, alt: None}, + (0, 2) => ScanCode{key: Some('3'), shift: Some('3'), hold: None, alt: None}, + (0, 3) => ScanCode{key: Some('4'), shift: Some('4'), hold: None, alt: None}, + (0, 4) => ScanCode{key: Some('5'), shift: Some('5'), hold: None, alt: None}, + (4, 5) => ScanCode{key: Some('6'), shift: Some('6'), hold: None, alt: None}, + (4, 6) => ScanCode{key: Some('7'), shift: Some('7'), hold: None, alt: None}, + (4, 7) => ScanCode{key: Some('8'), shift: Some('8'), hold: None, alt: None}, + (4, 8) => ScanCode{key: Some('9'), shift: Some('9'), hold: None, alt: None}, + (4, 9) => ScanCode{key: Some('0'), shift: Some('0'), hold: None, alt: None}, + + (1, 0) => ScanCode{key: Some(0x8_u8.into()), shift: Some(0x8_u8.into()), hold: None /* hold of none -> repeat */, alt: Some(0x8_u8.into())}, // backspace + (1, 1) => ScanCode{key: Some('\''), shift: Some('\''), hold: Some('@'), alt: None}, + (1, 2) => ScanCode{key: Some('p'), shift: Some('P'), hold: Some('#'), alt: None}, + (1, 3) => ScanCode{key: Some('y'), shift: Some('Y'), hold: Some('&'), alt: None}, + (1, 4) => ScanCode{key: Some('f'), shift: Some('F'), hold: Some('*'), alt: None}, + (5, 5) => ScanCode{key: Some('g'), shift: Some('G'), hold: Some('-'), alt: None}, + (5, 6) => ScanCode{key: Some('c'), shift: Some('C'), hold: Some('+'), alt: None}, + (5, 7) => ScanCode{key: Some('r'), shift: Some('R'), hold: Some('('), alt: None}, + (5, 8) => ScanCode{key: Some('l'), shift: Some('L'), hold: Some(')'), alt: None}, + (5, 9) => ScanCode{key: Some('?'), shift: Some('?'), hold: Some('!'), alt: None}, + + (2, 0) => ScanCode{key: Some('a'), shift: Some('A'), hold: Some('\\'), alt: None}, + (2, 1) => ScanCode{key: Some('o'), shift: Some('O'), hold: Some('`'), alt: None}, + (2, 2) => ScanCode{key: Some('e'), shift: Some('E'), hold: Some('~'), alt: None}, + (2, 3) => ScanCode{key: Some('u'), shift: Some('U'), hold: Some('|'), alt: None}, + (2, 4) => ScanCode{key: Some('i'), shift: Some('I'), hold: Some('['), alt: None}, + (6, 5) => ScanCode{key: Some('d'), shift: Some('D'), hold: Some(']'), alt: None}, + (6, 6) => ScanCode{key: Some('h'), shift: Some('H'), hold: Some('<'), alt: None}, + (6, 7) => ScanCode{key: Some('t'), shift: Some('T'), hold: Some('>'), alt: None}, + (6, 8) => ScanCode{key: Some('n'), shift: Some('N'), hold: Some('{'), alt: None}, + (6, 9) => ScanCode{key: Some('s'), shift: Some('S'), hold: Some('}'), alt: None}, + + (3, 0) => ScanCode{key: Some('q'), shift: Some('Q'), hold: Some('_'), alt: None}, + (3, 1) => ScanCode{key: Some('j'), shift: Some('J'), hold: Some('$'), alt: None}, + (3, 2) => ScanCode{key: Some('k'), shift: Some('K'), hold: Some('"'), alt: None}, + (3, 3) => ScanCode{key: Some('x'), shift: Some('X'), hold: Some(':'), alt: None}, + (3, 4) => ScanCode{key: Some('b'), shift: Some('B'), hold: Some(';'), alt: None}, + (7, 5) => ScanCode{key: Some('m'), shift: Some('M'), hold: Some('/'), alt: None}, + (7, 6) => ScanCode{key: Some('w'), shift: Some('W'), hold: Some('^'), alt: None}, + (7, 7) => ScanCode{key: Some('v'), shift: Some('V'), hold: Some('='), alt: None}, + (7, 8) => ScanCode{key: Some('z'), shift: Some('Z'), hold: Some('%'), alt: None}, + (7, 9) => ScanCode{key: Some(0xd_u8.into()), shift: Some(0xd_u8.into()), hold: Some(0xd_u8.into()), alt: Some(0xd_u8.into())}, // carriage return + + (8, 5) => ScanCode{key: Some(0xf_u8.into()), shift: Some(0xf_u8.into()), hold: Some(0xf_u8.into()), alt: Some(0xf_u8.into())}, // shift in (blue shift) + (8, 6) => ScanCode{key: Some(','), shift: Some(0xe_u8.into()), hold: Some(0xe_u8.into()), alt: None}, // 0xe is shift out (sym) + (8, 7) => ScanCode{key: Some(' '), shift: Some(' '), hold: None /* hold of none -> repeat */, alt: None}, + (8, 8) => ScanCode{key: Some('.'), shift: Some('😊'), hold: Some('😊'), alt: None}, + (8, 9) => ScanCode{key: Some(0xf_u8.into()), shift: Some(0xf_u8.into()), hold: Some(0xf_u8.into()), alt: Some(0xf_u8.into())}, // shift in (blue shift) + + // the F0/tab key also doubles as a secondary power key (can't do UP5K UART rx at same time) + (8, 0) => ScanCode{key: Some(0x11_u8.into()), shift: Some(0x11_u8.into()), hold: Some(0x11_u8.into()), alt: Some(0x11_u8.into())}, // DC1 (F1) + (8, 1) => ScanCode{key: Some(0x12_u8.into()), shift: Some(0x12_u8.into()), hold: Some(0x12_u8.into()), alt: Some(0x12_u8.into())}, // DC2 (F2) + (3, 8) => ScanCode{key: Some(0x13_u8.into()), shift: Some(0x13_u8.into()), hold: Some(0x13_u8.into()), alt: Some(0x13_u8.into())}, // DC3 (F3) + // the F4/ctrl key also doubles as a power key + (3, 9) => ScanCode{key: Some(0x14_u8.into()), shift: Some(0x14_u8.into()), hold: Some(0x14_u8.into()), alt: Some(0x14_u8.into())}, // DC4 (F4) + (8, 3) => ScanCode{key: Some('←'), shift: Some('←'), hold: None, alt: Some('←')}, + (3, 6) => ScanCode{key: Some('β†’'), shift: Some('β†’'), hold: None, alt: Some('β†’')}, + (6, 4) => ScanCode{key: Some('↑'), shift: Some('↑'), hold: None, alt: Some('↑')}, + (8, 2) => ScanCode{key: Some('↓'), shift: Some('↓'), hold: None, alt: Some('↓')}, + // this one is OK + (5, 2) => ScanCode{key: Some('∴'), shift: Some('∴'), hold: None, alt: Some('∴')}, + + _ => ScanCode {key: None, shift: None, hold: None, alt: None} + } +} diff --git a/services/keyboard/src/mappings/qwerty.rs b/services/keyboard/src/mappings/qwerty.rs new file mode 100644 index 000000000..af100e3ae --- /dev/null +++ b/services/keyboard/src/mappings/qwerty.rs @@ -0,0 +1,73 @@ +use crate::{RowCol, ScanCode}; + +/// Compute the qwerty key mapping of row/col to key tuples +pub(crate) fn map_qwerty(code: RowCol) -> ScanCode { + let rc = (code.r, code.c); + + match rc { + (0, 0) => ScanCode{key: Some('1'), shift: Some('1'), hold: None, alt: None}, + (0, 1) => ScanCode{key: Some('2'), shift: Some('2'), hold: None, alt: None}, + (0, 2) => ScanCode{key: Some('3'), shift: Some('3'), hold: None, alt: None}, + (0, 3) => ScanCode{key: Some('4'), shift: Some('4'), hold: None, alt: None}, + (0, 4) => ScanCode{key: Some('5'), shift: Some('5'), hold: None, alt: None}, + (4, 5) => ScanCode{key: Some('6'), shift: Some('6'), hold: None, alt: None}, + (4, 6) => ScanCode{key: Some('7'), shift: Some('7'), hold: None, alt: None}, + (4, 7) => ScanCode{key: Some('8'), shift: Some('8'), hold: None, alt: None}, + (4, 8) => ScanCode{key: Some('9'), shift: Some('9'), hold: None, alt: None}, + (4, 9) => ScanCode{key: Some('0'), shift: Some('0'), hold: None, alt: None}, + + (1, 0) => ScanCode{key: Some('q'), shift: Some('Q'), hold: Some('%'), alt: None}, + (1, 1) => ScanCode{key: Some('w'), shift: Some('W'), hold: Some('^'), alt: None}, + (1, 2) => ScanCode{key: Some('e'), shift: Some('E'), hold: Some('~'), alt: None}, + (1, 3) => ScanCode{key: Some('r'), shift: Some('R'), hold: Some('|'), alt: None}, + (1, 4) => ScanCode{key: Some('t'), shift: Some('T'), hold: Some('['), alt: None}, + (5, 5) => ScanCode{key: Some('y'), shift: Some('Y'), hold: Some(']'), alt: None}, + (5, 6) => ScanCode{key: Some('u'), shift: Some('U'), hold: Some('<'), alt: None}, + (5, 7) => ScanCode{key: Some('i'), shift: Some('I'), hold: Some('>'), alt: None}, + (5, 8) => ScanCode{key: Some('o'), shift: Some('O'), hold: Some('{'), alt: None}, + (5, 9) => ScanCode{key: Some('p'), shift: Some('P'), hold: Some('}'), alt: None}, + + (2, 0) => ScanCode{key: Some('a'), shift: Some('A'), hold: Some('@'), alt: None}, + (2, 1) => ScanCode{key: Some('s'), shift: Some('S'), hold: Some('#'), alt: None}, + (2, 2) => ScanCode{key: Some('d'), shift: Some('D'), hold: Some('&'), alt: None}, + (2, 3) => ScanCode{key: Some('f'), shift: Some('F'), hold: Some('*'), alt: None}, + (2, 4) => ScanCode{key: Some('g'), shift: Some('G'), hold: Some('-'), alt: None}, + (6, 5) => ScanCode{key: Some('h'), shift: Some('H'), hold: Some('+'), alt: None}, + (6, 6) => ScanCode{key: Some('j'), shift: Some('J'), hold: Some('='), alt: None}, + (6, 7) => ScanCode{key: Some('k'), shift: Some('K'), hold: Some('('), alt: None}, + (6, 8) => ScanCode{key: Some('l'), shift: Some('L'), hold: Some(')'), alt: None}, + (6, 9) => ScanCode{key: Some(0x8_u8.into()), shift: Some(0x8_u8.into()), hold: None /* hold of none -> repeat */, alt: Some(0x8_u8.into())}, // backspace + + (3, 0) => ScanCode{key: Some('!'), shift: Some('!'), hold: Some('`'), alt: None}, + (3, 1) => ScanCode{key: Some('z'), shift: Some('Z'), hold: Some('_'), alt: None}, + (3, 2) => ScanCode{key: Some('x'), shift: Some('X'), hold: Some('$'), alt: None}, + (3, 3) => ScanCode{key: Some('c'), shift: Some('C'), hold: Some('"'), alt: None}, + (3, 4) => ScanCode{key: Some('v'), shift: Some('V'), hold: Some('\''), alt: None}, + (7, 5) => ScanCode{key: Some('b'), shift: Some('B'), hold: Some(':'), alt: None}, + (7, 6) => ScanCode{key: Some('n'), shift: Some('N'), hold: Some(';'), alt: None}, + (7, 7) => ScanCode{key: Some('m'), shift: Some('M'), hold: Some('/'), alt: None}, + (7, 8) => ScanCode{key: Some('?'), shift: Some('?'), hold: Some('\\'), alt: None}, + (7, 9) => ScanCode{key: Some(0xd_u8.into()), shift: Some(0xd_u8.into()), hold: Some(0xd_u8.into()), alt: Some(0xd_u8.into())}, // carriage return + + (8, 5) => ScanCode{key: Some(0xf_u8.into()), shift: Some(0xf_u8.into()), hold: Some(0xf_u8.into()), alt: Some(0xf_u8.into())}, // shift in (blue shift) + (8, 6) => ScanCode{key: Some(','), shift: Some(0xe_u8.into()), hold: Some('福'), alt: None}, // 0xe is shift out (sym) '富' -> just for testing hanzi plane + (8, 7) => ScanCode{key: Some(' '), shift: Some(' '), hold: None /* hold of none -> repeat */, alt: None}, + (8, 8) => ScanCode{key: Some('.'), shift: Some('😊'), hold: Some('😊'), alt: None}, + (8, 9) => ScanCode{key: Some(0xf_u8.into()), shift: Some(0xf_u8.into()), hold: Some(0xf_u8.into()), alt: Some(0xf_u8.into())}, // shift in (blue shift) + + // the F0/tab key also doubles as a secondary power key (can't do UP5K UART rx at same time) + (8, 0) => ScanCode{key: Some(0x11_u8.into()), shift: Some(0x11_u8.into()), hold: Some(0x11_u8.into()), alt: Some(0x11_u8.into())}, // DC1 (F1) + (8, 1) => ScanCode{key: Some(0x12_u8.into()), shift: Some(0x12_u8.into()), hold: Some(0x12_u8.into()), alt: Some(0x12_u8.into())}, // DC2 (F2) + (3, 8) => ScanCode{key: Some(0x13_u8.into()), shift: Some(0x13_u8.into()), hold: Some(0x13_u8.into()), alt: Some(0x13_u8.into())}, // DC3 (F3) + // the F4/ctrl key also doubles as a power key + (3, 9) => ScanCode{key: Some(0x14_u8.into()), shift: Some(0x14_u8.into()), hold: Some(0x14_u8.into()), alt: Some(0x14_u8.into())}, // DC4 (F4) + (8, 3) => ScanCode{key: Some('←'), shift: Some('←'), hold: None, alt: Some('←')}, + (3, 6) => ScanCode{key: Some('β†’'), shift: Some('β†’'), hold: None, alt: Some('β†’')}, + (6, 4) => ScanCode{key: Some('↑'), shift: Some('↑'), hold: None, alt: Some('↑')}, + (8, 2) => ScanCode{key: Some('↓'), shift: Some('↓'), hold: None, alt: Some('↓')}, + // this one is OK + (5, 2) => ScanCode{key: Some('∴'), shift: Some('∴'), hold: None, alt: Some('∴')}, + + _ => ScanCode {key: None, shift: None, hold: None, alt: None} + } +} diff --git a/services/keyboard/src/mappings/qwertz.rs b/services/keyboard/src/mappings/qwertz.rs new file mode 100644 index 000000000..490b1ee6c --- /dev/null +++ b/services/keyboard/src/mappings/qwertz.rs @@ -0,0 +1,73 @@ +use crate::{RowCol, ScanCode}; + +/// Compute the qwertz key mapping of row/col to key tuples +pub(crate) fn map_qwertz(code: RowCol) -> ScanCode { + let rc = (code.r, code.c); + + match rc { + (0, 0) => ScanCode{key: Some('1'), shift: Some('1'), hold: Some('!'), alt: None}, + (0, 1) => ScanCode{key: Some('2'), shift: Some('2'), hold: Some('"'), alt: None}, + (0, 2) => ScanCode{key: Some('3'), shift: Some('3'), hold: Some('Β§'), alt: None}, + (0, 3) => ScanCode{key: Some('4'), shift: Some('4'), hold: Some('$'), alt: None}, + (0, 4) => ScanCode{key: Some('5'), shift: Some('5'), hold: Some('%'), alt: None}, + (4, 5) => ScanCode{key: Some('6'), shift: Some('6'), hold: Some('&'), alt: None}, + (4, 6) => ScanCode{key: Some('7'), shift: Some('7'), hold: Some('/'), alt: None}, + (4, 7) => ScanCode{key: Some('8'), shift: Some('8'), hold: Some('('), alt: None}, + (4, 8) => ScanCode{key: Some('9'), shift: Some('9'), hold: Some(')'), alt: None}, + (4, 9) => ScanCode{key: Some('0'), shift: Some('0'), hold: Some('='), alt: None}, + + (1, 0) => ScanCode{key: Some('q'), shift: Some('Q'), hold: Some('@'), alt: None}, + (1, 1) => ScanCode{key: Some('w'), shift: Some('W'), hold: Some('ß'), alt: None}, + (1, 2) => ScanCode{key: Some('e'), shift: Some('E'), hold: Some('€'), alt: None}, + (1, 3) => ScanCode{key: Some('r'), shift: Some('R'), hold: Some('^'), alt: None}, + (1, 4) => ScanCode{key: Some('t'), shift: Some('T'), hold: Some('Β‘'), alt: None}, + (5, 5) => ScanCode{key: Some('z'), shift: Some('Z'), hold: Some('ΒΏ'), alt: None}, + (5, 6) => ScanCode{key: Some('u'), shift: Some('U'), hold: Some('ΓΌ'), alt: None}, + (5, 7) => ScanCode{key: Some('i'), shift: Some('I'), hold: Some('~'), alt: None}, + (5, 8) => ScanCode{key: Some('o'), shift: Some('O'), hold: Some('ΓΆ'), alt: None}, + (5, 9) => ScanCode{key: Some('p'), shift: Some('P'), hold: Some('#'), alt: None}, + + (2, 0) => ScanCode{key: Some('a'), shift: Some('A'), hold: Some('Γ€'), alt: None}, + (2, 1) => ScanCode{key: Some('s'), shift: Some('S'), hold: Some('['), alt: None}, + (2, 2) => ScanCode{key: Some('d'), shift: Some('D'), hold: Some(']'), alt: None}, + (2, 3) => ScanCode{key: Some('f'), shift: Some('F'), hold: Some('*'), alt: None}, + (2, 4) => ScanCode{key: Some('g'), shift: Some('G'), hold: Some('-'), alt: None}, + (6, 5) => ScanCode{key: Some('h'), shift: Some('H'), hold: Some('+'), alt: None}, + (6, 6) => ScanCode{key: Some('j'), shift: Some('J'), hold: Some('\\'), alt: None}, + (6, 7) => ScanCode{key: Some('k'), shift: Some('K'), hold: Some('{'), alt: None}, + (6, 8) => ScanCode{key: Some('l'), shift: Some('L'), hold: Some('}'), alt: None}, + (6, 9) => ScanCode{key: Some(0x8_u8.into()), shift: Some(0x8_u8.into()), hold: None /* hold of none -> repeat */, alt: Some(0x8_u8.into())}, // backspace + + (3, 0) => ScanCode{key: None, shift: Some('?'), hold: Some('?'), alt: None}, + (3, 1) => ScanCode{key: Some('y'), shift: Some('Y'), hold: Some('|'), alt: None}, + (3, 2) => ScanCode{key: Some('x'), shift: Some('X'), hold: Some('_'), alt: None}, + (3, 3) => ScanCode{key: Some('c'), shift: Some('C'), hold: Some('`'), alt: None}, + (3, 4) => ScanCode{key: Some('v'), shift: Some('V'), hold: Some('\''), alt: None}, + (7, 5) => ScanCode{key: Some('b'), shift: Some('B'), hold: Some(':'), alt: None}, + (7, 6) => ScanCode{key: Some('n'), shift: Some('N'), hold: Some(';'), alt: None}, + (7, 7) => ScanCode{key: Some('m'), shift: Some('M'), hold: Some('Β΅'), alt: None}, + (7, 8) => ScanCode{key: Some('<'), shift: Some('<'), hold: Some('>'), alt: None}, + (7, 9) => ScanCode{key: Some(0xd_u8.into()), shift: Some(0xd_u8.into()), hold: Some(0xd_u8.into()), alt: Some(0xd_u8.into())}, // carriage return + + (8, 5) => ScanCode{key: Some(0xf_u8.into()), shift: Some(0xf_u8.into()), hold: Some(0xf_u8.into()), alt: Some(0xf_u8.into())}, // shift in (blue shift) + (8, 6) => ScanCode{key: Some(','), shift: Some(0xe_u8.into()), hold: Some('福'), alt: None}, // 0xe is shift out (sym) '富' -> just for testing hanzi plane + (8, 7) => ScanCode{key: Some(' '), shift: Some(' '), hold: None /* hold of none -> repeat */, alt: None}, + (8, 8) => ScanCode{key: Some('.'), shift: Some('😊'), hold: Some('😊'), alt: None}, + (8, 9) => ScanCode{key: Some(0xf_u8.into()), shift: Some(0xf_u8.into()), hold: Some(0xf_u8.into()), alt: Some(0xf_u8.into())}, // shift in (blue shift) + + // the F0/tab key also doubles as a secondary power key (can't do UP5K UART rx at same time) + (8, 0) => ScanCode{key: Some(0x11_u8.into()), shift: Some(0x11_u8.into()), hold: Some('\t'), alt: Some(0x11_u8.into())}, // DC1 (F1) + (8, 1) => ScanCode{key: Some(0x12_u8.into()), shift: Some(0x12_u8.into()), hold: Some(0x12_u8.into()), alt: Some(0x12_u8.into())}, // DC2 (F2) + (3, 8) => ScanCode{key: Some(0x13_u8.into()), shift: Some(0x13_u8.into()), hold: Some(0x13_u8.into()), alt: Some(0x13_u8.into())}, // DC3 (F3) + // the F4/ctrl key also doubles as a power key + (3, 9) => ScanCode{key: Some(0x14_u8.into()), shift: Some(0x14_u8.into()), hold: Some(0x14_u8.into()), alt: Some(0x14_u8.into())}, // DC4 (F4) + (8, 3) => ScanCode{key: Some('←'), shift: Some('←'), hold: None, alt: Some('←')}, + (3, 6) => ScanCode{key: Some('β†’'), shift: Some('β†’'), hold: None, alt: Some('β†’')}, + (6, 4) => ScanCode{key: Some('↑'), shift: Some('↑'), hold: None, alt: Some('↑')}, + (8, 2) => ScanCode{key: Some('↓'), shift: Some('↓'), hold: None, alt: Some('↓')}, + // this one is OK + (5, 2) => ScanCode{key: Some('∴'), shift: Some('∴'), hold: None, alt: Some('∴')}, + + _ => ScanCode {key: None, shift: None, hold: None, alt: None} + } +}