Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / .unmaintained / m68k-pp-native / Drivers / touchscreen.hidd / touchscreenclass.c
blobb6324f4ed4fcd46c0adc94de2c56c9967e5bfc68
1 /*
2 Copyright © 1995-2002, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: The main touchscreen class. Actually a mouse class but still
6 implements a touchscreen.
7 Lang: English.
8 */
10 #include <proto/exec.h>
11 #include <proto/utility.h>
12 #include <proto/oop.h>
13 #include <oop/oop.h>
15 #include <exec/alerts.h>
16 #include <exec/memory.h>
18 #include <hardware/intbits.h>
20 #include <hidd/hidd.h>
21 #include <hidd/mouse.h>
22 #include <hidd/irq.h>
24 #include <devices/inputevent.h>
25 #include <string.h>
27 #include "touchscreen.h"
29 #define DEBUG 1
30 #include <aros/debug.h>
32 #define HiddMouseAB (TSD(cl)->hiddMouseAB)
34 /* Prototypes */
36 /***** Mouse::New() ***************************************/
37 static OOP_Object * _mouse_new(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
39 BOOL has_mouse_hidd = FALSE;
41 EnterFunc(bug("_Mouse::New()\n"));
43 ObtainSemaphoreShared( &TSD(cl)->sema);
45 if (TSD(cl)->mousehidd)
46 has_mouse_hidd = TRUE;
48 ReleaseSemaphore( &TSD(cl)->sema);
50 if (has_mouse_hidd) /* Cannot open twice */
51 ReturnPtr("_Mouse::New", OOP_Object *, NULL); /* Should have some error code here */
53 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
54 if (o) {
55 struct mouse_data *data = OOP_INST_DATA(cl, o);
56 struct TagItem *tag, *tstate;
58 tstate = msg->attrList;
60 /* Search for all mouse attrs */
62 while ((tag = NextTagItem((const struct TagItem **)&tstate))) {
63 ULONG idx;
65 if (IS_HIDDMOUSE_ATTR(tag->ti_Tag, idx))
67 switch (idx)
69 case aoHidd_Mouse_IrqHandler:
70 data->mouse_callback = (APTR)tag->ti_Data;
71 break;
73 case aoHidd_Mouse_IrqHandlerData:
74 data->callbackdata = (APTR)tag->ti_Data;
75 break;
78 } /* while (tags to process) */
81 * Try to get access to the IRQ hidd.
83 data->irqhidd = OOP_NewObject(NULL, CLID_Hidd_IRQ, NULL);
84 if (NULL != data->irqhidd) {
85 HIDDT_IRQ_Handler * irq;
86 data->irq = irq = AllocMem(sizeof(HIDDT_IRQ_Handler),
87 MEMF_CLEAR | MEMF_PUBLIC);
88 if (NULL != irq) {
89 irq->h_Node.ln_Pri = 127;
90 irq->h_Node.ln_Name = "Mouse class irq";
91 irq->h_Code = touchscreen_int;
92 irq->h_Data = (APTR)data;
94 HIDD_IRQ_AddHandler(data->irqhidd, irq, vHidd_IRQ_Mouse);
95 D(bug("Added IRQ Handler for TOUCHSCREEN (virq=%d)!\n",vHidd_IRQ_Mouse));
100 data->VBlank.is_Code = (APTR)&tsVBlank;
101 data->VBlank.is_Data = (APTR)data;
102 data->VBlank.is_Node.ln_Name = "Mouse VBlank server";
103 data->VBlank.is_Node.ln_Pri = 0;
104 data->VBlank.is_Node.ln_Type = NT_INTERRUPT;
105 AddIntServer(INTB_VERTB, &data->VBlank);
106 D(bug("Add INT_VERTB for mouse.\n"));
108 data->state = STATE_IDLE;
109 data->idlectr = 0;
111 ObtainSemaphore( &TSD(cl)->sema);
112 TSD(cl)->mousehidd = o;
113 ReleaseSemaphore( &TSD(cl)->sema);
115 return o;
121 STATIC VOID _mouse_dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
123 struct mouse_data *data = OOP_INST_DATA(cl, o);
125 ObtainSemaphore( &TSD(cl)->sema);
126 TSD(cl)->mousehidd = NULL;
127 ReleaseSemaphore( &TSD(cl)->sema);
129 HIDD_IRQ_RemHandler(data->irqhidd, data->irq);
130 FreeMem(data->irq, sizeof(HIDDT_IRQ_Handler));
132 RemIntServer(INTB_VERTB, &data->VBlank);
134 OOP_DisposeObject(data->irqhidd);
135 OOP_DoSuperMethod(cl, o, msg);
138 /***** Mouse::Get() ***************************************/
139 static VOID _mouse_get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
141 struct mouse_data *data = OOP_INST_DATA(cl, o);
142 ULONG idx;
144 if (IS_HIDDMOUSE_ATTR(msg->attrID, idx)) {
145 switch (idx) {
146 case aoHidd_Mouse_IrqHandler:
147 *msg->storage = (IPTR)data->mouse_callback;
148 break;
150 case aoHidd_Mouse_IrqHandlerData:
151 *msg->storage = (IPTR)data->callbackdata;
152 break;
154 case aoHidd_Mouse_State:
155 break;
160 /***** Mouse::HandleEvent() ***************************************/
162 static VOID _mouse_handleevent(OOP_Class *cl, OOP_Object *o, struct pHidd_Mouse_HandleEvent *msg)
164 struct mouse_data * data;
166 EnterFunc(bug("_touechscreen_handleevent()\n"));
168 data = OOP_INST_DATA(cl, o);
170 /* Nothing done yet */
172 ReturnVoid("_Mouse::HandleEvent");
175 #undef TSD
176 #define TSD(cl) tsd
178 /******************** init_kbdclass() *********************************/
180 #define NUM_ROOT_METHODS 3
181 #define NUM_TOUCHSCREEN_METHODS 1
183 OOP_Class *_init_mouseclass (struct mouse_staticdata *tsd)
185 OOP_Class *cl = NULL;
187 struct OOP_ABDescr attrbases[] =
189 { IID_Hidd_Mouse, &tsd->hiddMouseAB },
190 { NULL, NULL }
193 struct OOP_MethodDescr root_descr[NUM_ROOT_METHODS + 1] =
195 {OOP_METHODDEF(_mouse_new), moRoot_New},
196 {OOP_METHODDEF(_mouse_dispose), moRoot_Dispose},
197 {OOP_METHODDEF(_mouse_get), moRoot_Get},
198 {NULL, 0UL}
201 struct OOP_MethodDescr mousehidd_descr[NUM_TOUCHSCREEN_METHODS + 1] =
203 {OOP_METHODDEF(_mouse_handleevent), moHidd_Mouse_HandleEvent},
204 {NULL, 0UL}
207 struct OOP_InterfaceDescr ifdescr[] =
209 {root_descr, IID_Root, NUM_ROOT_METHODS},
210 {mousehidd_descr, IID_Hidd_DBmouse, NUM_TOUCHSCREEN_METHODS},
211 {NULL, NULL, 0}
214 OOP_AttrBase MetaAttrBase = OOP_ObtainAttrBase(IID_Meta);
216 struct TagItem tags[] =
218 {aMeta_SuperID, (IPTR)CLID_Hidd },
219 {aMeta_InterfaceDescr, (IPTR)ifdescr},
220 {aMeta_InstSize, (IPTR)sizeof (struct mouse_data) },
221 {aMeta_ID, (IPTR)CLID_Hidd_DBmouse },
222 {TAG_DONE, 0UL}
225 EnterFunc(bug("_MouseHiddClass init\n"));
227 if (MetaAttrBase) {
228 cl = OOP_NewObject(NULL, CLID_HiddMeta, tags);
229 if(cl) {
230 cl->UserData = (APTR)tsd;
231 tsd->mouseclass = cl;
233 if (OOP_ObtainAttrBases(attrbases)) {
234 D(bug("_MouseHiddClass ok\n"));
236 OOP_AddClass(cl);
237 } else {
238 _free_mouseclass(tsd);
239 cl = NULL;
242 /* Don't need this anymore */
243 OOP_ReleaseAttrBase(IID_Meta);
245 ReturnPtr("_init_mouseclass", OOP_Class *, cl);
248 /*************** free_mouseclass() **********************************/
249 VOID _free_mouseclass(struct mouse_staticdata *tsd)
251 struct OOP_ABDescr attrbases[] =
253 { IID_Hidd_Mouse, &tsd->hiddMouseAB },
254 { NULL, NULL }
257 EnterFunc(bug("_free_mouseclass(tsd=%p)\n", tsd));
259 if(tsd) {
260 OOP_RemoveClass(tsd->mouseclass);
262 if(tsd->mouseclass) OOP_DisposeObject((OOP_Object *) tsd->mouseclass);
263 tsd->mouseclass = NULL;
265 OOP_ReleaseAttrBases(attrbases);
267 ReturnVoid("_free_mouseclass");