2 Copyright © 1995-2002, The AROS Development Team. All rights reserved.
5 Desc: The main touchscreen class. Actually a mouse class but still
6 implements a touchscreen.
10 #include <proto/exec.h>
11 #include <proto/utility.h>
12 #include <proto/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>
24 #include <devices/inputevent.h>
27 #include "touchscreen.h"
30 #include <aros/debug.h>
32 #define HiddMouseAB (TSD(cl)->hiddMouseAB)
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
);
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
))) {
65 if (IS_HIDDMOUSE_ATTR(tag
->ti_Tag
, idx
))
69 case aoHidd_Mouse_IrqHandler
:
70 data
->mouse_callback
= (APTR
)tag
->ti_Data
;
73 case aoHidd_Mouse_IrqHandlerData
:
74 data
->callbackdata
= (APTR
)tag
->ti_Data
;
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
);
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
;
111 ObtainSemaphore( &TSD(cl
)->sema
);
112 TSD(cl
)->mousehidd
= o
;
113 ReleaseSemaphore( &TSD(cl
)->sema
);
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
);
144 if (IS_HIDDMOUSE_ATTR(msg
->attrID
, idx
)) {
146 case aoHidd_Mouse_IrqHandler
:
147 *msg
->storage
= (IPTR
)data
->mouse_callback
;
150 case aoHidd_Mouse_IrqHandlerData
:
151 *msg
->storage
= (IPTR
)data
->callbackdata
;
154 case aoHidd_Mouse_State
:
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");
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
},
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
},
201 struct OOP_MethodDescr mousehidd_descr
[NUM_TOUCHSCREEN_METHODS
+ 1] =
203 {OOP_METHODDEF(_mouse_handleevent
), moHidd_Mouse_HandleEvent
},
207 struct OOP_InterfaceDescr ifdescr
[] =
209 {root_descr
, IID_Root
, NUM_ROOT_METHODS
},
210 {mousehidd_descr
, IID_Hidd_DBmouse
, NUM_TOUCHSCREEN_METHODS
},
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
},
225 EnterFunc(bug("_MouseHiddClass init\n"));
228 cl
= OOP_NewObject(NULL
, CLID_HiddMeta
, tags
);
230 cl
->UserData
= (APTR
)tsd
;
231 tsd
->mouseclass
= cl
;
233 if (OOP_ObtainAttrBases(attrbases
)) {
234 D(bug("_MouseHiddClass ok\n"));
238 _free_mouseclass(tsd
);
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
},
257 EnterFunc(bug("_free_mouseclass(tsd=%p)\n", 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");