2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 Desc: Linux hidd handling keyboard events.
9 #define __OOP_NOATTRBASES__
13 #include <proto/utility.h>
14 #include <proto/oop.h>
15 #include <proto/dos.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
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
;
43 APTR callbackdata
= NULL
;
45 EnterFunc(bug("[LinuxInput] Kbd::New()\n"));
47 ObtainSemaphore(&LSD(cl
)->sema
);
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
)))
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"));
68 case aoHidd_Kbd_IrqHandler
:
69 callback
= (APTR
)tag
->ti_Data
;
70 D(bug("Got callback %p\n", (APTR
)tag
->ti_Data
));
73 case aoHidd_Kbd_IrqHandlerData
:
74 callbackdata
= (APTR
)tag
->ti_Data
;
75 D(bug("Got data %p\n", (APTR
)tag
->ti_Data
));
80 } /* while (tags to process) */
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
);
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
);
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
;
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");
143 /**************** scancode2hidd() ****************/
144 #define DEF_TAB_SIZE 128
146 const UBYTE deftable
[] =
277 static UWORD
scancode2hidd(UBYTE scancode
, struct LinuxInput_staticdata
*lsd
)
281 if ((scancode
& 0x80) == 0x80)
286 hiddcode
= scancode2rawkey
[scancode
];
290 if (scancode
>= DEF_TAB_SIZE
)
293 hiddcode
= deftable
[scancode
];
299 VOID
HIDD_LinuxKbd_HandleEvent(OOP_Object
*o
, UBYTE scanCode
)
301 static OOP_MethodID mid
;
302 struct pHidd_LinuxKbd_HandleEvent p
;
305 mid
= OOP_GetMethodID(IID_Hidd_LinuxKbd
, moHidd_LinuxKbd_HandleEvent
);
308 p
.scanCode
= scanCode
;
310 OOP_DoMethod(o
, (OOP_Msg
)&p
);