Kernel - Split key translation out of PS2Keyboard
[tpg/acess2.git] / KernelLand / Modules / Input / PS2KbMouse / kb.c
1 /*
2  * Acess2
3  * PS2 Keyboard Driver
4  */
5 #include <acess.h>
6 #include <modules.h>
7 #include <fs_devfs.h>
8 #include <api_drv_common.h>
9 #include <api_drv_keyboard.h>
10 #include <Input/Keyboard/include/keyboard.h>
11 #include "kb_transtab.h"
12
13 // === CONSTANTS ===
14 #define KB_BUFFER_SIZE  1024
15 #define USE_KERNEL_MAGIC        1
16
17 // === PROTOTYPES ===
18  int    KB_Install(char **Arguments);
19 void    KB_HandleScancode(Uint8 scancode);
20 void    KB_UpdateLEDs(void);
21  int    KB_IOCtl(tVFS_Node *Node, int Id, void *Data);
22
23 // === GLOBALS ===
24  int    giPS2Kb_Layer;
25  int    gbPS2Kb_KeyUp;
26 tKeyboard       *gPS2Kb_Info;
27
28 // === CODE ===
29 /**
30  * \brief Install the keyboard driver
31  */
32 int KB_Install(char **Arguments)
33 {
34         gPS2Kb_Info = Keyboard_CreateInstance(KEYSYM_RIGHTGUI, "PS2Keyboard");
35         return MODULE_ERR_OK;
36 }
37
38 /**
39  * \brief Called on a keyboard IRQ
40  * \param IRQNum        IRQ number (unused)
41  */
42 void KB_HandleScancode(Uint8 scancode)
43 {
44         Uint32  hidcode;
45
46         // Ignore ACKs
47         if(scancode == 0xFA) return;
48
49         // Layer 1
50         if(scancode == 0xE0) {
51                 giPS2Kb_Layer = 1;
52                 return;
53         }
54         // Layer 2
55         if(scancode == 0xE1) {
56                 giPS2Kb_Layer = 2;
57                 return;
58         }
59
60         #if KB_ALT_SCANCODES
61         if(scancode == 0xF0)
62         {
63                 gbPS2Kb_KeyUp = 1;
64                 return;
65         }
66         #else
67         if(scancode & 0x80)
68         {
69                 scancode &= 0x7F;
70                 gbPS2Kb_KeyUp = 1;
71         }
72         #endif
73
74         hidcode = gp101_to_HID[giPS2Kb_Layer][scancode];
75         if( !hidcode )
76         {
77                 Log_Warning("PS2Kb", "Unknown scancode %i:0x%x", giPS2Kb_Layer, scancode);
78                 return ;
79         }
80         else
81         {
82                 if( gbPS2Kb_KeyUp )
83                         Keyboard_HandleKey( gPS2Kb_Info, (1 << 31) | hidcode );
84                 else
85                         Keyboard_HandleKey( gPS2Kb_Info, (0 << 31) | hidcode );
86         }
87         
88         giPS2Kb_Layer = 0;
89         gbPS2Kb_KeyUp = 0;
90 }
91
92 /**
93  * \fn void KB_UpdateLEDs(void)
94  * \brief Updates the status of the keyboard LEDs
95  */
96 void KB_UpdateLEDs(void)
97 {
98 //      Uint8   leds;
99
100 //      leds = (gbKB_CapsState ? 4 : 0);
101
102         // TODO: Update LEDS
103         Log_Warning("Keyboard", "TODO: Update LEDs");
104 }
105

UCC git Repository :: git.ucc.asn.au