(minor) Modules/UDI - Improved error message for multiple UDI_DL_BUF
[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 == 0)
76         {
77                 Log_Warning("PS2Kb", "Unknown scancode %i:0x%x %s", giPS2Kb_Layer, scancode,
78                         gbPS2Kb_KeyUp ? "release" : "press"
79                         );
80         }
81         else if( hidcode == -1 )
82         {
83                 // Ignored (Fake shift)
84         }
85         else
86         {
87                 if( gbPS2Kb_KeyUp )
88                         Keyboard_HandleKey( gPS2Kb_Info, (1 << 31) | hidcode );
89                 else
90                         Keyboard_HandleKey( gPS2Kb_Info, (0 << 31) | hidcode );
91         }
92         
93         giPS2Kb_Layer = 0;
94         gbPS2Kb_KeyUp = 0;
95 }
96
97 /**
98  * \fn void KB_UpdateLEDs(void)
99  * \brief Updates the status of the keyboard LEDs
100  */
101 void KB_UpdateLEDs(void)
102 {
103 //      Uint8   leds;
104
105 //      leds = (gbKB_CapsState ? 4 : 0);
106
107         // TODO: Update LEDS
108         Log_Warning("Keyboard", "TODO: Update LEDs");
109 }
110

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