X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FUSB%2FHID%2Fmouse.c;h=d706a626eb731ab4fa065ae99cef4d5dc9307377;hb=5cab4c07bc13888dc7956194ef9595508072a4eb;hp=07f41c4987a198a9c9fdeb001518319b9ab66b1c;hpb=19f38ccc051cc9b9bbcb7048b0c12266cb1d4312;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/USB/HID/mouse.c b/KernelLand/Modules/USB/HID/mouse.c index 07f41c49..d706a626 100644 --- a/KernelLand/Modules/USB/HID/mouse.c +++ b/KernelLand/Modules/USB/HID/mouse.c @@ -5,16 +5,14 @@ * mouse.c * - USB Mouse driver */ -#define DEBUG 1 +#define DEBUG 0 #include #include "hid_reports.h" -#include -#include +#include // === CONSTANTS === #define MAX_AXIES 3 // X, Y, Scroll #define MAX_BUTTONS 5 // Left, Right, Middle, ... -#define FILE_SIZE (sizeof(tJoystick_FileHeader) + MAX_AXIES*sizeof(tJoystick_Axis) + MAX_BUTTONS) // === TYPES === typedef struct sHID_Mouse tHID_Mouse; @@ -24,18 +22,8 @@ struct sHID_Mouse tHID_Mouse *Next; tUSB_DataCallback DataAvail; - // VFS Node - tVFS_Node Node; + tMouse *Handle; - // Joystick Spec data - Uint8 FileData[ FILE_SIZE ]; - tJoystick_FileHeader *FileHeader; - tJoystick_Axis *Axies; - Uint8 *Buttons; - - // Limits for axis positions - Uint16 AxisLimits[MAX_AXIES]; - // - Report parsing int nMappings; struct { @@ -48,13 +36,7 @@ struct sHID_Mouse }; // === PROTOTYES === -char *HID_Mouse_Root_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *HID_Mouse_Root_FindDir(tVFS_Node *Node, const char *Name); -size_t HID_Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); - int HID_Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data); -void HID_Mouse_Dev_Reference(tVFS_Node *Node); -void HID_Mouse_Dev_Close(tVFS_Node *Node); - +Sint32 _ReadBits(void *Data, int Offset, int Length); void HID_Mouse_DataAvail(tUSBInterface *Dev, int EndPt, int Length, void *Data); tHID_ReportCallbacks *HID_Mouse_Report_Collection(tUSBInterface *Dev, tHID_ReportGlobalState *Global, tHID_ReportLocalState *Local, Uint32 Value); @@ -62,25 +44,6 @@ void HID_Mouse_Report_EndCollection(tUSBInterface *Dev); void HID_Mouse_Report_Input(tUSBInterface *Dev, tHID_ReportGlobalState *Global, tHID_ReportLocalState *Local, Uint32 Value); // === GLOBALS === -tVFS_NodeType gHID_Mouse_RootNodeType = { - .TypeName = "HID Mouse Root", - .ReadDir = HID_Mouse_Root_ReadDir, - .FindDir = HID_Mouse_Root_FindDir -}; -tVFS_NodeType gHID_Mouse_DevNodeType = { - .TypeName = "HID Mouse Dev", - .Read = HID_Mouse_Dev_Read, - .IOCtl = HID_Mouse_Dev_IOCtl, - .Reference = HID_Mouse_Dev_Reference, - .Close = HID_Mouse_Dev_Close, -}; -tDevFS_Driver gHID_Mouse_DevFS = { - .Name = "USBMouse", - .RootNode = { - .Type = &gHID_Mouse_RootNodeType, - .Flags = VFS_FFLAG_DIRECTORY - } -}; tHID_ReportCallbacks gHID_Mouse_ReportCBs = { .Collection = HID_Mouse_Report_Collection, .EndCollection = HID_Mouse_Report_EndCollection, @@ -91,94 +54,6 @@ tHID_Mouse *gpHID_FirstMouse; tHID_Mouse *gpHID_LastMouse = (tHID_Mouse*)&gpHID_FirstMouse; // === CODE === -// ---------------------------------------------------------------------------- -// VFS Interface -// ---------------------------------------------------------------------------- -char *HID_Mouse_Root_ReadDir(tVFS_Node *Node, int Pos) -{ - char data[3]; - if(Pos < 0 || Pos >= Node->Size) return NULL; - - snprintf(data, 3, "%i", Pos); - return strdup(data); -} - -tVFS_Node *HID_Mouse_Root_FindDir(tVFS_Node *Node, const char *Name) -{ - int ID; - int ofs; - tHID_Mouse *mouse; - - if( Name[0] == '\0' ) - return NULL; - - ofs = ParseInt(Name, &ID); - if( ofs == 0 || Name[ofs] != '\0' ) - return NULL; - - // Scan list, locate item - Mutex_Acquire(&glHID_MouseListLock); - for( mouse = gpHID_FirstMouse; mouse && ID --; mouse = mouse->Next ) ; - mouse->Node.ReferenceCount ++; - Mutex_Release(&glHID_MouseListLock); - - return &mouse->Node; -} - -size_t HID_Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) -{ - tHID_Mouse *info = Node->ImplPtr; - - if( Offset > FILE_SIZE ) return 0; - - if( Length > FILE_SIZE ) Length = FILE_SIZE; - if( Offset + Length > FILE_SIZE ) Length = FILE_SIZE - Offset; - - memcpy( Buffer, info->FileData + Offset, Length ); - - VFS_MarkAvaliable( &info->Node, 0 ); - - return Length; -} - -static const char *csaDevIOCtls[] = {DRV_IOCTLNAMES, DRV_JOY_IOCTLNAMES, NULL}; -int HID_Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data) -{ - tJoystick_NumValue *numval = Data; - tHID_Mouse *info = Node->ImplPtr; - switch(ID) - { - BASE_IOCTLS(DRV_TYPE_JOYSTICK, "USBMouse", 0x050, csaDevIOCtls); - - case JOY_IOCTL_GETSETAXISLIMIT: - if( !numval || !CheckMem(numval, sizeof(*numval)) ) - return -1; - if(numval->Num < 0 || numval->Num >= MAX_AXIES) - return 0; - if(numval->Value != -1) - info->AxisLimits[numval->Num] = numval->Value; - return info->AxisLimits[numval->Num]; - - case JOY_IOCTL_GETSETAXISPOSITION: - if( !numval || !CheckMem(numval, sizeof(*numval)) ) - return -1; - if(numval->Num < 0 || numval->Num >= MAX_AXIES) - return 0; - if(numval->Value != -1) - info->Axies[numval->Num].CursorPos = numval->Value; - return info->Axies[numval->Num].CursorPos; - } - return -1; -} -void HID_Mouse_Dev_Reference(tVFS_Node *Node) -{ - Node->ReferenceCount ++; -} -void HID_Mouse_Dev_Close(tVFS_Node *Node) -{ - Node->ReferenceCount --; -} - // ---------------------------------------------------------------------------- // Data input / Update // ---------------------------------------------------------------------------- @@ -243,6 +118,8 @@ void HID_Mouse_DataAvail(tUSBInterface *Dev, int EndPt, int Length, void *Data) { tHID_Mouse *info; int ofs; + Uint32 button_value = 0; + int axis_values[MAX_AXIES] = {0}; info = USB_GetDeviceDataPtr(Dev); if( !info ) return ; @@ -265,32 +142,20 @@ void HID_Mouse_DataAvail(tUSBInterface *Dev, int EndPt, int Length, void *Data) if( dest & 0x80 ) { // Axis - info->Axies[ dest & 0x7F ].CurValue = value; + axis_values[ dest & 0x7F ] = value; + LOG("Axis %i = %i", dest & 0x7F, value); } else { // Button - info->Buttons[ dest & 0x7F ] = (value == 0) ? 0 : 0xFF; + if( value == 0 ) + ; + else + button_value |= 1 << (dest & 0x7F); } } - // Update axis positions - for( int i = 0; i < MAX_AXIES; i ++ ) - { - int newpos; - - // TODO: Scaling - newpos = info->Axies[i].CursorPos + info->Axies[i].CurValue; - - if(newpos < 0) newpos = 0; - if(newpos > info->AxisLimits[i]) newpos = info->AxisLimits[i]; - - info->Axies[i].CursorPos = newpos; - } -// Log_Debug("USBMouse", "New Pos (%i,%i,%i)", -// info->Axies[0].CursorPos, info->Axies[1].CursorPos, info->Axies[2].CursorPos -// ); - VFS_MarkAvaliable( &info->Node, 1 ); + Mouse_HandleEvent(info->Handle, button_value, axis_values); } // ---------------------------------------------------------------------------- @@ -313,20 +178,8 @@ tHID_ReportCallbacks *HID_Mouse_Report_Collection( // New device! info = calloc( sizeof(tHID_Mouse), 1 ); info->DataAvail = HID_Mouse_DataAvail; - info->Node.ImplPtr = info; - info->Node.Type = &gHID_Mouse_DevNodeType; - - info->FileHeader = (void*)info->FileData; - info->Axies = (void*)(info->FileHeader + 1); - info->Buttons = (void*)(info->Axies + MAX_AXIES); - info->FileHeader->NAxies = MAX_AXIES; - info->FileHeader->NButtons = MAX_BUTTONS; - - for( int i = 0; i < MAX_AXIES; i ++ ) { - info->Axies[i].MinValue = -10; - info->Axies[i].MaxValue = 10; - } - + + info->Handle = Mouse_Register("USBMouse", MAX_BUTTONS, MAX_AXIES); LOG("Initialised new mouse at %p", info); @@ -359,7 +212,6 @@ void HID_Mouse_Report_EndCollection(tUSBInterface *Dev) Mutex_Acquire(&glHID_MouseListLock); gpHID_LastMouse->Next = info; gpHID_LastMouse = info; - gHID_Mouse_DevFS.RootNode.Size ++; Mutex_Release(&glHID_MouseListLock); } else @@ -396,6 +248,8 @@ void HID_int_AddInput(tUSBInterface *Dev, Uint32 Usage, Uint8 Size, Uint32 Min, default: tag = 0xFF; break; } + LOG("Usage = 0x%08x, tag = 0x%2x", Usage, tag); + // --- Add to list of mappings --- info->nMappings ++; info->Mappings = realloc(info->Mappings, info->nMappings * sizeof(info->Mappings[0])); @@ -405,11 +259,12 @@ void HID_int_AddInput(tUSBInterface *Dev, Uint32 Usage, Uint8 Size, Uint32 Min, // --- Update Min/Max for Axies --- // TODO: DPI too - if( tag != 0xFF && (tag & 0x80) ) - { - info->Axies[ tag & 0x7F ].MinValue = Min; - info->Axies[ tag & 0x7F ].MaxValue = Max; - } + // TODO: Pass to mouse multiplexer +// if( tag != 0xFF && (tag & 0x80) ) +// { +// info->Axies[ tag & 0x7F ].MinValue = Min; +// info->Axies[ tag & 0x7F ].MaxValue = Max; +// } } /** @@ -422,11 +277,13 @@ void HID_Mouse_Report_Input( ) { Uint32 usage = 0; + LOG("Local->Usages.nItems = %i", Local->Usages.nItems); for( int i = 0; i < Global->ReportCount; i ++ ) { // - Update usage if( i < Local->Usages.nItems ) usage = Local->Usages.Items[i]; + LOG("%i: usage = %x", i, usage); // - Add to list HID_int_AddInput(Dev, usage, Global->ReportSize, Global->LogMin, Global->LogMax); }