aboutsummaryrefslogtreecommitdiff
path: root/src/machine/key.rs
diff options
context:
space:
mode:
authorTianhao Wang <wth@riseup.net>2024-02-05 04:18:51 +0100
committerTianhao Wang <shrik3@mailbox.org>2024-06-11 15:13:38 +0200
commit959d50d9117a0ed3f280bf7d5bfbffd1fa1a5740 (patch)
treecfa2d2cf408ce9597fed3076b76251b8e3e7537d /src/machine/key.rs
parenta6b91c56f29257c3e54f0bfb2d99bf07262cb184 (diff)
PS/2 Keyboard controller: read and decode key
Diffstat (limited to 'src/machine/key.rs')
-rw-r--r--src/machine/key.rs51
1 files changed, 13 insertions, 38 deletions
diff --git a/src/machine/key.rs b/src/machine/key.rs
index 04220a6..8d4e5f9 100644
--- a/src/machine/key.rs
+++ b/src/machine/key.rs
@@ -1,17 +1,14 @@
use bitflags::bitflags;
use core::convert;
+use core::ffi::c_uchar;
+#[derive(Copy, Clone, Debug)]
pub struct Key {
- asc: u8,
- scan: u8,
- modi: Modifiers,
- rawcode: u8, // this field not necessary, remove after testing
+ pub asc: c_uchar,
+ pub scan: u8,
+ pub modi: Modifiers,
}
-// Not implementing
-// +operator char()
-//
-
impl convert::Into<char> for Key {
fn into(self) -> char {
self.asc as char
@@ -25,6 +22,7 @@ impl convert::Into<u8> for Key {
}
bitflags! {
+ #[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub struct Modifiers:u8 {
const NONE = 0;
const SHIFT = 1 << 0;
@@ -42,10 +40,9 @@ bitflags! {
impl Key {
pub fn new() -> Self {
Self {
- asc: 0,
- scan: 0,
+ asc: 0, // logically scan + modi.shift => asc
+ scan: 0, // scancode, "raw"
modi: Modifiers::NONE,
- rawcode: 0,
}
}
pub fn decode(&mut self) {
@@ -59,14 +56,6 @@ impl Key {
self.scan = 0;
}
- pub fn set_raw(&mut self, code: u8) {
- self.rawcode = code;
- }
-
- pub fn get_raw(self) -> u8 {
- self.rawcode
- }
-
// setter and getter for ascii and scancode
pub fn set_ascii(&mut self, ascii: u8) {
self.asc = ascii;
@@ -98,20 +87,6 @@ impl Key {
}
}
-use core::ffi::c_uchar;
-
-// bit masks for modifier keys
-pub enum MbitDefs {
- Shift = 0b00000001,
- AltLeft = 0b00000010,
- AltRight = 0b00000100,
- CtrlLeft = 0b00001000,
- CtrlRight = 0b00010000,
- CapsLock = 0b00100000,
- NumLock = 0b01000000,
- ScrollLock = 0b10000000,
-}
-
// scan codes of a few specific keys
pub enum Scan {
F1 = 0x3b,
@@ -126,25 +101,25 @@ pub enum Scan {
// Decoding tables ... this shit is so ugly, thanks to rust's strong typing system!!!
// Also, this is a german layout keyboard
// oh btw, the code translation is done by ChatGPT if it's wrong complain to the AI!
-const NORMAL_TAB: [c_uchar; 89] = [
+pub const NORMAL_TAB: [c_uchar; 89] = [
0, 0, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 225, 39, 8, 0, 113, 119, 101, 114, 116, 122, 117,
105, 111, 112, 129, 43, 10, 0, 97, 115, 100, 102, 103, 104, 106, 107, 108, 148, 132, 94, 0, 35,
121, 120, 99, 118, 98, 110, 109, 44, 46, 45, 0, 42, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 45, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0, 60, 0, 0,
];
-const SHIFT_TAB: [c_uchar; 89] = [
+pub const SHIFT_TAB: [c_uchar; 89] = [
0, 0, 33, 34, 21, 36, 37, 38, 47, 40, 41, 61, 63, 96, 0, 0, 81, 87, 69, 82, 84, 90, 85, 73, 79,
80, 154, 42, 0, 0, 65, 83, 68, 70, 71, 72, 74, 75, 76, 153, 142, 248, 0, 39, 89, 88, 67, 86,
66, 78, 77, 59, 58, 95, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0,
];
-const ALT_TAB: [c_uchar; 89] = [
+pub const ALT_TAB: [c_uchar; 89] = [
0, 0, 0, 253, 0, 0, 0, 0, 123, 91, 93, 125, 92, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 126,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 124, 0, 0,
];
-const ASC_NUM_TAB: [c_uchar; 13] = [55, 56, 57, 45, 52, 53, 54, 43, 49, 50, 51, 48, 44];
-const SCAN_NUM_TAB: [c_uchar; 13] = [8, 9, 10, 53, 5, 6, 7, 27, 2, 3, 4, 11, 51];
+pub const ASC_NUM_TAB: [c_uchar; 13] = [55, 56, 57, 45, 52, 53, 54, 43, 49, 50, 51, 48, 44];
+pub const SCAN_NUM_TAB: [c_uchar; 13] = [8, 9, 10, 53, 5, 6, 7, 27, 2, 3, 4, 11, 51];