2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 Desc: The main mouse class.
10 This is the universal serial mouse driver.
11 The code is very old, and is actually one big TODO. Here is a short list
13 1. Drop serial HIDDs and use device API instead. This will allow to do
14 interesting things, like handling serial mice on USB-Serial adapters.
15 Useful at least for testing.
16 2. Rewrite detection routine. Device detection should be done in startup.c,
17 and one instance should be created for every mouse detected. Yes, we can
18 handle several mice at once. Additionally it will provide correct
20 3. Replace busyloop PIT-based mouse_usleep() with timer.device-based delay.
21 Will make the driver working on any arch.
23 Please keep code clean from all .bss and .data sections. .rodata may exist
24 as it will be connected together with .text section during linking.
27 #include <proto/exec.h>
28 #include <proto/utility.h>
29 #include <proto/oop.h>
31 #include <exec/alerts.h>
32 #include <exec/memory.h>
33 #include <hidd/hidd.h>
34 #include <hidd/mouse.h>
35 #include <devices/inputevent.h>
37 #include <aros/symbolsets.h>
42 #include <aros/debug.h>
46 int test_mouse_serial(OOP_Class
*, OOP_Object
*);
47 void dispose_mouse_serial(OOP_Class
*, OOP_Object
*);
49 /* defines for buttonstate */
52 #define RIGHT_BUTTON 2
53 #define MIDDLE_BUTTON 4
55 /***** Mouse::New() ***************************************/
56 OOP_Object
* PCMouse__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
58 EnterFunc(bug("_Mouse::New()\n"));
60 if (MSD(cl
)->mousehidd
) /* Cannot open twice */
61 ReturnPtr("_Mouse::New", OOP_Object
*, NULL
); /* Should have some error code here */
63 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
66 struct mouse_data
*data
= OOP_INST_DATA(cl
, o
);
67 struct TagItem
*tag
, *tstate
;
69 tstate
= msg
->attrList
;
71 /* Search for all mouse attrs */
73 while ((tag
= NextTagItem(&tstate
)))
77 if (IS_HIDDMOUSE_ATTR(tag
->ti_Tag
, idx
))
81 case aoHidd_Mouse_IrqHandler
:
82 data
->mouse_callback
= (APTR
)tag
->ti_Data
;
85 case aoHidd_Mouse_IrqHandlerData
:
86 data
->callbackdata
= (APTR
)tag
->ti_Data
;
91 } /* while (tags to process) */
93 /* Search for mouse installed. Check every COM port in the system */
94 if (!test_mouse_serial(cl
, o
))
96 /* No mouse found. What we can do now is just Dispose() :( */
97 OOP_MethodID disp_mid
= msg
->mID
- moRoot_New
+ moRoot_Dispose
;
99 /* Do not call own Dispose */
100 OOP_DoSuperMethod(cl
, o
, &disp_mid
);
104 MSD(cl
)->mousehidd
= o
;
110 VOID
PCMouse__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
112 MSD(cl
)->mousehidd
= NULL
;
114 dispose_mouse_serial(cl
, o
);
116 OOP_DoSuperMethod(cl
, o
, msg
);
119 /***** Mouse::Get() ***************************************/
120 VOID
PCMouse__Root__Get(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
)
122 struct mouse_data
*data
= OOP_INST_DATA(cl
, o
);
125 if (IS_HIDDMOUSE_ATTR(msg
->attrID
, idx
))
129 case aoHidd_Mouse_IrqHandler
:
130 *msg
->storage
= (IPTR
)data
->mouse_callback
;
133 case aoHidd_Mouse_IrqHandlerData
:
134 *msg
->storage
= (IPTR
)data
->callbackdata
;
137 case aoHidd_Mouse_State
:
138 *msg
->storage
= 0; /* FIXME: Implement this */
141 case aoHidd_Mouse_RelativeCoords
:
142 *msg
->storage
= TRUE
;
148 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
151 /******************** init and expunge *********************************/
154 #define OOPBase (LIBBASE->msd.oopBase)
156 static int PCMouse_InitAttrs(struct mousebase
*LIBBASE
)
158 struct OOP_ABDescr attrbases
[] =
160 { IID_Hidd
, &LIBBASE
->msd
.hiddAttrBase
},
161 { IID_Hidd_Mouse
, &LIBBASE
->msd
.hiddMouseAB
},
165 EnterFunc(bug("PCMouse_InitAttrs\n"));
167 LIBBASE
->msd
.utilityBase
= OpenLibrary("utility.library", 36);
168 if (!LIBBASE
->msd
.utilityBase
)
171 if (!OOP_ObtainAttrBases(attrbases
))
174 LIBBASE
->msd
.hwMethodBase
= OOP_GetMethodID(IID_HW
, 0);
178 /*************** free_kbdclass() **********************************/
179 static int PCMouse_ExpungeAttrs(struct mousebase
*LIBBASE
)
181 struct OOP_ABDescr attrbases
[] =
183 { IID_Hidd
, &LIBBASE
->msd
.hiddAttrBase
},
184 { IID_Hidd_Mouse
, &LIBBASE
->msd
.hiddMouseAB
},
188 EnterFunc(bug("PCMouse_InitClass\n"));
190 OOP_ReleaseAttrBases(attrbases
);
192 if (LIBBASE
->msd
.utilityBase
)
193 CloseLibrary(LIBBASE
->msd
.utilityBase
);
198 ADD2INITLIB(PCMouse_InitAttrs
, 0)
199 ADD2EXPUNGELIB(PCMouse_ExpungeAttrs
, 0)