From 4d8f90dd4d4544bb272849fb1038fa4c67dc0c44 Mon Sep 17 00:00:00 2001 From: Maximilian Fischer Date: Tue, 15 Dec 2015 13:03:06 +0100 Subject: [PATCH 1/4] added altGr support to keyboard --- kernel/drivers/kb_layouts/layouts.rs | 357 ++++++++++++++------------- kernel/drivers/ps2.rs | 22 +- 2 files changed, 194 insertions(+), 185 deletions(-) diff --git a/kernel/drivers/kb_layouts/layouts.rs b/kernel/drivers/kb_layouts/layouts.rs index 3a72edc6a..2a130f2fa 100644 --- a/kernel/drivers/kb_layouts/layouts.rs +++ b/kernel/drivers/kb_layouts/layouts.rs @@ -26,14 +26,15 @@ pub fn get_scancode_from_layout(layout: &Layout, scancode: u8) -> [char; 2] { } /// Function to return the character associated with the scancode, and the layout -pub fn char_for_scancode(scancode: u8, shift: bool, layout: &Layout) -> char { +pub fn char_for_scancode(scancode: u8, shift: bool, altgr: bool, layout: &Layout) -> char { let mut character = '\x00'; if scancode < 58 { - let characters: [char; 2] = get_scancode_from_layout(layout, scancode); - if shift { + let characters: [char; 3] = get_scancode_from_layout(layout, scancode); + if altgr { + character = characters[2]; + } else if shift { character = characters[1]; } else { - // Else... character = characters[0]; } } @@ -43,182 +44,182 @@ pub fn char_for_scancode(scancode: u8, shift: bool, layout: &Layout) -> char { // SCANCODES /// Scancodes for English keyboards -static SCANCODES_EN: [[char; 2]; 58] = [['\0', '\0'], - ['\x1B', '\x1B'], - ['1', '!'], - ['2', '@'], - ['3', '#'], - ['4', '$'], - ['5', '%'], - ['6', '^'], - ['7', '&'], - ['8', '*'], - ['9', '('], - ['0', ')'], - ['-', '_'], - ['=', '+'], - ['\0', '\0'], - ['\t', '\t'], - ['q', 'Q'], - ['w', 'W'], - ['e', 'E'], - ['r', 'R'], - ['t', 'T'], - ['y', 'Y'], - ['u', 'U'], - ['i', 'I'], - ['o', 'O'], - ['p', 'P'], - ['[', '{'], - [']', '}'], - ['\n', '\n'], - ['\0', '\0'], - ['a', 'A'], - ['s', 'S'], - ['d', 'D'], - ['f', 'F'], - ['g', 'G'], - ['h', 'H'], - ['j', 'J'], - ['k', 'K'], - ['l', 'L'], - [';', ':'], - ['\'', '"'], - ['`', '~'], - ['\0', '\0'], - ['\\', '|'], - ['z', 'Z'], - ['x', 'X'], - ['c', 'C'], - ['v', 'V'], - ['b', 'B'], - ['n', 'N'], - ['m', 'M'], - [',', '<'], - ['.', '>'], - ['/', '?'], - ['\0', '\0'], - ['\0', '\0'], - ['\0', '\0'], - [' ', ' ']]; +static SCANCODES_EN: [[char; 3]; 58] = [['\0', '\0', '\0'], + ['\x1B', '\x1B', '\x1B'], + ['1', '!', '1'], + ['2', '@', '2'], + ['3', '#', '3'], + ['4', '$', '4'], + ['5', '%', '5'], + ['6', '^', '6'], + ['7', '&', '7'], + ['8', '*', '8'], + ['9', '(', '9'], + ['0', ')', '0'], + ['-', '_', '-'], + ['=', '+', '='], + ['\0', '\0', '\0'], + ['\t', '\t', '\t'], + ['q', 'Q', 'q'], + ['w', 'W', 'w'], + ['e', 'E', 'e'], + ['r', 'R', 'r'], + ['t', 'T', 't'], + ['y', 'Y', 'y'], + ['u', 'U', 'u'], + ['i', 'I', 'i'], + ['o', 'O', 'o'], + ['p', 'P', 'p'], + ['[', '{', '['], + [']', '}', ']'], + ['\n', '\n', '\n'], + ['\0', '\0', '\0'], + ['a', 'A', 'a'], + ['s', 'S', 's'], + ['d', 'D', 'd'], + ['f', 'F', 'f'], + ['g', 'G', 'g'], + ['h', 'H', 'h'], + ['j', 'J', 'j'], + ['k', 'K', 'k'], + ['l', 'L', 'l'], + [';', ':', ';'], + ['\'', '"', '\''], + ['`', '~', '`'], + ['\0', '\0', '\0'], + ['\\', '|', '\\'], + ['z', 'Z', 'z'], + ['x', 'X', 'x'], + ['c', 'C', 'c'], + ['v', 'V', 'v'], + ['b', 'B', 'b'], + ['n', 'N', 'n'], + ['m', 'M', 'm'], + [',', '<', ','], + ['.', '>', '.'], + ['/', '?', '/'], + ['\0', '\0', '\0'], + ['\0', '\0', '\0'], + ['\0', '\0', '\0'], + [' ', ' ', ' ']]; /// Scancodes for French keyboards -static SCANCODES_FR: [[char; 2]; 58] = [['\0', '\0'], - ['\x1B', '\x1B'], - ['1', '&'], - ['2', 'é'], - ['3', '"'], - ['4', '\''], - ['5', '('], - ['6', '-'], - ['7', 'è'], - ['8', '_'], - ['9', 'ç'], - ['0', 'à'], - ['-', ')'], - ['=', '='], - ['\0', '\0'], - ['\t', '\t'], - ['a', 'A'], - ['z', 'Z'], - ['e', 'E'], - ['r', 'R'], - ['t', 'T'], - ['y', 'Y'], - ['u', 'U'], - ['i', 'I'], - ['o', 'O'], - ['p', 'P'], - ['^', '¨'], - ['$', '£'], - ['\n', '\n'], - ['\0', '\0'], - ['q', 'Q'], - ['s', 'S'], - ['d', 'D'], - ['f', 'F'], - ['g', 'G'], - ['h', 'H'], - ['j', 'J'], - ['k', 'K'], - ['l', 'L'], - ['m', 'M'], - ['ù', '%'], - ['*', 'µ'], - ['\0', '\0'], - ['<', '>'], - ['w', 'W'], - ['x', 'X'], - ['c', 'C'], - ['v', 'V'], - ['b', 'B'], - ['n', 'N'], - [',', '?'], - [';', '.'], - [':', '/'], - ['!', '§'], - ['\0', '\0'], - ['\0', '\0'], - ['\0', '\0'], - [' ', ' ']]; +static SCANCODES_FR: [[char; 2]; 58] = [['\0', '\0', '\0'], + ['\x1B', '\x1B', '\0'], + ['1', '&', '1'], + ['2', 'é', '2'], + ['3', '"', '3'], + ['4', '\'', '4'], + ['5', '(', '5'], + ['6', '-', '6'], + ['7', 'è', '7'], + ['8', '_', '8'], + ['9', 'ç', '9'], + ['0', 'à', '0'], + ['-', ')', '-'], + ['=', '=', '='], + ['\0', '\0', '\0'], + ['\t', '\t', '\t'], + ['a', 'A', 'a'], + ['z', 'Z', 'z'], + ['e', 'E', 'e'], + ['r', 'R', 'r'], + ['t', 'T', 't'], + ['y', 'Y', 'y'], + ['u', 'U', 'u'], + ['i', 'I', 'i'], + ['o', 'O', 'o'], + ['p', 'P', 'p'], + ['^', '¨', '^'], + ['$', '£', '$'], + ['\n', '\n', '\n'], + ['\0', '\0', '\0'], + ['q', 'Q', 'q'], + ['s', 'S', 's'], + ['d', 'D', 'd'], + ['f', 'F', 'f'], + ['g', 'G', 'g'], + ['h', 'H', 'h'], + ['j', 'J', 'j'], + ['k', 'K', 'k'], + ['l', 'L', 'l'], + ['m', 'M', 'm'], + ['ù', '%', 'ù'], + ['*', 'µ', '*'], + ['\0', '\0', '\0'], + ['<', '>', '|'], + ['w', 'W', 'w'], + ['x', 'X', 'x'], + ['c', 'C', 'c'], + ['v', 'V', 'v'], + ['b', 'B', 'b'], + ['n', 'N', 'n'], + [',', '?', ','], + [';', '.', ';'], + [':', '/', ':'], + ['!', '§', '!'], + ['\0', '\0', '\0'], + ['\0', '\0', '\0'], + ['\0', '\0', '\0'], + [' ', ' ', ' ']]; /// Scancodes for German keyboards -static SCANCODES_DE: [[char; 2]; 58] = [['\0', '\0'], - ['\x1B', '\x1B'], - ['1', '!'], - ['2', '"'], - ['3', '§'], - ['4', '$'], - ['5', '%'], - ['6', '&'], - ['7', '/'], - ['8', '('], - ['9', ')'], - ['0', '='], - ['ß', '?'], - ['\'', '`'], - ['\0', '\0'], - ['\t', '\t'], - ['q', 'Q'], - ['w', 'W'], - ['e', 'E'], - ['r', 'R'], - ['t', 'T'], - ['z', 'Z'], - ['u', 'U'], - ['i', 'I'], - ['o', 'O'], - ['p', 'P'], - ['ü', 'Ü'], - ['+', '*'], - ['\n', '\n'], - ['\0', '\0'], - ['a', 'A'], - ['s', 'S'], - ['d', 'D'], - ['f', 'F'], - ['g', 'G'], - ['h', 'H'], - ['j', 'J'], - ['k', 'K'], - ['l', 'L'], - ['ö', 'Ö'], - ['ä', 'Ä'], - ['#', '\''], - ['\0', '\0'], - ['<', '>'], - ['y', 'Y'], - ['x', 'X'], - ['c', 'C'], - ['v', 'V'], - ['b', 'B'], - ['n', 'N'], - ['m', 'M'], - [',', ';'], - ['.', ':'], - ['-', '_'], - ['\0', '\0'], - ['\0', '\0'], - ['\0', '\0'], - [' ', ' ']]; +static SCANCODES_DE: [[char; 3]; 58] = [['\0', '\0', '\0'], + ['\x1B', '\x1B', '\x1B'], + ['1', '!', '1'], + ['2', '"', '²'], + ['3', '§', '³'], + ['4', '$', '4'], + ['5', '%', '%'], + ['6', '&', '6'], + ['7', '/', '{'], + ['8', '(', '['], + ['9', ')', ']'], + ['0', '=', '{'], + ['ß', '?', '\\'], + ['\'', '`', '\''], + ['\0', '\0', '\0'], + ['\t', '\t', '\t'], + ['q', 'Q', '@'], + ['w', 'W', 'w'], + ['e', 'E', '€'], + ['r', 'R', 'r'], + ['t', 'T', 't'], + ['z', 'Z', 'z'], + ['u', 'U', 'u'], + ['i', 'I', 'i'], + ['o', 'O', 'o'], + ['p', 'P', 'p'], + ['ü', 'Ü', 'ü'], + ['+', '*', '~'], + ['\n', '\n', '\n'], + ['\0', '\0', '\0'], + ['a', 'A', 'a'], + ['s', 'S', 's'], + ['d', 'D', 'd'], + ['f', 'F', 'f'], + ['g', 'G', 'g'], + ['h', 'H', 'h'], + ['j', 'J', 'j'], + ['k', 'K', 'k'], + ['l', 'L', 'l'], + ['ö', 'Ö', 'ö'], + ['ä', 'Ä', 'ä'], + ['#', '\'', '#'], + ['\0', '\0', '\0'], + ['<', '>', '|'], + ['y', 'Y', 'y'], + ['x', 'X', 'x'], + ['c', 'C', 'c'], + ['v', 'V', 'v'], + ['b', 'B', 'b'], + ['n', 'N', 'n'], + ['m', 'M', 'µ'], + [',', ';', ','], + ['.', ':', '.'], + ['-', '_', '-'], + ['\0', '\0', '\0'], + ['\0', '\0', '\0'], + ['\0', '\0', '\0'], + [' ', ' ', ' ']]; diff --git a/kernel/drivers/ps2.rs b/kernel/drivers/ps2.rs index 54c8518d4..861ec1cfd 100644 --- a/kernel/drivers/ps2.rs +++ b/kernel/drivers/ps2.rs @@ -26,6 +26,8 @@ pub struct Ps2 { caps_lock: bool, /// Caps lock toggle caps_lock_toggle: bool, + /// AltGr? + altgr: bool, /// The mouse packet mouse_packet: [u8; 4], /// Mouse packet index @@ -49,6 +51,7 @@ impl Ps2 { rshift: false, caps_lock: false, caps_lock_toggle: false, + altgr: false, mouse_packet: [0; 4], mouse_i: 0, mouse_x: 0, @@ -140,17 +143,22 @@ impl Ps2 { if self.caps_lock && !self.caps_lock_toggle { self.caps_lock = false; } + } else if scancode == 0xE0 { + let scancode_byte_2 = unsafe { self.data.read() }; + if scancode_byte_2 == 0x11 { + self.altgr = true; + } else if scancode_byte_2 == 0xF0 { + let scancode_byte_3 = unsafe { self.data.read() }; + if scancode_byte_3 == 0x11 { + self.altgr = false; + } + } } - let shift; - if self.caps_lock { - shift = !(self.lshift || self.rshift); - } else { - shift = self.lshift || self.rshift; - } + let shift = self.caps_lock != (self.lshift || self.rshift); return Some(KeyEvent { - character: layouts::char_for_scancode(scancode & 0x7F, shift, &self.layout), + character: layouts::char_for_scancode(scancode & 0x7F, shift, self.altgr, &self.layout), scancode: scancode & 0x7F, pressed: scancode < 0x80, }); From 4efedabc4ddac152e9498aca5eeb68f3e46a554c Mon Sep 17 00:00:00 2001 From: Maximilian Fischer Date: Tue, 15 Dec 2015 13:03:20 +0100 Subject: [PATCH 2/4] updated submodule --- rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust b/rust index 5d1fd1e37..64668ae40 160000 --- a/rust +++ b/rust @@ -1 +1 @@ -Subproject commit 5d1fd1e37dae114978a7d53cf363a93b7dc98404 +Subproject commit 64668ae405b6989d8426f45f0ce9cb68eac078a7 From b49dfca75c46c823a355279b8733bf7171d09e39 Mon Sep 17 00:00:00 2001 From: Maximilian Fischer Date: Wed, 16 Dec 2015 15:16:57 +0100 Subject: [PATCH 3/4] Add support for right alt key (altgr) --- kernel/drivers/kb_layouts/layouts.rs | 54 ++++++++++++++++++++-------- kernel/drivers/ps2.rs | 9 ++--- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/kernel/drivers/kb_layouts/layouts.rs b/kernel/drivers/kb_layouts/layouts.rs index 2a130f2fa..abee9a42a 100644 --- a/kernel/drivers/kb_layouts/layouts.rs +++ b/kernel/drivers/kb_layouts/layouts.rs @@ -2,6 +2,7 @@ /// The layout can be: /// * ENGLISH /// * FRENCH +/// * GERMAN pub enum Layout { ENGLISH, FRENCH, @@ -15,9 +16,9 @@ pub enum Layout { /// ``` /// let layout = Layout::ENGLISH; /// //Get the scancode 'EN' -/// let sc : [[char; 2]; 58] = get_scancode_from_layout(layout); +/// let sc : [[char; 3]; 58] = get_scancode_from_layout(layout); /// ``` -pub fn get_scancode_from_layout(layout: &Layout, scancode: u8) -> [char; 2] { +pub fn get_scancode_from_layout(layout: &Layout, scancode: u8) -> [char; 3] { match *layout { Layout::ENGLISH => SCANCODES_EN[scancode as usize], Layout::FRENCH => SCANCODES_FR[scancode as usize], @@ -25,18 +26,34 @@ pub fn get_scancode_from_layout(layout: &Layout, scancode: u8) -> [char; 2] { } } +fn get_special_keys_from_layout(layout: &Layout, scancode: u8) -> [char; 3] { + let keys : &[(u8, [char; 3])] = match *layout { + Layout::ENGLISH => SCANCODES_EXTRA_EN, + Layout::FRENCH => SCANCODES_EXTRA_FR, + Layout::GERMAN => SCANCODES_EXTRA_DE, + }; + match keys.iter().filter(|&&(code, keys)| code == scancode).next() { + Some(&(code, keys)) => keys, + None => ['\0', '\0', '\0'] + } +} + + /// Function to return the character associated with the scancode, and the layout pub fn char_for_scancode(scancode: u8, shift: bool, altgr: bool, layout: &Layout) -> char { let mut character = '\x00'; + let mut characters: [char; 3] = ['\0', '\0', '\0']; if scancode < 58 { - let characters: [char; 3] = get_scancode_from_layout(layout, scancode); - if altgr { - character = characters[2]; - } else if shift { - character = characters[1]; - } else { - character = characters[0]; - } + characters = get_scancode_from_layout(layout, scancode); + } else { + characters = get_special_keys_from_layout(layout, scancode); + } + if altgr { + character = characters[2]; + } else if shift { + character = characters[1]; + } else { + character = characters[0]; } character } @@ -103,8 +120,11 @@ static SCANCODES_EN: [[char; 3]; 58] = [['\0', '\0', '\0'], ['\0', '\0', '\0'], [' ', ' ', ' ']]; +/// Special keys, not present on every keyboard +static SCANCODES_EXTRA_EN: &'static[(u8, [char; 3])] = &[]; + /// Scancodes for French keyboards -static SCANCODES_FR: [[char; 2]; 58] = [['\0', '\0', '\0'], +static SCANCODES_FR: [[char; 3]; 58] = [['\0', '\0', '\0'], ['\x1B', '\x1B', '\0'], ['1', '&', '1'], ['2', 'é', '2'], @@ -163,6 +183,9 @@ static SCANCODES_FR: [[char; 2]; 58] = [['\0', '\0', '\0'], ['\0', '\0', '\0'], [' ', ' ', ' ']]; +/// Special keys, not present on every keyboard +static SCANCODES_EXTRA_FR: &'static[(u8, [char; 3])] = &[]; + /// Scancodes for German keyboards static SCANCODES_DE: [[char; 3]; 58] = [['\0', '\0', '\0'], ['\x1B', '\x1B', '\x1B'], @@ -175,7 +198,7 @@ static SCANCODES_DE: [[char; 3]; 58] = [['\0', '\0', '\0'], ['7', '/', '{'], ['8', '(', '['], ['9', ')', ']'], - ['0', '=', '{'], + ['0', '=', '}'], ['ß', '?', '\\'], ['\'', '`', '\''], ['\0', '\0', '\0'], @@ -205,9 +228,9 @@ static SCANCODES_DE: [[char; 3]; 58] = [['\0', '\0', '\0'], ['l', 'L', 'l'], ['ö', 'Ö', 'ö'], ['ä', 'Ä', 'ä'], - ['#', '\'', '#'], + ['^', '°', '^'], ['\0', '\0', '\0'], - ['<', '>', '|'], + ['#', '\'', '#'], ['y', 'Y', 'y'], ['x', 'X', 'x'], ['c', 'C', 'c'], @@ -223,3 +246,6 @@ static SCANCODES_DE: [[char; 3]; 58] = [['\0', '\0', '\0'], ['\0', '\0', '\0'], [' ', ' ', ' ']]; +/// Special keys, not present on every keyboard +static SCANCODES_EXTRA_DE: &'static[(u8, [char; 3])] = &[(0x56, ['<', '>', '|'])]; + diff --git a/kernel/drivers/ps2.rs b/kernel/drivers/ps2.rs index 861ec1cfd..9e1e0b4ee 100644 --- a/kernel/drivers/ps2.rs +++ b/kernel/drivers/ps2.rs @@ -145,13 +145,10 @@ impl Ps2 { } } else if scancode == 0xE0 { let scancode_byte_2 = unsafe { self.data.read() }; - if scancode_byte_2 == 0x11 { + if scancode_byte_2 == 0x38 { self.altgr = true; - } else if scancode_byte_2 == 0xF0 { - let scancode_byte_3 = unsafe { self.data.read() }; - if scancode_byte_3 == 0x11 { - self.altgr = false; - } + } else if scancode_byte_2 == 0xB8 { + self.altgr = false; } } From a0ec5e383401bcbd2a8cfee93ea31b61926cbad1 Mon Sep 17 00:00:00 2001 From: Maximilian Fischer Date: Fri, 18 Dec 2015 07:27:38 +0100 Subject: [PATCH 4/4] new commits in rust --- rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust b/rust index 64668ae40..660787e1a 160000 --- a/rust +++ b/rust @@ -1 +1 @@ -Subproject commit 64668ae405b6989d8426f45f0ce9cb68eac078a7 +Subproject commit 660787e1a61d5367c187ea2228deb0048e344343