[haiku-development] [PATCH 4/4] Use emergency driver for USB keyboards

---
 .../drivers/input/usb_hid/KeyboardDevice.cpp       |   46 +++++++++++++++++--
 .../kernel/drivers/input/usb_hid/KeyboardDevice.h  |    5 ++
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/src/add-ons/kernel/drivers/input/usb_hid/KeyboardDevice.cpp 
b/src/add-ons/kernel/drivers/input/usb_hid/KeyboardDevice.cpp
index f9db269..379afd9 100644
--- a/src/add-ons/kernel/drivers/input/usb_hid/KeyboardDevice.cpp
+++ b/src/add-ons/kernel/drivers/input/usb_hid/KeyboardDevice.cpp
@@ -11,6 +11,10 @@
 #include <string.h>
 #include <usb/USB_hid.h>
 
+#if HAIKU_TARGET_PLATFORM_HAIKU
+#include <emergency.h>
+#endif
+
 // input server private for raw_key_info, KB_READ, etc...
 #include "kb_mouse_driver.h"
 
@@ -22,7 +26,9 @@ KeyboardDevice::KeyboardDevice(usb_device device, usb_pipe 
interruptPipe,
                        instructionCount, totalReportSize, 512),
                fRepeatDelay(300000),
                fRepeatRate(35000),
-               fLastTransferBuffer(NULL)
+               fLastTransferBuffer(NULL),
+               fF12Pressed(false),
+               fEmergencyModule(NULL)
 {
        fCurrentRepeatDelay = B_INFINITE_TIMEOUT;
        fCurrentRepeatKey = 0;
@@ -34,11 +40,20 @@ KeyboardDevice::KeyboardDevice(usb_device device, usb_pipe 
interruptPipe,
        }
 
        SetBaseName("input/keyboard/usb/");
+
+#if HAIKU_TARGET_PLATFORM_HAIKU
+       /* Don't care if it could be loaded or not... */
+       get_module(B_EMERGENCY_MODULE_NAME, (module_info **)&fEmergencyModule);
+#endif
 }
 
 
 KeyboardDevice::~KeyboardDevice()
 {
+#if HAIKU_TARGET_PLATFORM_HAIKU
+       if (fEmergencyModule)
+               put_module(B_EMERGENCY_MODULE_NAME);
+#endif
        free(fLastTransferBuffer);
 }
 
@@ -296,6 +311,18 @@ KeyboardDevice::_InterpretBuffer()
 
        static size_t sKeyTableSize = sizeof(sKeyTable) / sizeof(sKeyTable[0]);
 
+       static char sKeymapTable[] = {
+                 0,   0,   0,   0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 
'i', 'j', 'k', 'l',
+               'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 
'y', 'z', '1', '2',
+               '3', '4', '5', '6', '7', '8', '9', '0', '\n', 27,  8, '\t', ' 
', '-', '=', '[',
+               ']',  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, '/', '*', '-', '+', '\n', '1', '2', '3', 
'4', '5', '6', '7',
+               '8', '9', '0', '.', '<', 0, 0, '='
+       };
+
+       static size_t sKeymapTableSize = sizeof(sKeymapTable) / 
sizeof(sKeymapTable[0]);
+
        uint8 modifierChange = fLastTransferBuffer[0] ^ fTransferBuffer[0];
        for (uint8 i = 0; modifierChange; i++, modifierChange >>= 1) {
                if (modifierChange & 1)
@@ -328,15 +355,24 @@ KeyboardDevice::_InterpretBuffer()
                                        key = KEY_Break;
                                else if (key == 0xe && (current[0] & 1))
                                        key = KEY_SysRq;
-#if HAIKU_TARGET_PLATFORM_HAIKU
-                               else if (keyDown && key == 0x0d) // ToDo: 
remove again
-                                       panic("keyboard requested halt.\n");
-#endif
+                               else if (key == 0x0d)
+                                       fF12Pressed = keyDown;
                                else if (key == 0) {
                                        // unmapped key
                                        key = 0x200000 + current[i];
                                }
 
+#if HAIKU_TARGET_PLATFORM_HAIKU
+                               if (keyDown && fF12Pressed) {
+                                       if (fTransferBuffer[0] & 0x22) {
+                                               /* (LShift || RShift) && F12 */
+                                               if (key != 0x0d && 
fEmergencyModule && key < sKeymapTableSize)
+                                                       
fEmergencyModule->emergency_key(sKeymapTable[current[i]]);
+                                       } else
+                                               // TODO: remove again
+                                               panic("keyboard requested 
halt.\n");
+                               }
+#endif
                                _WriteKey(key, keyDown);
 
                                if (keyDown) {
diff --git a/src/add-ons/kernel/drivers/input/usb_hid/KeyboardDevice.h 
b/src/add-ons/kernel/drivers/input/usb_hid/KeyboardDevice.h
index 620f2cf..32f94a1 100644
--- a/src/add-ons/kernel/drivers/input/usb_hid/KeyboardDevice.h
+++ b/src/add-ons/kernel/drivers/input/usb_hid/KeyboardDevice.h
@@ -8,6 +8,8 @@
 
 #include "HIDDevice.h"
 
+typedef struct emergency_module_info emergency_module_info;
+
 class KeyboardDevice : public HIDDevice {
 public:
                                                                
KeyboardDevice(usb_device device,
@@ -31,6 +33,9 @@ private:
                uint32                                  fCurrentRepeatKey;
 
                uint8 *                                 fLastTransferBuffer;
+
+               emergency_module_info   *fEmergencyModule;
+               bool                                    fF12Pressed;
 };
 
 #endif // _USB_KEYBOARD_DEVICE_H_
-- 
1.5.4.2


Other related posts: