From: John Hodge Date: Thu, 1 Mar 2012 10:21:01 +0000 (+0800) Subject: Kernel - Split key translation out of PS2Keyboard X-Git-Tag: rel0.15~744 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=f48e29379bd57e2d361cbc65477be120da47e874;p=tpg%2Facess2.git Kernel - Split key translation out of PS2Keyboard - Also unified all keyboard events into a meta-driver (/Devices/Keyboard) - NOTE: Possibly broken VTerm arrow keys due to API change --- diff --git a/KernelLand/Kernel/drv/vterm.c b/KernelLand/Kernel/drv/vterm.c index f3769187..40fa50f6 100644 --- a/KernelLand/Kernel/drv/vterm.c +++ b/KernelLand/Kernel/drv/vterm.c @@ -21,7 +21,7 @@ //#define DEFAULT_OUTPUT "BochsGA" #define DEFAULT_OUTPUT "Vesa" #define FALLBACK_OUTPUT "x86_VGAText" -#define DEFAULT_INPUT "PS2Keyboard" +#define DEFAULT_INPUT "Keyboard" #define DEFAULT_WIDTH 640 #define DEFAULT_HEIGHT 480 #define DEFAULT_SCROLLBACK 2 // 2 Screens of text + current screen diff --git a/KernelLand/Kernel/include/api_drv_keyboard.h b/KernelLand/Kernel/include/api_drv_keyboard.h index 57ca247e..f027e0e0 100644 --- a/KernelLand/Kernel/include/api_drv_keyboard.h +++ b/KernelLand/Kernel/include/api_drv_keyboard.h @@ -137,5 +137,6 @@ enum eTplKeyboard_KeyCodes { */ }; +#include "keysyms.h" #endif diff --git a/KernelLand/Kernel/include/keysyms.h b/KernelLand/Kernel/include/keysyms.h new file mode 100644 index 00000000..25169e4c --- /dev/null +++ b/KernelLand/Kernel/include/keysyms.h @@ -0,0 +1,144 @@ +/* + * Acess2 USB Stack HID Driver + * - By John Hodge (thePowersGang) + * + * usb_keysyms.h + * - USB HID Keyboard Symbols + */ +#ifndef _USB_KEYSYMS_H_ +#define _USB_KEYSYMS_H_ + +enum eUSB_Keysyms +{ + KEYSYM_NONE, + KEYSYM_ERRORROLLOVER, + KEYSYM_POSTFAIL, + KEYSYM_ERRORUNDEFINED, + // 0x04 / 4 + KEYSYM_a, KEYSYM_b, KEYSYM_c, + KEYSYM_d, KEYSYM_e, KEYSYM_f, + KEYSYM_g, KEYSYM_h, KEYSYM_i, + KEYSYM_j, KEYSYM_k, KEYSYM_l, + KEYSYM_m, KEYSYM_n, KEYSYM_o, + KEYSYM_p, KEYSYM_q, KEYSYM_r, + KEYSYM_s, KEYSYM_t, KEYSYM_u, + KEYSYM_v, KEYSYM_w, KEYSYM_x, + KEYSYM_y, KEYSYM_z, + + // 0x1E / 30 + KEYSYM_1, KEYSYM_2, + KEYSYM_3, KEYSYM_4, + KEYSYM_5, KEYSYM_6, + KEYSYM_7, KEYSYM_8, + KEYSYM_9, KEYSYM_0, + + KEYSYM_RETURN, // Enter + KEYSYM_ESC, // Esc. + KEYSYM_BACKSP, // Backspace + KEYSYM_TAB, // Tab + KEYSYM_SPACE, // Spacebar + KEYSYM_MINUS, // - _ + KEYSYM_EQUALS, // = + + KEYSYM_SQUARE_OPEN, // [ { + KEYSYM_SQUARE_CLOSE, // ] } + KEYSYM_BACKSLASH, // \ | + KEYSYM_HASH_TILDE, // # ~ (Non-US) + KEYSYM_SEMICOLON, // ; : + KEYSYM_QUOTE, // ' " + KEYSYM_GRAVE_TILDE, // Grave Accent, Tilde + KEYSYM_COMMA, // , < + KEYSYM_PERIOD, // . > + KEYSYM_SLASH, // / ? + KEYSYM_CAPS, // Caps Lock + KEYSYM_F1, KEYSYM_F2, + KEYSYM_F3, KEYSYM_F4, + KEYSYM_F5, KEYSYM_F6, + KEYSYM_F7, KEYSYM_F8, + KEYSYM_F9, KEYSYM_F10, + KEYSYM_F11, KEYSYM_F12, + KEYSYM_PRINTSCREEN, + KEYSYM_SCROLLLOCK, + KEYSYM_PAUSE, + KEYSYM_INSERT, + KEYSYM_HOME, + KEYSYM_PGUP, + KEYSYM_DELETE, + KEYSYM_END, + KEYSYM_PGDN, + KEYSYM_RIGHTARROW, + KEYSYM_LEFTARROW, + KEYSYM_DOWNARROW, + KEYSYM_UPARROW, + + KEYSYM_NUMLOCK, + KEYSYM_KPSLASH, + KEYSYM_KPSTAR, + KEYSYM_KPMINUS, + KEYSYM_KPPLUS, + KEYSYM_KPENTER, + KEYSYM_KP1, + KEYSYM_KP2, + KEYSYM_KP3, + KEYSYM_KP4, + KEYSYM_KP5, + KEYSYM_KP6, + KEYSYM_KP7, + KEYSYM_KP8, + KEYSYM_KP9, + KEYSYM_KP0, + KEYSYM_KPPERIOD, + + KEYSYM_NONUS_BACKSLASH, + KEYSYM_APPLICATION, // Windows Key + KEYSYM_POWER, + KEYSYM_KPEQUALS, + + KEYSYM_F13, KEYSYM_F14, + KEYSYM_F15, KEYSYM_F16, + KEYSYM_F17, KEYSYM_F18, + KEYSYM_F19, KEYSYM_F20, + KEYSYM_F21, KEYSYM_F22, + KEYSYM_F23, KEYSYM_F24, + KEYSYM_EXECUTE, + KEYSYM_HELP, + KEYSYM_MENU, + KEYSYM_SELECT, + KEYSYM_STOP, + KEYSYM_AGAIN, + KEYSYM_UNDO, + KEYSYM_CUT, + KEYSYM_COPY, + KEYSYM_PASTE, + KEYSYM_FIND, + KEYSYM_MUTE, + KEYSYM_VOLUP, + KEYSYM_VOLDN, + KEYSYM_LOCKING_CAPS, // Physically toggles + KEYSYM_LOGKING_NUM, + KEYSYM_LOGKING_SCROLL, + KEYSYM_KPCOMMA, + KEYSYM_KPEQUAL, + KEYSYM_KBINT1, + KEYSYM_KBINT2, + KEYSYM_KBINT3, + KEYSYM_KBINT4, + KEYSYM_KBINT5, + KEYSYM_KBINT6, + KEYSYM_KBINT7, + KEYSYM_KBINT8, + KEYSYM_KBINT9, + + KEYSYM_LEFTCTRL = 0xE0, + KEYSYM_LEFTSHIFT, + KEYSYM_LEFTALT, + KEYSYM_LEFTGUI, // Menu? + KEYSYM_RIGHTCTRL, + KEYSYM_RIGHTSHIFT, + KEYSYM_RIGHTALT, + KEYSYM_RIGHTGUI + + // TODO: Define the rest +}; + +#endif + diff --git a/KernelLand/Modules/Input/Keyboard/Makefile b/KernelLand/Modules/Input/Keyboard/Makefile new file mode 100644 index 00000000..d4764169 --- /dev/null +++ b/KernelLand/Modules/Input/Keyboard/Makefile @@ -0,0 +1,7 @@ +# +# + +OBJ = main.o +NAME = Keyboard + +-include ../Makefile.tpl diff --git a/KernelLand/Modules/Input/Keyboard/include/keyboard.h b/KernelLand/Modules/Input/Keyboard/include/keyboard.h new file mode 100644 index 00000000..c5753998 --- /dev/null +++ b/KernelLand/Modules/Input/Keyboard/include/keyboard.h @@ -0,0 +1,20 @@ +/* + * Acess2 Kernel - Keyboard mulitplexer/translation + * - By John Hodge (thePowersGang) + * + * keyboard.h + * - Interface header + */ +#ifndef _KEYBOARD__KEYBOARD_H_ +#define _KEYBOARD__KEYBAORD_H_ + +#include + +typedef struct sKeyboard tKeyboard; + +extern tKeyboard *Keyboard_CreateInstance(int MaxSym, const char *Ident); +extern void Keyboard_RemoveInstance(tKeyboard *Instance); +extern void Keyboard_HandleKey(tKeyboard *Source, Uint32 HIDKeySym); + +#endif + diff --git a/KernelLand/Modules/Input/Keyboard/keymap_int.h b/KernelLand/Modules/Input/Keyboard/keymap_int.h new file mode 100644 index 00000000..50da0baf --- /dev/null +++ b/KernelLand/Modules/Input/Keyboard/keymap_int.h @@ -0,0 +1,41 @@ +/* + * Acess2 Kernel - Keyboard Character Mappings + * - By John Hodge (thePowersGang) + * + * keymap.h + * - Core keymap "library" header + */ +#ifndef _KEYMAP__KEYMAP_INT_H_ +#define _KEYMAP__KEYMAP_INT_H_ + +typedef struct sKeymap tKeymap; +typedef struct sKeymapLayer tKeymapLayer; + +struct sKeymapLayer +{ + int nSyms; + Uint32 Sym[]; +}; + +struct sKeymap +{ + char *Name; + int nLayers; + tKeymapLayer *Layers[]; +}; + +struct sKeyboard +{ + struct sKeyboard *Next; + char *Name; + struct sVFS_Node *Node; + + tKeymap *Keymap; + + Uint32 State; + int MaxKeysym; + Uint8 KeyStates[]; +}; + +#endif + diff --git a/KernelLand/Modules/Input/Keyboard/layout_kbdus.h b/KernelLand/Modules/Input/Keyboard/layout_kbdus.h new file mode 100644 index 00000000..0809407e --- /dev/null +++ b/KernelLand/Modules/Input/Keyboard/layout_kbdus.h @@ -0,0 +1,46 @@ + +#ifndef _KEYMAP__LAYOUT_KBDUS_H_ +#define _KEYMAP__LAYOUT_KBDUS_H_ + +#include "keymap_int.h" + +// - Base (NO PREFIX) +tKeymapLayer gpKBDUS1 = { + KEYSYM_SLASH+1, + { + 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', '\x1b', '\b', '\t', ' ', '-', '=', '[', ']', '\\', '#', ';', + '\'', '`', ',', '.', '/', +// KEY_CAPSLOCK, +// KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, +// KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, +// 0, KEY_SCROLLLOCK, KEY_PAUSE, KEY_INS, KEY_HOME, KEY_PGUP, KEY_PGDOWN, +// KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN, +// KEY_NUMLOCK, KEY_KPSLASH, KEY_KPSTAR, KEY_KPMINUS, +// KEY_KPPLUS, KEY_KPENTER, +// KEY_KPEND, KEY_KPDOWN, KEY_KPLEFT, + } +}; +tKeymapLayer gpKBDUS1s = { + KEYSYM_SLASH+1, + { + 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', + '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', + '\n', '\x1b', '\b', '\t', ' ', '_', '+', '{', '}', '|', '~', ':', + '\'', '~', '<', '>', '?', + } +}; + +tKeymap gKeymap_KBDUS = { + "en-us", + 2, + {&gpKBDUS1, &gpKBDUS1s} +}; + +#endif + diff --git a/KernelLand/Modules/Input/Keyboard/main.c b/KernelLand/Modules/Input/Keyboard/main.c new file mode 100644 index 00000000..17c0f5fc --- /dev/null +++ b/KernelLand/Modules/Input/Keyboard/main.c @@ -0,0 +1,253 @@ +/* + * Acess2 Kernel - Keyboard Character Mappings + * - By John Hodge (thePowersGang) + * + * main.c + * - Core keyboard multiplexer + * + * TODO: Make the key transation code more general (for non-US layouts) + * TODO: Support multiple virtual keyboards + */ +#define DEBUG 0 +#define VERSION VER2(1,0) +#include +#include +#include +#include +#include "keymap_int.h" +#include "layout_kbdus.h" + +#define USE_KERNEL_MAGIC 1 + +// === IMPORTS === +#if USE_KERNEL_MAGIC +extern void Threads_ToggleTrace(int TID); +extern void Threads_Dump(void); +extern void Heap_Stats(void); +#endif + +// === PROTOTYPES === + int Keyboard_Install(char **Arguments); +void Keyboard_Cleanup(void); +// - Internal +tKeymap *Keyboard_LoadMap(const char *Name); +void Keyboard_FreeMap(tKeymap *Keymap); +// - User side + int Keyboard_IOCtl(tVFS_Node *Node, int ID, void *Data); +// - Device Side +tKeyboard *Keyboard_CreateInstance(int MaxSym, const char *Name); +void Keyboard_RemoveInstance(tKeyboard *Instance); +void Keyboard_HandleKey(tKeyboard *Source, Uint32 HIDKeySym); + +// === GLOBALS === +MODULE_DEFINE(0, VERSION, Keyboard, Keyboard_Install, Keyboard_Cleanup, NULL); +tVFS_NodeType gKB_NodeType = { + .IOCtl = Keyboard_IOCtl +}; +tDevFS_Driver gKB_DevInfo = { + NULL, "Keyboard", + { .Type = &gKB_NodeType } +}; +#if USE_KERNEL_MAGIC + int giKB_MagicAddress = 0; + int giKB_MagicAddressPos = 0; +#endif + +// === CODE === +int Keyboard_Install(char **Arguments) +{ + DevFS_AddDevice( &gKB_DevInfo ); + return 0; +} + +void Keyboard_Cleanup(void) +{ + // TODO: Do I need this? +} + +tKeymap *Keyboard_LoadMap(const char *Name) +{ + return NULL; +} + +void Keyboard_FreeMap(tKeymap *Keymap) +{ +} + +// --- VFS Interface --- +static const char *csaIOCTL_NAMES[] = {DRV_IOCTLNAMES, DRV_KEYBAORD_IOCTLNAMES, NULL}; +int Keyboard_IOCtl(tVFS_Node *Node, int Id, void *Data) +{ + switch(Id) + { + BASE_IOCTLS(DRV_TYPE_KEYBOARD, "Keyboard", 0x100, csaIOCTL_NAMES); + + case KB_IOCTL_SETCALLBACK: + if( Threads_GetUID() != 0 ) return -1; + if( MM_IsUser( (tVAddr)Data ) ) return -1; + if( Node->ImplInt ) return 0; // Can only be set once + Node->ImplInt = (Uint)Data; + return 1; + } + return -1; +} + +// --- Device Interface --- +tKeyboard *Keyboard_CreateInstance(int MaxSym, const char *Name) +{ + tKeyboard *ret; + int sym_bitmap_size = (MaxSym + 7)/8; + int string_size = strlen(Name) + 1; + + ret = malloc( sizeof(tKeyboard) + sym_bitmap_size + string_size ); + if( !ret ) { + return NULL; + } + // Clear + memset(ret, 0, sizeof(tKeyboard) + sym_bitmap_size ); + // Set name + ret->Name = (char*)ret + sizeof(tKeyboard) + sym_bitmap_size; + memcpy(ret->Name, Name, string_size); + // Set node and default keymap + ret->Node = &gKB_DevInfo.RootNode; + ret->Keymap = &gKeymap_KBDUS; + + return ret; +} + +void Keyboard_RemoveInstance(tKeyboard *Instance) +{ + // TODO: Implement + Log_Error("Keyboard", "TODO: Implement Keyboard_RemoveInstance"); +} + +void Keyboard_HandleKey(tKeyboard *Source, Uint32 HIDKeySym) +{ + int bPressed; + Uint32 trans; + Uint32 flag; + Uint8 layer; + + bPressed = !(HIDKeySym & (1 << 31)); + HIDKeySym &= 0x7FFFFFFF; + + // Determine action + { + Uint8 mask = 1 << (HIDKeySym&7); + int ofs = HIDKeySym / 8; + int oldstate = !!(Source->KeyStates[ofs] & mask); + + // Get the state of all other devices attached + int otherstate = 0; + for( tKeyboard *kb = Source->Node->ImplPtr; kb; kb = kb->Next ) + { + if( kb == Source ) continue ; + if( kb->MaxKeysym <= HIDKeySym ) continue ; + otherstate = otherstate || (kb->KeyStates[ofs] & mask); + } + + // Update key state + if( bPressed ) + Source->KeyStates[ ofs ] |= mask; + else + Source->KeyStates[ ofs ] &= ~mask; + + // Get the action (Press, Refire or Release) + if( bPressed ) + { + if( !oldstate && !otherstate ) + flag = KEY_ACTION_PRESS; // Down + else + flag = KEY_ACTION_REFIRE; // Refire + } + else + { + if( !otherstate ) + flag = KEY_ACTION_RELEASE; // Up + else + flag = -1 ; // Do nothing + } + } + + // Translate \a State into layer + // TODO: Support non-trivial layouts + layer = !!(Source->State & 3); + + // Send raw symbol + if( flag == KEY_ACTION_RELEASE ) + trans = 0; + else { + + // Translate the keysym into a character + if( layer >= Source->Keymap->nLayers ) + trans = 0; + else if( HIDKeySym >= Source->Keymap->Layers[layer]->nSyms ) + trans = 0; + else + trans = Source->Keymap->Layers[layer]->Sym[HIDKeySym]; + // - No translation in \a layer, fall back to layer=0 + if(!trans && HIDKeySym < Source->Keymap->Layers[0]->nSyms) + trans = Source->Keymap->Layers[0]->Sym[HIDKeySym]; + } + + if( flag != -1 ) + { + tKeybardCallback Callback = (void*)Source->Node->ImplInt; + Callback( HIDKeySym | KEY_ACTION_RAWSYM ); + Callback( flag | trans ); + } + + // TODO: Translate this into agnostic code + switch( HIDKeySym ) + { + case KEYSYM_LEFTSHIFT: + if(bPressed) Source->State |= 1; + else Source->State &= ~1; + break; + case KEYSYM_RIGHTSHIFT: + if(bPressed) Source->State |= 2; + else Source->State &= ~2; + break; + } + + // --- Check for Kernel Magic Combos + #if USE_KERNEL_MAGIC + if(Source->KeyStates[KEYSYM_LEFTCTRL/8] & (1 << (KEYSYM_LEFTCTRL&7)) + && Source->KeyStates[KEYSYM_LEFTALT/8] & (1 << (KEYSYM_LEFTALT &7)) ) + { + int val; + switch(trans) + { + case '0': val = 0; goto _av; case '1': val = 1; goto _av; + case '2': val = 2; goto _av; case '3': val = 3; goto _av; + case '4': val = 4; goto _av; case '5': val = 5; goto _av; + case '6': val = 6; goto _av; case '7': val = 7; goto _av; + case '8': val = 8; goto _av; case '9': val = 9; goto _av; + case 'a': val = 10; goto _av; case 'b': val = 11; goto _av; + case 'c': val = 12; goto _av; case 'd': val = 13; goto _av; + case 'e': val = 14; goto _av; case 'f': val = 15; goto _av; + _av: + if(giKB_MagicAddressPos == BITS/4) break; + giKB_MagicAddress |= (Uint)val << giKB_MagicAddressPos; + giKB_MagicAddressPos ++; + break; + + // Instruction Tracing + case 't': + Log("Toggle instruction tracing on %i\n", giKB_MagicAddress); + Threads_ToggleTrace( giKB_MagicAddress ); + giKB_MagicAddress = 0; giKB_MagicAddressPos = 0; + return; + + // Thread List Dump + case 'p': Threads_Dump(); return; + // Heap Statistics + case 'h': Heap_Stats(); return; + // Dump Structure + case 's': return; + } + } + #endif + +} + diff --git a/KernelLand/Modules/Input/PS2KbMouse/kb.c b/KernelLand/Modules/Input/PS2KbMouse/kb.c index a121b611..c0ead3a4 100644 --- a/KernelLand/Modules/Input/PS2KbMouse/kb.c +++ b/KernelLand/Modules/Input/PS2KbMouse/kb.c @@ -7,17 +7,13 @@ #include #include #include -#include "kb_kbdus.h" +#include +#include "kb_transtab.h" // === CONSTANTS === #define KB_BUFFER_SIZE 1024 #define USE_KERNEL_MAGIC 1 -// === IMPORTS === -extern void Threads_ToggleTrace(int TID); -extern void Threads_Dump(void); -extern void Heap_Stats(void); - // === PROTOTYPES === int KB_Install(char **Arguments); void KB_HandleScancode(Uint8 scancode); @@ -25,25 +21,9 @@ void KB_UpdateLEDs(void); int KB_IOCtl(tVFS_Node *Node, int Id, void *Data); // === GLOBALS === -tVFS_NodeType gKB_NodeType = { - .IOCtl = KB_IOCtl -}; -tDevFS_Driver gKB_DevInfo = { - NULL, "PS2Keyboard", - { .Type = &gKB_NodeType } -}; -tKeybardCallback gKB_Callback = NULL; -Uint32 **gpKB_Map = gpKBDUS; -Uint8 gbaKB_States[3][256]; - int gbKB_ShiftState = 0; - int gbKB_CapsState = 0; - int gbKB_KeyUp = 0; - int giKB_KeyLayer = 0; -#if USE_KERNEL_MAGIC - int gbKB_MagicState = 0; - int giKB_MagicAddress = 0; - int giKB_MagicAddressPos = 0; -#endif + int giPS2Kb_Layer; + int gbPS2Kb_KeyUp; +tKeyboard *gPS2Kb_Info; // === CODE === /** @@ -51,8 +31,7 @@ Uint8 gbaKB_States[3][256]; */ int KB_Install(char **Arguments) { - DevFS_AddDevice( &gKB_DevInfo ); - //Log("KB_Install: Installed"); + gPS2Kb_Info = Keyboard_CreateInstance(KEYSYM_RIGHTGUI, "PS2Keyboard"); return MODULE_ERR_OK; } @@ -62,151 +41,52 @@ int KB_Install(char **Arguments) */ void KB_HandleScancode(Uint8 scancode) { - Uint32 ch; - int bCaseSwitch = (gbKB_ShiftState != 0) != (gbKB_CapsState != 0); - - //Log_Debug("Keyboard", "scancode = %02x", scancode); + Uint32 hidcode; // Ignore ACKs - if(scancode == 0xFA) { - // Oh man! This is anarchic (I'm leaving it here to represent - // the mess that Acess once was) - //kb_lastChar = KB_ACK; - return; - } + if(scancode == 0xFA) return; - // Layer +1 + // Layer 1 if(scancode == 0xE0) { - giKB_KeyLayer = 1; + giPS2Kb_Layer = 1; return; } - // Layer +2 + // Layer 2 if(scancode == 0xE1) { - giKB_KeyLayer = 2; + giPS2Kb_Layer = 2; return; } #if KB_ALT_SCANCODES if(scancode == 0xF0) { - gbKB_KeyUp = 1; + gbPS2Kb_KeyUp = 1; return; } #else if(scancode & 0x80) { scancode &= 0x7F; - gbKB_KeyUp = 1; + gbPS2Kb_KeyUp = 1; } #endif - - if( gKB_Callback ) - gKB_Callback( (giKB_KeyLayer << 8) | scancode | KEY_ACTION_RAWSYM ); - - // Translate - ch = gpKB_Map[giKB_KeyLayer*2+bCaseSwitch][scancode]; - // - Unknown characters in the shift layer fall through to lower - if(bCaseSwitch && ch == 0) - ch = gpKB_Map[giKB_KeyLayer*2][scancode]; - // Check for unknown key - if(!ch) - { - if(!gbKB_KeyUp) - Log_Warning("Keyboard", "UNK %i %x", giKB_KeyLayer, scancode); -// return ; - // Can pass through to ensure each raw message has a up/down with it - } - - // Key Up? - if (gbKB_KeyUp) - { - gbKB_KeyUp = 0; - gbaKB_States[giKB_KeyLayer][scancode] = 0; // Unset key state flag - - #if USE_KERNEL_MAGIC - if(ch == KEY_LCTRL) gbKB_MagicState &= ~1; - if(ch == KEY_LALT) gbKB_MagicState &= ~2; - #endif - - if(ch == KEY_LSHIFT) gbKB_ShiftState &= ~1; - if(ch == KEY_RSHIFT) gbKB_ShiftState &= ~2; - // Call callback - if(gKB_Callback) gKB_Callback( ch | KEY_ACTION_RELEASE ); - - // Reset Layer - giKB_KeyLayer = 0; - return; - } - - // Refire? - if( gbaKB_States[giKB_KeyLayer][scancode] == 1 ) + hidcode = gp101_to_HID[giPS2Kb_Layer][scancode]; + if( !hidcode ) { - if(gKB_Callback) gKB_Callback(ch | KEY_ACTION_REFIRE); - giKB_KeyLayer = 0; + Log_Warning("PS2Kb", "Unknown scancode %i:0x%x", giPS2Kb_Layer, scancode); return ; } - - // Set the bit relating to the key - gbaKB_States[giKB_KeyLayer][scancode] = 1; - // Set shift key bits - if(ch == KEY_LSHIFT) gbKB_ShiftState |= 1; - if(ch == KEY_RSHIFT) gbKB_ShiftState |= 2; - - // Check for Caps Lock - if(ch == KEY_CAPSLOCK) { - gbKB_CapsState = !gbKB_CapsState; - KB_UpdateLEDs(); - } - - // --- Check for Kernel Magic Combos - #if USE_KERNEL_MAGIC - if(ch == KEY_LCTRL) { - gbKB_MagicState |= 1; - //Log_Log("Keyboard", "Kernel Magic LCTRL Down\n"); - } - if(ch == KEY_LALT) { - gbKB_MagicState |= 2; - //Log_Log("Keyboard", "Kernel Magic LALT Down\n"); - } - if(gbKB_MagicState == 3) + else { - switch(ch) - { - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - case '8': case '9': case 'a': case 'b': - case 'c': case 'd': case 'e': case 'f': - { - char str[4] = {'0', 'x', ch, 0}; - if(giKB_MagicAddressPos == BITS/4) return; - giKB_MagicAddress |= atoi(str) << giKB_MagicAddressPos; - giKB_MagicAddressPos ++; - } - return; - - // Instruction Tracing - case 't': - Log("Toggle instruction tracing on %i\n", giKB_MagicAddress); - Threads_ToggleTrace( giKB_MagicAddress ); - giKB_MagicAddress = 0; giKB_MagicAddressPos = 0; - return; - - // Thread List Dump - case 'p': Threads_Dump(); return; - // Heap Statistics - case 'h': Heap_Stats(); return; - // Dump Structure - case 's': return; - } + if( gbPS2Kb_KeyUp ) + Keyboard_HandleKey( gPS2Kb_Info, (1 << 31) | hidcode ); + else + Keyboard_HandleKey( gPS2Kb_Info, (0 << 31) | hidcode ); } - #endif - - if(gKB_Callback) - gKB_Callback(ch | KEY_ACTION_PRESS); - - // Reset Layer - giKB_KeyLayer = 0; + + giPS2Kb_Layer = 0; + gbPS2Kb_KeyUp = 0; } /** @@ -215,37 +95,11 @@ void KB_HandleScancode(Uint8 scancode) */ void KB_UpdateLEDs(void) { - Uint8 leds; +// Uint8 leds; - leds = (gbKB_CapsState ? 4 : 0); +// leds = (gbKB_CapsState ? 4 : 0); // TODO: Update LEDS Log_Warning("Keyboard", "TODO: Update LEDs"); } -static const char *csaIOCTL_NAMES[] = {DRV_IOCTLNAMES, DRV_KEYBAORD_IOCTLNAMES, NULL}; - -/** - * \fn int KB_IOCtl(tVFS_Node *Node, int Id, void *Data) - * \brief Calls an IOCtl Command - */ -int KB_IOCtl(tVFS_Node *Node, int Id, void *Data) -{ - switch(Id) - { - BASE_IOCTLS(DRV_TYPE_KEYBOARD, "KB", 0x100, csaIOCTL_NAMES); - - // Sets the Keyboard Callback - case KB_IOCTL_SETCALLBACK: - // Sanity Check - if((Uint)Data < KERNEL_BASE) return 0; - // Can only be set once - if(gKB_Callback != NULL) return 0; - // Set Callback - gKB_Callback = Data; - return 1; - - default: - return 0; - } -} diff --git a/KernelLand/Modules/Input/PS2KbMouse/kb_kbdus.h b/KernelLand/Modules/Input/PS2KbMouse/kb_kbdus.h deleted file mode 100644 index 5df32573..00000000 --- a/KernelLand/Modules/Input/PS2KbMouse/kb_kbdus.h +++ /dev/null @@ -1,61 +0,0 @@ - -#ifndef _KBDUS_H -#define _KBDUS_H - -// - Base (NO PREFIX) -Uint32 gpKBDUS1[256] = { - 0, - KEY_ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', // 0x01 - 0x0e - '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', // 0x0f - 0x1c - KEY_LCTRL, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';','\'', // 0x1d - 0x28 - '`', KEY_LSHIFT,'\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', KEY_RSHIFT, // 0x29 - 0x3e - KEY_KPSTAR, - KEY_LALT, ' ', KEY_CAPSLOCK, - KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, - KEY_NUMLOCK, KEY_SCROLLLOCK, - KEY_KPHOME, KEY_KPUP, KEY_KPPGUP, KEY_KPMINUS, - KEY_KPLEFT, KEY_KP5, KEY_KPRIGHT, KEY_KPPLUS, - KEY_KPEND, KEY_KPDOWN, KEY_KPPGDN, - KEY_KPINS, KEY_KPDEL, - 0, 0, 0, KEY_F11, KEY_F12, 0, 0, 0, 0, 0, 0, 0, -/*60*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*70*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; -// Shift Key pressed -Uint32 gpKBDUS1s[256] = { - 0, - KEY_ESC, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\b', // 0x01 - 0x0e - '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', // 0x0f - 0x1c - KEY_LCTRL, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':','"', // 0x1d - 0x28 - '~', KEY_LSHIFT,'|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', KEY_RSHIFT, // 0x29 - 0x3e - 0 - }; -// - 0xE0 Prefixed -Uint32 gpKBDUS2[256] = { -// 0 1 2 3 4 5 6 7 8 9 A B C D E F -/*00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0-F -/*10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_KPENTER, KEY_RCTRL, 0, 0, -/*20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*30*/ 0, 0, 0, 0, 0, KEY_KPSLASH, 0, 0, KEY_RALT, 0, 0, 0, 0, 0, 0, 0, -/*40*/ 0, 0, 0, 0, 0, 0, 0, KEY_HOME, KEY_UP, KEY_PGUP, 0, KEY_LEFT, 0, KEY_RIGHT, 0, KEY_END, -/*50*/ KEY_DOWN, KEY_PGDOWN, KEY_INS, KEY_DEL, 0, 0, 0, 0, 0, 0, 0, KEY_LWIN, KEY_RWIN, KEY_MENU, 0, 0, -/*60*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*70*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; -// - 0xE1 Prefixed -Uint32 gpKBDUS3[256] = { -// 0 1 2 3 4 5 6 7 8 9 A B C D E F -/*00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0-F -/*10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_PAUSE, 0, 0, -/*20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*30*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*40*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*50*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*60*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*70*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; - - -Uint32 *gpKBDUS[6] = { gpKBDUS1, gpKBDUS1s, gpKBDUS2, gpKBDUS2, gpKBDUS3, gpKBDUS3 }; - -#endif diff --git a/KernelLand/Modules/Input/PS2KbMouse/kb_transtab.h b/KernelLand/Modules/Input/PS2KbMouse/kb_transtab.h new file mode 100644 index 00000000..7ae82103 --- /dev/null +++ b/KernelLand/Modules/Input/PS2KbMouse/kb_transtab.h @@ -0,0 +1,68 @@ + +#ifndef _KBDUS_H +#define _KBDUS_H + +// - Base (NO PREFIX) +Uint32 gp101_to_HID_1[128] = { + 0, + // First row (0x01 - 0x0e) + KEYSYM_ESC, KEYSYM_1, KEYSYM_2, KEYSYM_3, KEYSYM_4, KEYSYM_5, KEYSYM_6, + KEYSYM_7, KEYSYM_8, KEYSYM_9, KEYSYM_0, KEYSYM_MINUS, KEYSYM_EQUALS, + KEYSYM_BACKSP, + // Second Row (0x0f - 0x1c) + KEYSYM_TAB, KEYSYM_q, KEYSYM_w, KEYSYM_e, KEYSYM_r, KEYSYM_t, KEYSYM_y, + KEYSYM_u, KEYSYM_i, KEYSYM_o, KEYSYM_p, KEYSYM_SQUARE_OPEN, KEYSYM_SQUARE_CLOSE, + KEYSYM_RETURN, + // Third Row (0x1d - 0x28) + KEYSYM_LEFTCTRL, KEYSYM_a, KEYSYM_s, KEYSYM_d, KEYSYM_f, KEYSYM_g, KEYSYM_h, + KEYSYM_j, KEYSYM_k, KEYSYM_l, KEYSYM_SEMICOLON, KEYSYM_QUOTE, // 0x1d - 0x28 + // Fourth Row (0x20 - 0x3e) + KEYSYM_GRAVE_TILDE, KEYSYM_LEFTSHIFT, KEYSYM_BACKSLASH, KEYSYM_z, KEYSYM_x, + KEYSYM_c, KEYSYM_v, KEYSYM_b, KEYSYM_n, KEYSYM_m, KEYSYM_COMMA, KEYSYM_PERIOD, + KEYSYM_SLASH, KEYSYM_RIGHTSHIFT, + // Bottom row (0x3f - 0x42) + KEYSYM_KPSTAR, KEYSYM_LEFTALT, KEYSYM_SPACE, KEYSYM_CAPS, + // F Keys (0x43 - 0x4d) + KEYSYM_F1, KEYSYM_F2, KEYSYM_F3, KEYSYM_F4, KEYSYM_F5, + KEYSYM_F6, KEYSYM_F7, KEYSYM_F8, KEYSYM_F9, KEYSYM_F10, + // Keypad + KEYSYM_NUMLOCK, KEYSYM_SCROLLLOCK, + KEYSYM_KP7, KEYSYM_KP8, KEYSYM_KP9, KEYSYM_KPMINUS, + KEYSYM_KP4, KEYSYM_KP5, KEYSYM_KP6, KEYSYM_KPPLUS, + KEYSYM_KP1, KEYSYM_KP2, KEYSYM_KP3, + KEYSYM_KP0, KEYSYM_KPPERIOD, + 0, 0, 0, KEYSYM_F11, KEYSYM_F12, 0, 0, 0, 0, 0, 0, 0, +/*60*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*70*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; +// - 0xE0 Prefixed +Uint32 gp101_to_HID_2[128] = { +// 0 1 2 3 4 5 6 7 8 9 A B C D E F +/*00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0-F +/*10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEYSYM_KPENTER, KEYSYM_RIGHTCTRL, 0, 0, +/*20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*30*/ 0, 0, 0, 0, 0, KEYSYM_KPSLASH, 0, 0, KEYSYM_RIGHTALT, 0, 0, 0, 0, 0, 0, 0, +/*40*/ 0, 0, 0, 0, 0, 0, 0, KEYSYM_HOME, + KEYSYM_UPARROW, KEYSYM_PGUP, 0, KEYSYM_LEFTARROW, 0, KEYSYM_RIGHTARROW, 0, KEYSYM_END, +/*50*/ KEYSYM_DOWNARROW, KEYSYM_PGDN, KEYSYM_INSERT, KEYSYM_DELETE, 0, 0, 0, 0, + 0, 0, 0, KEYSYM_LEFTGUI, KEYSYM_RIGHTGUI, KEYSYM_APPLICATION, 0, 0, +/*60*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*70*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; +// - 0xE1 Prefixed +Uint32 gp101_to_HID_3[128] = { +// 0 1 2 3 4 5 6 7 8 9 A B C D E F +/*00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0-F +/*10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEYSYM_PAUSE, 0, 0, +/*20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*30*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*40*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*50*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*60*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*70*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + + +Uint32 *gp101_to_HID[3] = { gp101_to_HID_1, gp101_to_HID_2, gp101_to_HID_3 }; + +#endif diff --git a/KernelLand/Modules/Input/PS2KbMouse/main.c b/KernelLand/Modules/Input/PS2KbMouse/main.c index c5ad4e8b..ae51f81c 100644 --- a/KernelLand/Modules/Input/PS2KbMouse/main.c +++ b/KernelLand/Modules/Input/PS2KbMouse/main.c @@ -30,7 +30,7 @@ // === GLOBALS === MODULE_DEFINE(0, 0x0100, Input_PS2KbMouse, PS2_Install, NULL, NULL); // Shuts the makefile up -MODULE_DEFINE(0, 0x0100, PS2Keyboard, KB_Install, NULL, "Input_PS2KbMouse", NULL); +MODULE_DEFINE(0, 0x0100, PS2Keyboard, KB_Install, NULL, "Input_PS2KbMouse", "Keyboard", NULL); MODULE_DEFINE(0, 0x0100, PS2Mouse, PS2Mouse_Install, NULL, "Input_PS2KbMouse", NULL); // === CODE === diff --git a/KernelLand/Modules/Makefile.tpl b/KernelLand/Modules/Makefile.tpl index e2ef60a2..e365e99d 100644 --- a/KernelLand/Modules/Makefile.tpl +++ b/KernelLand/Modules/Makefile.tpl @@ -10,6 +10,7 @@ LIBINCLUDES := $(addprefix -I$(ACESSDIR)/KernelLand/Modules/,$(DEPS)) LIBINCLUDES := $(addsuffix /include,$(LIBINCLUDES)) CPPFLAGS := -I$(ACESSDIR)/KernelLand/Kernel/include -I$(ACESSDIR)/KernelLand/Kernel/arch/$(ARCHDIR)/include +CPPFLAGS += -I$(ACESSDIR)/KernelLand/Modules CPPFLAGS += -DARCH=$(ARCH) -DARCH_is_$(ARCH) -DARCHDIR_is_$(ARCHDIR) CPPFLAGS += $(_CPPFLAGS) CPPFLAGS += $(LIBINCLUDES) diff --git a/KernelLand/Modules/USB/HID/keysyms.h b/KernelLand/Modules/USB/HID/keysyms.h deleted file mode 100644 index 558464e5..00000000 --- a/KernelLand/Modules/USB/HID/keysyms.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Acess2 USB Stack HID Driver - * - By John Hodge (thePowersGang) - * - * usb_keysyms.h - * - USB HID Keyboard Symbols - */ -#ifndef _USB_KEYSYMS_H_ -#define _USB_KEYSYMS_H_ - -enum eUSB_Keysyms -{ - KEYSYM_NONE, - KEYSYM_ERRORROLLOVER, - KEYSYM_POSTFAIL, - KEYSYM_ERRORUNDEFINED, - // 0x04 / 4 - KEYSYM_a, KEYSYM_b, KEYSYM_c, - KEYSYM_d, KEYSYM_e, KEYSYM_f, - KEYSYM_g, KEYSYM_h, KEYSYM_i, - KEYSYM_j, KEYSYM_k, KEYSYM_l, - KEYSYM_m, KEYSYM_n, KEYSYM_o, - KEYSYM_p, KEYSYM_q, KEYSYM_r, - KEYSYM_s, KEYSYM_t, KEYSYM_u, - KEYSYM_v, KEYSYM_w, KEYSYM_x, - KEYSYM_y, KEYSYM_z, - - // 0x1E / 30 - KEYSYM_1, KEYSYM_2, - KEYSYM_3, KEYSYM_4, - KEYSYM_5, KEYSYM_6, - KEYSYM_7, KEYSYM_8, - KEYSYM_9, KEYSYM_0, - - KEYSYM_RETURN, // Enter - KEYSYM_ESC, // Esc. - KEYSYM_BACKSP, // Backspace - KEYSYM_TAB, // Tab - KEYSYM_SPACE, // Spacebar - KEYSYM_MINUS, // - _ - KEYSYM_EQUALS, // = + - KEYSYM_SQUARE_OPEN, // [ { - KEYSYM_SQUARE_CLOSE, // ] } - KEYSYM_BACKSLASH, // \ | - KEYSYM_HASH_TILDE, // # ~ (Non-US) - KEYSYM_SEMICOLON, // ; : - KEYSYM_QUOTE, // ' " - KEYSYM_GRAVE_TILDE, // Grave Accent, Tilde - KEYSYM_COMMA, // , < - KEYSYM_PERIOD, // . > - KEYSYM_SLASH, // / ? - KEYSYM_CAPS, // Caps Lock - KEYSYM_F1, KEYSYM_F2, - KEYSYM_F3, KEYSYM_F4, - KEYSYM_F5, KEYSYM_F6, - KEYSYM_F7, KEYSYM_F8, - KEYSYM_F9, KEYSYM_F10, - KEYSYM_F11, KEYSYM_F12, - KEYSYM_PRINTSCREEN, - KEYSYM_SCROLLLOCK, - KEYSYM_PAUSE, - KEYSYM_INSERT, - KEYSYM_HOME, - KEYSYM_PGUP, - KEYSYM_DELETE, - KEYSYM_END, - KEYSYM_PGDN, - KEYSYM_RIGHTARROW, - KEYSYM_LEFTARROW, - KEYSYM_DOWNARROW, - KEYSYM_UPARROW, - - KEYSYM_NUMLOCK, - KEYSYM_KPSLASH, - KEYSYM_KPSTAR, - KEYSYM_KPMINUS, - KEYSYM_KPPLUS, - KEYSYM_KPENTER, - KEYSYM_KP1, - KEYSYM_KP2, - KEYSYM_KP3, - KEYSYM_KP4, - KEYSYM_KP5, - KEYSYM_KP7, - KEYSYM_KP8, - KEYSYM_KP9 - KEYSYM_KP0, - KEYSYM_KPPERIOD, - - KEYSYM_NONUS_BACKSLASH, - KEYSYM_APPLICATION, // Windows Key - KEYSYM_POWER, - KEYSYM_KPEQUALS, - - KEYSYM_F13, KEYSYM_F14, - KEYSYM_F15, KEYSYM_F16, - KEYSYM_F17, KEYSYM_F18, - KEYSYM_F19, KEYSYM_F20, - KEYSYM_F21, KEYSYM_F22, - KEYSYM_F23, KEYSYM_F24, - KEYSYM_EXECUTE, - KEYSYM_HELP, - KEYSYM_MENU, - KEYSYM_SELECT, - KEYSYM_STOP, - KEYSYM_AGAIN, - KEYSYM_UNDO, - KEYSYM_CUT, - KEYSYM_COPY, - KEYSYM_PASTE, - KEYSYM_FIND, - KEYSYM_MUTE, - KEYSYM_VOLUP, - KEYSYM_VOLDN, - KEYSYM_LOCKING_CAPS, // Physically toggles - KEYSYM_LOGKING_NUM, - KEYSYM_LOGKING_SCROLL, - KEYSYM_KPCOMMA - - // TODO: Define the rest -}; - -#endif - diff --git a/Makefile.cfg b/Makefile.cfg index 2642f5a5..0df599c0 100644 --- a/Makefile.cfg +++ b/Makefile.cfg @@ -58,6 +58,7 @@ MODULES += Storage/LVM include $(ACESSDIR)/BuildConf/$(ARCH)/$(PLATFORM).mk +MODULES += Input/Keyboard MODULES += IPStack # So the other modules are loaded before it #DYNMODS := USB/Core #DYNMODS += Filesystems/InitRD