From 1132ecca079b804631f096c9634e7e8128ccf4e7 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 16 Sep 2020 22:53:41 +0200 Subject: [PATCH] PS/2 Keyboard: fix handling of Pause key. - There is one single "Puase" key also acting as "Break" - For historical reasons it sends a complex sequence (control + num lock) instead of having its own key code Change-Id: If9fd84caf9a06cd8409b9c3642fe313a7c01fad1 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3449 Reviewed-by: Alex von Gluck IV Reviewed-by: Adrien Destugues --- .../kernel/bus_managers/ps2/ATKeymap.h | 22 +++++----- .../kernel/bus_managers/ps2/ps2_keyboard.cpp | 44 ++++++++++++++----- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/add-ons/kernel/bus_managers/ps2/ATKeymap.h b/src/add-ons/kernel/bus_managers/ps2/ATKeymap.h index 0edbe3af73..7b67655c29 100644 --- a/src/add-ons/kernel/bus_managers/ps2/ATKeymap.h +++ b/src/add-ons/kernel/bus_managers/ps2/ATKeymap.h @@ -11,7 +11,7 @@ const static uint32 kATKeycodeMap[] = { - 0x1, // Esc + 0x1, // Esc 1 0x12, // 1 0x13, // 2 0x14, // 3 @@ -20,7 +20,7 @@ const static uint32 kATKeycodeMap[] = { 0x17, // 6 0x18, // 7 0x19, // 8 - 0x1a, // 9 + 0x1a, // 9 10 0x1b, // 0 0x1c, // - 0x1d, // = @@ -30,7 +30,7 @@ const static uint32 kATKeycodeMap[] = { 0x28, // W 0x29, // E 0x2a, // R - 0x2b, // T + 0x2b, // T 20 0x2c, // Y 0x2d, // U 0x2e, // I @@ -40,7 +40,7 @@ const static uint32 kATKeycodeMap[] = { 0x32, // ] 0x47, // ENTER 0x5c, // Left Control - 0x3c, // A + 0x3c, // A 30 0x3d, // S 0x3e, // D 0x3f, // F @@ -50,7 +50,7 @@ const static uint32 kATKeycodeMap[] = { 0x43, // K 0x44, // L 0x45, // ; - 0x46, // ' + 0x46, // ' 40 0x11, // ` 0x4b, // Left Shift 0x33, // \ (backslash -- note: don't remove non-white-space after BS char) @@ -60,7 +60,7 @@ const static uint32 kATKeycodeMap[] = { 0x4f, // V 0x50, // B 0x51, // N - 0x52, // M + 0x52, // M 50 0x53, // , 0x54, // . 0x55, // / @@ -70,7 +70,7 @@ const static uint32 kATKeycodeMap[] = { 0x5e, // Space 0x3b, // Caps 0x02, // F1 - 0x03, // F2 + 0x03, // F2 60 0x04, // F3 0x05, // F4 0x06, // F5 @@ -80,7 +80,7 @@ const static uint32 kATKeycodeMap[] = { 0x0a, // F9 0x0b, // F10 0x22, // Num - 0x0f, // Scroll + 0x0f, // Scroll 70 0x37, // KP 7 0x38, // KP 8 0x39, // KP 9 @@ -90,11 +90,11 @@ const static uint32 kATKeycodeMap[] = { 0x4a, // KP 6 0x3a, // KP + 0x58, // KP 1 - 0x59, // KP 2 + 0x59, // KP 2 80 0x5a, // KP 3 0x64, // KP 0 0x65, // KP . - 0x00, // UNMAPPED + 0x7e, // SystReq 0x00, // UNMAPPED 0x69, // < 0x0c, // F11 @@ -208,7 +208,7 @@ const static uint32 kATKeycodeMap[] = { 0x00, // UNMAPPED 0x00, // UNMAPPED 0x00, // UNMAPPED - 0x7f, // Break + 0x10, // Pause 0x20, // Home 0x57, // Up Arrow 200 0x21, // Page Up diff --git a/src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.cpp b/src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.cpp index c88d941318..15ec67d391 100644 --- a/src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.cpp +++ b/src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.cpp @@ -5,7 +5,7 @@ * Authors (in chronological order): * Stefano Ceccherini (burton666@libero.it) * Axel Dörfler, axeld@pinc-software.de - * Marcus Overhagen + * Marcus Overhagen */ @@ -37,12 +37,14 @@ enum { }; enum { - EXTENDED_KEY = 0xe0, + EXTENDED_KEY_0 = 0xe0, + EXTENDED_KEY_1 = 0xe1, LEFT_ALT_KEY = 0x38, RIGHT_ALT_KEY = 0xb8, SYS_REQ_KEY = 0x54, PRNT_SCRN_KEY = 0x80 | 0x37, + PAUSE_KEY = 0x80 | 0x46, }; @@ -58,7 +60,9 @@ static bool sHasKeyboardReader = false; static bool sHasDebugReader = false; static sem_id sKeyboardSem; static struct packet_buffer *sKeyBuffer; -static bool sIsExtended = false; +static bool sIsExtended0 = false; +static bool sIsExtended1 = false; +static uint8 sPauseSequenceRead = 0; static int32 sKeyboardRepeatRate; static bigtime_t sKeyboardRepeatDelay; @@ -126,6 +130,8 @@ keyboard_handle_int(ps2_dev *dev) EMERGENCY_RIGHT_ALT = 0x02, EMERGENCY_SYS_REQ = 0x04, }; + + static const uint8 pauseSequence[] = { 0x1D, 0x45 }; static int emergencyKeyStatus = 0; raw_key_info keyInfo; uint8 scancode = dev->history[0].data; @@ -133,15 +139,17 @@ keyboard_handle_int(ps2_dev *dev) if (atomic_get(&sKeyboardOpenCount) == 0) return B_HANDLED_INTERRUPT; - // TODO: Handle braindead "pause" key special case - - if (scancode == EXTENDED_KEY) { - sIsExtended = true; -// TRACE("Extended key\n"); + if (scancode == EXTENDED_KEY_0) { + sIsExtended0 = true; + //TRACE("Extended key 0\n"); return B_HANDLED_INTERRUPT; } -// TRACE("scancode: %x\n", scancode); + if (scancode == EXTENDED_KEY_1) { + sIsExtended1 = true; + //TRACE("Extended key 1\n"); + return B_HANDLED_INTERRUPT; + } if ((scancode & 0x80) != 0) { keyInfo.is_keydown = false; @@ -149,9 +157,23 @@ keyboard_handle_int(ps2_dev *dev) } else keyInfo.is_keydown = true; - if (sIsExtended) { + // TRACE("scancode: %x\n", scancode); + + // Handle braindead "pause" key special case + if (sIsExtended1 && scancode == pauseSequence[sPauseSequenceRead]) { + sPauseSequenceRead++; + if (sPauseSequenceRead == 2) { + sIsExtended1 = false; + sPauseSequenceRead = 0; + scancode = PAUSE_KEY; + } else { + return B_HANDLED_INTERRUPT; + } + } + + if (sIsExtended0) { scancode |= 0x80; - sIsExtended = false; + sIsExtended0 = false; } // Handle emergency keys