2 * Acess2 Kernel - Mouse Mulitplexing Driver
3 * - By John Hodge (thePowersGang)
9 #define VERSION VER2(0,1)
13 #include "include/mouse_int.h"
16 int Mouse_Install(char **Arguments);
17 int Mouse_Cleanup(void);
19 int Mouse_Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]);
20 tVFS_Node *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags);
21 int Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data);
22 size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data, Uint Flags);
24 void Mouse_HandleEvent(Uint32 ButtonState, int *AxisDeltas, int *AxisValues);
27 tVFS_NodeType gMouse_RootNodeType = {
28 .ReadDir = Mouse_Root_ReadDir,
29 .FindDir = Mouse_Root_FindDir
31 tVFS_NodeType gMouse_DevNodeType = {
32 .IOCtl = Mouse_Dev_IOCtl,
33 .Read = Mouse_Dev_Read
35 tDevFS_Driver gMouse_DevInfo = {
37 { .Flags = VFS_FFLAG_DIRECTORY, .Type = &gMouse_RootNodeType, .Size = 1 }
39 tPointer gMouse_Pointer;
43 * \brief Initialise the keyboard driver
45 int Mouse_Install(char **Arguments)
47 /// - Register with DevFS
48 DevFS_AddDevice( &gMouse_DevInfo );
50 gMouse_Pointer.Node.Type = &gMouse_DevNodeType;
51 gMouse_Pointer.Node.ImplPtr = &gMouse_Pointer;
52 gMouse_Pointer.FileHeader = (void*)gMouse_Pointer.FileData;
53 gMouse_Pointer.Axies = (void*)( gMouse_Pointer.FileHeader + 1 );
54 gMouse_Pointer.Buttons = (void*)( gMouse_Pointer.Axies + MAX_AXIES );
55 gMouse_Pointer.FileHeader->NAxies = MAX_AXIES;
56 gMouse_Pointer.FileHeader->NButtons = MAX_BUTTONS;
62 * \brief Pre-unload cleanup function
64 int Mouse_Cleanup(void)
69 // --- VFS Interface ---
70 int Mouse_Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX])
74 strcpy(Dest, "system");
78 tVFS_Node *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags)
80 if( strcmp(Name, "system") != 0 ) return NULL;
81 return &gMouse_Pointer.Node;
84 static const char *csaIOCTL_NAMES[] = {DRV_IOCTLNAMES, DRV_JOY_IOCTLNAMES, NULL};
86 * \brief IOCtl handler for the mouse
88 int Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data)
90 tJoystick_NumValue *numval = Data;
91 tPointer *ptr = Node->ImplPtr;
94 BASE_IOCTLS(DRV_TYPE_MOUSE, "Mouse", VERSION, csaIOCTL_NAMES);
96 case JOY_IOCTL_GETSETAXISLIMIT:
97 if( !numval || !CheckMem(numval, sizeof(*numval)) )
99 LOG("GetSetAxisLimit %i = %i", numval->Num, numval->Value);
100 if(numval->Num < 0 || numval->Num >= ptr->FileHeader->NAxies)
102 if(numval->Value != -1)
103 ptr->AxisLimits[numval->Num] = numval->Value;
104 return ptr->AxisLimits[numval->Num];
106 case JOY_IOCTL_GETSETAXISPOSITION:
107 if( !numval || !CheckMem(numval, sizeof(*numval)) )
109 if(numval->Num < 0 || numval->Num >= ptr->FileHeader->NAxies)
111 if(numval->Value != -1)
112 ptr->Axies[numval->Num].CursorPos = numval->Value;
113 return ptr->Axies[numval->Num].CursorPos;
119 * \brief Read from a device
121 size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data, Uint Flags)
123 tPointer *ptr = Node->ImplPtr;
124 int n_buttons = ptr->FileHeader->NButtons;
125 int n_axies = ptr->FileHeader->NAxies;
127 ENTER("pNode iLength pData", Node, Length, Data);
129 // TODO: Locking (Acquire)
133 sizeof(tJoystick_FileHeader) + n_axies*sizeof(tJoystick_Axis) + n_buttons
137 VFS_MarkAvaliable( Node, 0 );
139 memcpy( Data, ptr->FileData, Length );
141 // TODO: Locking (Release)
147 // --- Device Interface ---
149 * Handle a mouse event (movement or button press/release)
150 * - See Input/Mouse/include/mouse.h
152 void Mouse_HandleEvent(Uint32 ButtonState, int *AxisDeltas, int *AxisValues)
154 tPointer *ptr = &gMouse_Pointer;
156 ENTER("pHandle xButtonState pAxisDeltas", Handle, ButtonState, AxisDeltas);
158 // Update cursor position
159 for( int i = 0; i < 2; i ++ )
161 ptr->Axies[i].CursorPos = AxisValues[i];
162 ptr->Axies[i].CurValue = AxisDeltas ? AxisDeltas[i] : 0;
164 for( int i = 0; i < 5; i ++ )
165 ptr->Buttons[i] = ButtonState & (1 << i) ? 255 : 0;
167 VFS_MarkAvaliable( &ptr->Node, 1 );