revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-linux / hidd / linuxinput / kbdclass.c
blobc6c5f92d92152c1644329ce13a53e97b2cc2057d
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Linux hidd handling keyboard events.
6 Lang: English.
7 */
9 #define __OOP_NOATTRBASES__
11 #include <dos/dos.h>
13 #include <proto/utility.h>
14 #include <proto/oop.h>
15 #include <proto/dos.h>
16 #include <oop/oop.h>
18 #include <hidd/hidd.h>
19 #include <hidd/keyboard.h>
20 #include <devices/inputevent.h>
21 #include <devices/rawkeycodes.h>
23 #include <aros/symbolsets.h>
25 #include "linuxinput_intern.h"
27 #include LC_LIBDEFS_FILE
29 #define DEBUG 0
30 #include <aros/debug.h>
32 static UBYTE scancode2rawkey[256];
33 static BOOL havetable = FALSE;
35 static UWORD scancode2hidd(UBYTE scancode, struct LinuxInput_staticdata *lsd);
37 /***** Kbd::New() ***************************************/
38 OOP_Object * LinuxKbd__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
40 BOOL has_kbd_hidd = FALSE;
41 struct TagItem *tag, *tstate;
42 APTR callback = NULL;
43 APTR callbackdata = NULL;
45 EnterFunc(bug("[LinuxInput] Kbd::New()\n"));
47 ObtainSemaphore(&LSD(cl)->sema);
48 if (LSD(cl)->kbdhidd)
49 has_kbd_hidd = TRUE;
50 ReleaseSemaphore(&LSD(cl)->sema);
52 if (has_kbd_hidd) /* Cannot open twice */
53 ReturnPtr("[LinuxInput] Kbd::New", OOP_Object *, NULL); /* Should have some error code here */
55 tstate = msg->attrList;
56 D(bug("[LinuxInput] tstate: %p, tag=%x\n", tstate, tstate->ti_Tag));
57 while ((tag = NextTagItem((struct TagItem **)&tstate)))
59 ULONG idx;
61 D(bug("[LinuxInput] Got tag %d, data %x\n", tag->ti_Tag, tag->ti_Data));
63 if (IS_HIDDKBD_ATTR(tag->ti_Tag, idx))
65 D(bug("[LinuxInput] Kbd hidd tag\n"));
66 switch (idx)
68 case aoHidd_Kbd_IrqHandler:
69 callback = (APTR)tag->ti_Data;
70 D(bug("Got callback %p\n", (APTR)tag->ti_Data));
71 break;
73 case aoHidd_Kbd_IrqHandlerData:
74 callbackdata = (APTR)tag->ti_Data;
75 D(bug("Got data %p\n", (APTR)tag->ti_Data));
76 break;
80 } /* while (tags to process) */
82 if (NULL == callback)
83 ReturnPtr("[LinuxInput] Kbd::New", OOP_Object *, NULL); /* Should have some error code here */
85 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
86 if (o)
88 struct LinuxKbd_data *data = OOP_INST_DATA(cl, o);
90 data->kbd_callback = (VOID (*)(APTR, UWORD))callback;
91 data->callbackdata = callbackdata;
93 ObtainSemaphore(&LSD(cl)->sema);
94 LSD(cl)->kbdhidd = o;
95 Update_EventHandlers(LSD(cl));
96 ReleaseSemaphore(&LSD(cl)->sema);
99 ReturnPtr("[LinuxInput] Kbd::New", OOP_Object *, o);
103 VOID LinuxKbd__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
105 ObtainSemaphore(&LSD(cl)->sema);
106 LSD(cl)->kbdhidd = NULL;
107 Update_EventHandlers(LSD(cl));
108 ReleaseSemaphore(&LSD(cl)->sema);
110 OOP_DoSuperMethod(cl, o, msg);
113 /***** LinuxKbd::HandleEvent() ***************************************/
115 VOID LinuxKbd__Hidd_LinuxKbd__HandleEvent(OOP_Class *cl, OOP_Object *o, struct pHidd_LinuxKbd_HandleEvent *msg)
117 struct LinuxKbd_data *data;
118 UBYTE scancode;
119 UWORD hiddcode;
121 EnterFunc(bug("[LinuxInput] linuxkbd_handleevent()\n"));
123 data = OOP_INST_DATA(cl, o);
125 scancode = msg->scanCode;
126 hiddcode = scancode2hidd(scancode, LSD(cl));
128 if (hiddcode != 0xFF)
130 if (scancode >= 0x80)
131 hiddcode |= IECODE_UP_PREFIX;
133 data->kbd_callback(data->callbackdata, hiddcode);
136 ReturnVoid("[LinuxInput] Kbd::HandleEvent");
140 #undef LSD
141 #define LSD(cl) lsd
143 /**************** scancode2hidd() ****************/
144 #define DEF_TAB_SIZE 128
146 const UBYTE deftable[] =
148 0xff,
149 RAWKEY_ESCAPE,
150 RAWKEY_1,
151 RAWKEY_2,
152 RAWKEY_3,
153 RAWKEY_4,
154 RAWKEY_5,
155 RAWKEY_6,
156 RAWKEY_7,
157 RAWKEY_8,
158 RAWKEY_9,
159 RAWKEY_0,
160 RAWKEY_MINUS,
161 RAWKEY_EQUAL,
162 RAWKEY_BACKSPACE,
163 RAWKEY_TAB,
164 RAWKEY_Q,
165 RAWKEY_W,
166 RAWKEY_E,
167 RAWKEY_R,
168 RAWKEY_T,
169 RAWKEY_Y,
170 RAWKEY_U,
171 RAWKEY_I,
172 RAWKEY_O,
173 RAWKEY_P,
174 RAWKEY_LBRACKET,
175 RAWKEY_RBRACKET,
176 RAWKEY_RETURN,
177 RAWKEY_CONTROL,
178 RAWKEY_A,
179 RAWKEY_S,
180 RAWKEY_D,
181 RAWKEY_F,
182 RAWKEY_G,
183 RAWKEY_H,
184 RAWKEY_J,
185 RAWKEY_K,
186 RAWKEY_L,
187 RAWKEY_SEMICOLON,
188 RAWKEY_QUOTE,
189 RAWKEY_TILDE,
190 RAWKEY_LSHIFT,
191 RAWKEY_2B,
192 RAWKEY_Z,
193 RAWKEY_X,
194 RAWKEY_C,
195 RAWKEY_V,
196 RAWKEY_B,
197 RAWKEY_N,
198 RAWKEY_M,
199 RAWKEY_COMMA,
200 RAWKEY_PERIOD,
201 RAWKEY_SLASH,
202 RAWKEY_RSHIFT,
203 0x5C,
204 RAWKEY_LALT,
205 RAWKEY_SPACE,
206 RAWKEY_CAPSLOCK,
207 RAWKEY_F1,
208 RAWKEY_F2,
209 RAWKEY_F3,
210 RAWKEY_F4,
211 RAWKEY_F5,
212 RAWKEY_F6,
213 RAWKEY_F7,
214 RAWKEY_F8,
215 RAWKEY_F9,
216 RAWKEY_F10,
217 0x5A,
218 0xff,
219 RAWKEY_KP_7,
220 RAWKEY_KP_8,
221 RAWKEY_KP_9,
222 0x5D,
223 RAWKEY_KP_4,
224 RAWKEY_KP_5,
225 RAWKEY_KP_6,
226 RAWKEY_KP_PLUS,
227 RAWKEY_KP_1,
228 RAWKEY_KP_2,
229 RAWKEY_KP_3,
230 RAWKEY_KP_0,
231 RAWKEY_KP_DECIMAL,
232 0xff,
233 0xff,
234 RAWKEY_LESSGREATER,
235 RAWKEY_F11,
236 RAWKEY_F12,
237 0xff,
238 0xff,
239 0xff,
240 0xff,
241 0xff,
242 0xff,
243 0xff,
244 RAWKEY_KP_ENTER,
245 RAWKEY_CONTROL,
246 0x5B,
247 0xff,
248 RAWKEY_RALT,
249 RAWKEY_PAUSE,
250 RAWKEY_HOME,
251 RAWKEY_UP,
252 RAWKEY_PAGEUP,
253 RAWKEY_LEFT,
254 RAWKEY_RIGHT,
255 RAWKEY_END,
256 RAWKEY_DOWN,
257 RAWKEY_PAGEDOWN,
258 RAWKEY_INSERT,
259 RAWKEY_DELETE,
260 0xff,
261 0xff,
262 0xff,
263 0xff,
264 0xff,
265 0xff,
266 0xff,
267 RAWKEY_PAUSE,
268 0xff,
269 0xff,
270 0xff,
271 0xff,
272 0xff,
273 RAWKEY_LAMIGA,
274 RAWKEY_RAMIGA,
275 0xff
277 static UWORD scancode2hidd(UBYTE scancode, struct LinuxInput_staticdata *lsd)
279 UWORD hiddcode;
281 if ((scancode & 0x80) == 0x80)
282 scancode &= ~0x80;
284 if (havetable)
286 hiddcode = scancode2rawkey[scancode];
288 else
290 if (scancode >= DEF_TAB_SIZE)
291 hiddcode = 0xFF;
292 else
293 hiddcode = deftable[scancode];
296 return hiddcode;
299 VOID HIDD_LinuxKbd_HandleEvent(OOP_Object *o, UBYTE scanCode)
301 static OOP_MethodID mid;
302 struct pHidd_LinuxKbd_HandleEvent p;
304 if (!mid)
305 mid = OOP_GetMethodID(IID_Hidd_LinuxKbd, moHidd_LinuxKbd_HandleEvent);
307 p.mID = mid;
308 p.scanCode = scanCode;
310 OOP_DoMethod(o, (OOP_Msg)&p);