2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
5 Desc: The main mouse class.
10 This is the native-i386 hidd maintaining all available mouse types. It
11 maintains all COM/PS2 mouses available. USB is in a way (we need pci.hidd
12 working, then usb.hidd).
14 Please keep code clean from all .bss and .data sections. .rodata may exist
15 as it will be connected together with .text section during linking. In near
16 future this driver will be compiled as elf executable (instead of object)
20 #include <proto/exec.h>
21 #include <proto/utility.h>
22 #include <proto/oop.h>
25 #include <exec/alerts.h>
26 #include <exec/memory.h>
28 #include <hidd/hidd.h>
29 #include <hidd/mouse.h>
31 #include <devices/inputevent.h>
34 #include <aros/symbolsets.h>
38 #include LC_LIBDEFS_FILE
41 #include <aros/debug.h>
43 #warning "TODO: Remove all .data from file !"
48 #define HiddMouseAB (MSD(cl)->hiddMouseAB)
52 int test_mouse_usb(OOP_Class
*, OOP_Object
*);
53 int test_mouse_ps2(OOP_Class
*, OOP_Object
*);
54 int test_mouse_com(OOP_Class
*, OOP_Object
*);
55 void dispose_mouse_usb(OOP_Class
*, OOP_Object
*);
56 void dispose_mouse_ps2(OOP_Class
*, OOP_Object
*);
57 void dispose_mouse_seriell(OOP_Class
*, OOP_Object
*);
58 void getps2State(OOP_Class
*, OOP_Object
*, struct pHidd_Mouse_Event
*);
60 /* defines for buttonstate */
63 #define RIGHT_BUTTON 2
64 #define MIDDLE_BUTTON 4
66 /***** Mouse::New() ***************************************/
67 OOP_Object
* PCMouse__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
69 BOOL has_mouse_hidd
= FALSE
;
71 EnterFunc(bug("_Mouse::New()\n"));
73 ObtainSemaphoreShared( &MSD(cl
)->sema
);
75 if (MSD(cl
)->mousehidd
)
76 has_mouse_hidd
= TRUE
;
78 ReleaseSemaphore( &MSD(cl
)->sema
);
80 if (has_mouse_hidd
) /* Cannot open twice */
81 ReturnPtr("_Mouse::New", OOP_Object
*, NULL
); /* Should have some error code here */
83 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
86 struct mouse_data
*data
= OOP_INST_DATA(cl
, o
);
87 struct TagItem
*tag
, *tstate
;
89 tstate
= msg
->attrList
;
91 /* Search for all mouse attrs */
93 while ((tag
= NextTagItem((const struct TagItem
**)&tstate
)))
97 if (IS_HIDDMOUSE_ATTR(tag
->ti_Tag
, idx
))
101 case aoHidd_Mouse_IrqHandler
:
102 data
->mouse_callback
= (APTR
)tag
->ti_Data
;
105 case aoHidd_Mouse_IrqHandlerData
:
106 data
->callbackdata
= (APTR
)tag
->ti_Data
;
111 } /* while (tags to process) */
113 /* Search for mouse installed. As USB is the fastest to test, do it
114 first, if not found search for PS/2 mouse. If failure then check every
115 COM port in the system - the las chance to see... */
117 data
->type
= MDT_USB
;
118 if (!test_mouse_usb(cl
, o
))
120 memset(&data
->u
.com
, 0, sizeof(data
->u
.com
));
121 data
->type
= MDT_SERIELL
;
123 if (!test_mouse_com(cl
, o
))
125 memset(&data
->u
.ps2
, 0, sizeof(data
->u
.ps2
));
126 data
->type
= MDT_PS2
;
128 if (!test_mouse_ps2(cl
, o
))
130 /* No mouse found. What we can do now is just Dispose() :( */
131 OOP_MethodID disp_mid
;
132 data
->type
= MDT_UNKNOWN
;
133 disp_mid
= OOP_GetMethodID(IID_Root
, moRoot_Dispose
);
134 OOP_CoerceMethod(cl
, o
, (OOP_Msg
) &disp_mid
);
141 ObtainSemaphore( &MSD(cl
)->sema
);
142 MSD(cl
)->mousehidd
= o
;
143 ReleaseSemaphore( &MSD(cl
)->sema
);
149 VOID
PCMouse__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
151 struct mouse_data
*data
= OOP_INST_DATA(cl
, o
);
153 ObtainSemaphore( &MSD(cl
)->sema
);
154 MSD(cl
)->mousehidd
= NULL
;
155 ReleaseSemaphore( &MSD(cl
)->sema
);
160 dispose_mouse_usb(cl
, o
);
164 dispose_mouse_seriell(cl
, o
);
168 dispose_mouse_ps2(cl
, o
);
172 OOP_DoSuperMethod(cl
, o
, msg
);
175 /***** Mouse::Get() ***************************************/
176 VOID
PCMouse__Root__Get(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
)
178 struct mouse_data
*data
= OOP_INST_DATA(cl
, o
);
181 if (IS_HIDDMOUSE_ATTR(msg
->attrID
, idx
))
185 case aoHidd_Mouse_IrqHandler
:
186 *msg
->storage
= (IPTR
)data
->mouse_callback
;
189 case aoHidd_Mouse_IrqHandlerData
:
190 *msg
->storage
= (IPTR
)data
->callbackdata
;
193 case aoHidd_Mouse_State
:
194 if (data
->type
== MDT_PS2
)
195 getps2State(cl
, o
, (struct pHidd_Mouse_Event
*)msg
->storage
);
198 case aoHidd_Mouse_RelativeCoords
:
199 *msg
->storage
= TRUE
;
205 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
208 /***** Mouse::HandleEvent() ***************************************/
210 VOID
PCMouse__Hidd_Mouse__HandleEvent(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_Mouse_HandleEvent
*msg
)
212 struct mouse_data
* data
;
214 EnterFunc(bug("_mouse_handleevent()\n"));
216 data
= OOP_INST_DATA(cl
, o
);
218 /* Nothing done yet */
220 ReturnVoid("_Mouse::HandleEvent");
223 /******************** init_kbdclass() *********************************/
225 static int PCMouse_InitAttrs(LIBBASETYPEPTR LIBBASE
)
227 struct OOP_ABDescr attrbases
[] =
229 { IID_Hidd_Mouse
, &LIBBASE
->msd
.hiddMouseAB
},
233 EnterFunc(bug("PCMouse_InitAttrs\n"));
235 ReturnInt("PCMouse_InitAttr", ULONG
, OOP_ObtainAttrBases(attrbases
));
238 /*************** free_kbdclass() **********************************/
239 static int PCMouse_ExpungeAttrs(LIBBASETYPEPTR LIBBASE
)
241 struct OOP_ABDescr attrbases
[] =
243 { IID_Hidd_Mouse
, &LIBBASE
->msd
.hiddMouseAB
},
247 EnterFunc(bug("PCMouse_InitClass\n"));
249 OOP_ReleaseAttrBases(attrbases
);
254 ADD2INITLIB(PCMouse_InitAttrs
, 0)
255 ADD2EXPUNGELIB(PCMouse_ExpungeAttrs
, 0)