2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
5 Desc: GDI hidd handling keypresses.
9 #define __OOP_NOATTRBASES__
11 #include <aros/debug.h>
12 #include <aros/symbolsets.h>
13 #include <devices/inputevent.h>
14 #include <devices/rawkeycodes.h>
16 #include <hidd/hidd.h>
17 #include <hidd/keyboard.h>
19 #include <proto/kernel.h>
20 #include <proto/utility.h>
21 #include <proto/oop.h>
23 #include LC_LIBDEFS_FILE
28 #include "stdkeytable.h"
29 #include "e0keytable.h"
31 /****************************************************************************************/
33 static OOP_AttrBase HiddKbdAB
;
35 static struct OOP_ABDescr attrbases
[] =
37 { IID_Hidd_Kbd
, &HiddKbdAB
},
41 /****************************************************************************************/
43 static VOID
KbdIntHandler(struct gdikbd_data
*data
, volatile struct GDI_Control
*KEYBOARDDATA
)
48 UWORD eventcode
= KEYBOARDDATA
->KbdEvent
;
49 UWORD rawcode
= KEYBOARDDATA
->KeyCode
;
52 * Signal to event processing thread that we've read the event.
53 * Omit Forbid()/Permit() pair here because we are inside interrupt.
55 native_func
->GDI_KbdAck();
59 keytable
= e0_keytable
;
64 keytable
= std_keytable
;
65 numkeys
= NUM_STDKEYS
;
69 if (rawcode
< numkeys
)
71 keycode
= keytable
[rawcode
];
74 if (eventcode
== WM_KEYUP
)
75 keycode
|= IECODE_UP_PREFIX
;
77 data
->kbd_callback(data
->callbackdata
, keycode
);
82 /****************************************************************************************/
84 OOP_Object
* GDIKbd__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
86 struct TagItem
*tag
, *tstate
;
88 APTR callbackdata
= NULL
;
90 EnterFunc(bug("GDIKbd::New()\n"));
94 /* It is illegal to create more than one object */
95 ReturnPtr("GDIKbd::New", OOP_Object
*, NULL
);
98 tstate
= msg
->attrList
;
99 D(bug("attrList: 0x%p\n", tstate
));
101 while ((tag
= NextTagItem(&tstate
)))
105 D(bug("Got tag %d, data %x\n", tag
->ti_Tag
, tag
->ti_Data
));
107 if (IS_HIDDKBD_ATTR(tag
->ti_Tag
, idx
))
109 D(bug("Kbd hidd tag\n"));
112 case aoHidd_Kbd_IrqHandler
:
113 callback
= (APTR
)tag
->ti_Data
;
114 D(bug("Got callback %p\n", (APTR
)tag
->ti_Data
));
117 case aoHidd_Kbd_IrqHandlerData
:
118 callbackdata
= (APTR
)tag
->ti_Data
;
119 D(bug("Got data %p\n", (APTR
)tag
->ti_Data
));
124 } /* while (tags to process) */
126 if (NULL
== callback
)
127 ReturnPtr("GDIKbd::New", OOP_Object
*, NULL
); /* Should have some error code here */
129 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
132 struct gdikbd_data
*data
= OOP_INST_DATA(cl
, o
);
133 struct GDI_Control
*ctl
= XSD(cl
)->ctl
;
135 data
->interrupt
= KrnAddIRQHandler(ctl
->KbdIrq
, KbdIntHandler
, data
, ctl
);
138 data
->kbd_callback
= (VOID (*)(APTR
, UWORD
))callback
;
139 data
->callbackdata
= callbackdata
;
141 XSD(cl
)->kbdhidd
= o
;
143 ReturnPtr("GDIKbd::New", OOP_Object
*, o
);
145 OOP_MethodID disp_mid
= OOP_GetMethodID(IID_Root
, moRoot_Dispose
);
146 OOP_CoerceMethod(cl
, o
, (OOP_Msg
) &disp_mid
);
151 /****************************************************************************************/
153 VOID
GDIKbd__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
155 struct gdikbd_data
*data
= OOP_INST_DATA(cl
, o
);
157 EnterFunc(bug("[GDIKbd] Dispose()\n"));
159 KrnRemIRQHandler(data
->interrupt
);
160 ObtainSemaphore( &XSD(cl
)->sema
);
161 XSD(cl
)->kbdhidd
= NULL
;
162 ReleaseSemaphore( &XSD(cl
)->sema
);
163 OOP_DoSuperMethod(cl
, o
, msg
);
166 /****************************************************************************************/
168 static int kbd_init(LIBBASETYPEPTR LIBBASE
)
170 return OOP_ObtainAttrBases(attrbases
);
173 /****************************************************************************************/
175 static int kbd_expunge(LIBBASETYPEPTR LIBBASE
)
177 OOP_ReleaseAttrBases(attrbases
);
181 /****************************************************************************************/
183 ADD2INITLIB(kbd_init
, 0);
184 ADD2EXPUNGELIB(kbd_expunge
, 0);