xous-core/services/keyboard/src/api.rs

115 lines
2.9 KiB
Rust
Raw Normal View History

pub const SERVER_NAME_KBD: &str = "_Matrix keyboard driver_";
2021-01-10 22:11:15 +00:00
#[derive(Debug, Default, Copy, Clone)]
pub struct ScanCode {
/// base key value
pub key: Option<char>,
/// tap blue shift key, then key
pub shift: Option<char>,
/// hold blue shift key, then key
pub hold: Option<char>,
/// hold orange shift key, then key
pub alt: Option<char>,
}
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
2021-01-10 22:11:15 +00:00
pub enum KeyMap {
Qwerty,
Azerty,
Qwertz,
Dvorak,
Braille,
Undefined,
}
impl From<usize> for KeyMap {
fn from(code: usize) -> Self {
match code {
0 => KeyMap::Qwerty,
1 => KeyMap::Azerty,
2 => KeyMap::Qwertz,
3 => KeyMap::Dvorak,
4 => KeyMap::Braille,
_ => KeyMap::Qwerty,
2021-01-10 22:11:15 +00:00
}
}
}
impl Into<usize> for KeyMap {
fn into(self) -> usize {
match self {
// note: these indicese correspond to the position on the keyboard menu
2021-01-10 22:11:15 +00:00
KeyMap::Qwerty => 0,
KeyMap::Azerty => 1,
KeyMap::Qwertz => 2,
KeyMap::Dvorak => 3,
KeyMap::Braille => 4,
2021-01-10 22:11:15 +00:00
KeyMap::Undefined => 255,
}
}
}
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
pub(crate) enum Opcode {
2021-01-10 22:11:15 +00:00
/// set which keyboard mapping is present
SelectKeyMap, //(KeyMap),
GetKeyMap,
2021-01-10 22:11:15 +00:00
/// request for ScanCodes
RegisterListener,
2021-01-10 22:11:15 +00:00
/// request for raw keyups/downs
RegisterRawListener,
2021-01-10 22:11:15 +00:00
/// set repeat delay, rate; both in ms
SetRepeat, //(u32, u32),
2021-01-10 22:11:15 +00:00
/// set chording interval (how long to wait for all keydowns to happen before interpreting as a chord), in ms (for braille keyboards)
SetChordInterval, //(u32),
2021-04-15 20:11:25 +00:00
/// used by host mode emulation and debug UART to inject keys
InjectKey, //(char),
2021-01-10 22:11:15 +00:00
/// used by the interrupt handler to transfer results to the main loop
2021-04-04 10:23:26 +00:00
HandlerTrigger,
2021-04-16 11:27:48 +00:00
/// used to turn keyboard vibrate on and off
Vibe,
/// Suspend/resume callback
SuspendResume,
2021-01-10 22:11:15 +00:00
}
// this structure is used to register a keyboard listener. Currently, we only accept
// one trusted listener (enforced by name server and structurally in the code),
// which is the GAM.
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
pub(crate) struct KeyboardRegistration {
pub server_name: xous_ipc::String::<64>,
pub listener_op_id: usize,
}
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash)]
pub struct RowCol {
pub r: u8,
pub c: u8,
}
impl RowCol {
#[allow(dead_code)]
pub fn new(r: u8, c: u8) -> RowCol {
RowCol { r, c }
}
}
#[derive(Debug)]
pub struct KeyRawStates {
pub keydowns: Vec::<RowCol>,
pub keyups: Vec::<RowCol>,
}
impl KeyRawStates {
pub fn new() -> Self {
KeyRawStates {
keydowns: Vec::with_capacity(16),
keyups: Vec::with_capacity(16),
}
}
}