Modules/Mouse - Fixing bugs, removing debug
authorJohn Hodge <[email protected]>
Sun, 11 Mar 2012 03:21:12 +0000 (11:21 +0800)
committerJohn Hodge <[email protected]>
Sun, 11 Mar 2012 03:21:12 +0000 (11:21 +0800)
- Mouse multiplexer now works
- AxWin3 uses it nicely
- TODO: Fix AxWin3 arrow key handling

KernelLand/Modules/Input/Mouse/main.c
KernelLand/Modules/Input/PS2KbMouse/common.h
KernelLand/Modules/Input/PS2KbMouse/main.c
KernelLand/Modules/Input/PS2KbMouse/ps2mouse.c
KernelLand/Modules/USB/Core/usb_poll.c
KernelLand/Modules/USB/HID/main.c
KernelLand/Modules/USB/HID/mouse.c
Usermode/Applications/axwin3_src/WM/input.c
Usermode/Applications/axwin3_src/WM/main.c

index 7e9b4aa..5e6a9a2 100644 (file)
@@ -38,7 +38,7 @@ tVFS_NodeType gMouse_DevNodeType = {
 };
 tDevFS_Driver  gMouse_DevInfo = {
        NULL, "Mouse",
-       { .Flags = VFS_FFLAG_DIRECTORY, .Type = &gMouse_RootNodeType }
+       { .Flags = VFS_FFLAG_DIRECTORY, .Type = &gMouse_RootNodeType, .Size = 1 }
 };
 tPointer       gMouse_Pointer;
 
@@ -53,6 +53,8 @@ int Mouse_Install(char **Arguments)
 
        gMouse_Pointer.Node.Type = &gMouse_DevNodeType;
        gMouse_Pointer.Node.ImplPtr = &gMouse_Pointer;
+       gMouse_Pointer.FileHeader = (void*)gMouse_Pointer.FileData;
+       gMouse_Pointer.Axies = (void*)( gMouse_Pointer.FileHeader + 1 );
 
        return 0;
 }
@@ -92,6 +94,7 @@ int Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data)
        case JOY_IOCTL_GETSETAXISLIMIT:
                if( !numval || !CheckMem(numval, sizeof(*numval)) )
                        return -1;
+               LOG("GetSetAxisLimit %i = %i", numval->Num, numval->Value);
                if(numval->Num < 0 || numval->Num >= ptr->FileHeader->NAxies)
                        return 0;
                if(numval->Value != -1)
@@ -119,6 +122,8 @@ size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data)
         int    n_buttons = ptr->FileHeader->NButtons;
         int    n_axies = ptr->FileHeader->NAxies;
 
+       ENTER("pNode iLength pData", Node, Length, Data);
+
        // TODO: Locking (Acquire)
 
        Length = MIN(
@@ -155,6 +160,7 @@ size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data)
 
        // TODO: Locking (Release)
 
+       LEAVE('i', Length);
        return Length;
 }
 
@@ -192,7 +198,7 @@ tMouse *Mouse_Register(const char *Name, int NumButtons, int NumAxies)
        // TODO: Locking
        ret->Next = target->FirstDev;
        target->FirstDev = ret;
-       if( ret->NumAxies <= MAX_AXIES && ret->NumAxies > target->FileHeader->NAxies ) {
+       if( ret->NumAxies > target->FileHeader->NAxies ) {
                // Clear new axis data
                memset(
                        target->Axies + target->FileHeader->NAxies,
@@ -202,7 +208,7 @@ tMouse *Mouse_Register(const char *Name, int NumButtons, int NumAxies)
                target->FileHeader->NAxies = ret->NumAxies;
                target->Buttons = (void*)( target->Axies + ret->NumAxies );
        }
-       if( ret->NumButtons <= MAX_BUTTONS && ret->NumButtons > target->FileHeader->NButtons ) {
+       if( ret->NumButtons > target->FileHeader->NButtons ) {
                // No need to move as buttons can expand out into space
                target->FileHeader->NButtons = ret->NumButtons;
        }
@@ -225,18 +231,25 @@ void Mouse_RemoveInstance(tMouse *Instance)
  */
 void Mouse_HandleEvent(tMouse *Handle, Uint32 ButtonState, int *AxisDeltas)
 {
-       tPointer *ptr = Handle->Pointer;
+       tPointer *ptr;
        
-       Handle->ButtonState = ButtonState;
+       ENTER("pHandle xButtonState pAxisDeltas", Handle, ButtonState, AxisDeltas);
+
+       ptr = Handle->Pointer;
 
+       // Update device state
+       Handle->ButtonState = ButtonState;
        memcpy(Handle->LastAxisVal, AxisDeltas, sizeof(*AxisDeltas)*Handle->NumAxies);
 
+       // Update cursor position
        // TODO: Acceleration?
-       
        for( int i = 0; i < Handle->NumAxies; i ++ )
        {
                ptr->Axies[i].CursorPos = MIN(MAX(0, ptr->Axies[i].CursorPos+AxisDeltas[i]), ptr->AxisLimits[i]);
+               LOG("Axis %i: delta = %i, pos = %i", i, AxisDeltas[i], ptr->Axies[i].CursorPos);
        }
+
        VFS_MarkAvaliable( &ptr->Node, 1 );
+       LEAVE('-');
 }
 
index 7cbffe9..b5886a5 100644 (file)
@@ -21,6 +21,6 @@ extern void   PL050_EnableMouse(void);
 extern void    KB_HandleScancode(Uint8 scancode);
 extern void    PS2Mouse_HandleInterrupt(Uint8 InputByte);
 
-extern void    (*gpMouse_EnableFcn)(void);
+extern void    (*gpPS2Mouse_EnableFcn)(void);
 
 #endif
index ae51f81..ceb422a 100644 (file)
@@ -7,7 +7,7 @@
 #include <modules.h>
 #include "common.h"
 
-// === IMPORTS ===
+// === CONSTANTS ===
 // TODO: Allow runtime/compile-time switching
 //       Maybe PCI will have it?
 // Integrator-CP
 // === GLOBALS ===
 MODULE_DEFINE(0, 0x0100, Input_PS2KbMouse, PS2_Install, NULL, NULL);   // Shuts the makefile up
 MODULE_DEFINE(0, 0x0100, PS2Keyboard, KB_Install, NULL, "Input_PS2KbMouse", "Keyboard", NULL);
-MODULE_DEFINE(0, 0x0100, PS2Mouse, PS2Mouse_Install, NULL, "Input_PS2KbMouse", NULL);
+MODULE_DEFINE(0, 0x0100, PS2Mouse, PS2Mouse_Install, NULL, "Input_PS2KbMouse", "Mouse", NULL);
 
 // === CODE ===
 int PS2_Install(char **Arguments)
 {
        #if ARCHDIR_is_x86 || ARCHDIR_is_x86_64
        KBC8042_Init();
-       gpMouse_EnableFcn = KBC8042_EnableMouse;
+       gpPS2Mouse_EnableFcn = KBC8042_EnableMouse;
        #elif ARCHDIR_is_armv7
        PL050_Init(KEYBOARD_BASE, KEYBOARD_IRQ, MOUSE_BASE, MOUSE_IRQ);
-       gpMouse_EnableFcn = PL050_EnableMouse;
+       gpPS2Mouse_EnableFcn = PL050_EnableMouse;
        #endif
 
        return MODULE_ERR_OK;
index 69ce2b2..e7c9949 100644 (file)
@@ -5,9 +5,7 @@
 #include <acess.h>\r
 #include <modules.h>\r
 #include <vfs.h>\r
-#include <fs_devfs.h>\r
-#include <api_drv_common.h>\r
-#include <api_drv_joystick.h>\r
+#include <Input/Mouse/include/mouse.h>\r
 #include "common.h"\r
 \r
 // == CONSTANTS ==\r
 // - Internal -\r
  int   PS2Mouse_Install(char **Arguments);\r
 void   PS2Mouse_HandleInterrupt(Uint8 InputByte);\r
-// - Filesystem -\r
-size_t PS2Mouse_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);\r
- int   PS2Mouse_IOCtl(tVFS_Node *Node, int ID, void *Data);\r
 \r
 // == GLOBALS ==\r
-void   (*gpMouse_EnableFcn)(void);\r
+void   (*gpPS2Mouse_EnableFcn)(void);\r
 // - Settings\r
- int   giMouse_Sensitivity = 1;\r
- int   giMouse_MaxX = 640, giMouse_MaxY = 480;\r
-// - File Data\r
-Uint8  gMouse_FileData[sizeof(tJoystick_FileHeader) + NUM_AXIES*sizeof(tJoystick_Axis) + NUM_BUTTONS];\r
-tJoystick_FileHeader   *gMouse_FileHeader = (void *)gMouse_FileData;\r
-tJoystick_Axis *gMouse_Axies;\r
-Uint8  *gMouse_Buttons;\r
-tJoystick_Callback     gMouse_Callback;\r
- int   gMouse_CallbackArg;\r
- int   giMouse_AxisLimits[2];\r
+ int   giPS2Mouse_Sensitivity = 1;\r
 // - Internal State\r
- int   giMouse_Cycle = 0;      // IRQ Position\r
-Uint8  gaMouse_Bytes[4] = {0,0,0,0};\r
-// - Driver definition\r
-tVFS_NodeType  gMouse_NodeType = {\r
-       .Read = PS2Mouse_Read,\r
-       .IOCtl = PS2Mouse_IOCtl\r
-};\r
-tDevFS_Driver  gMouse_DriverStruct = {\r
-       NULL, "PS2Mouse",\r
-       {\r
-       .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX,\r
-       .Type = &gMouse_NodeType\r
-       }\r
-};\r
+ int   giPS2Mouse_Cycle = 0;   // IRQ Position\r
+Uint8  gaPS2Mouse_Bytes[4] = {0,0,0,0};\r
+tMouse *gpPS2Mouse_Handle;\r
 \r
 // == CODE ==\r
 int PS2Mouse_Install(char **Arguments)\r
 {\r
-       \r
-\r
-       // Set up variables\r
-       gMouse_Axies = (void*)&gMouse_FileData[4];\r
-       gMouse_Buttons = (void*)&gMouse_Axies[NUM_AXIES];\r
+       gpPS2Mouse_Handle = Mouse_Register("PS2Mouse", NUM_AXIES, NUM_BUTTONS);\r
 \r
-       gMouse_FileHeader->NAxies = 2;  gMouse_FileHeader->NButtons = 3;\r
-       gMouse_Axies[0].MinValue = -10; gMouse_Axies[0].MaxValue = 10;\r
-       gMouse_Axies[1].MinValue = -10; gMouse_Axies[1].MaxValue = 10;\r
-       \r
        // Initialise Mouse Controller\r
-       giMouse_Cycle = 0;      // Set Current Cycle position\r
-       gpMouse_EnableFcn();\r
-       \r
-       DevFS_AddDevice(&gMouse_DriverStruct);\r
-       \r
+       giPS2Mouse_Cycle = 0;   // Set Current Cycle position\r
+       gpPS2Mouse_EnableFcn();\r
+\r
        return MODULE_ERR_OK;\r
 }\r
 \r
@@ -79,22 +44,21 @@ void PS2Mouse_HandleInterrupt(Uint8 InputByte)
 {\r
        Uint8   flags;\r
         int    d[2], d_accel[2];\r
-        int    i;\r
        \r
        // Gather mouse data\r
-       gaMouse_Bytes[giMouse_Cycle] = InputByte;\r
-       LOG("gaMouse_Bytes[%i] = 0x%02x", gMouse_Axies[0].MaxValue);\r
+       gaPS2Mouse_Bytes[giPS2Mouse_Cycle] = InputByte;\r
        // - If bit 3 of the first byte is not set, it's not a valid packet?\r
-       if(giMouse_Cycle == 0 && !(gaMouse_Bytes[0] & 0x08) )\r
-               return ;\r
-       giMouse_Cycle++;\r
-       if(giMouse_Cycle < 3)\r
+       if(giPS2Mouse_Cycle == 0 && !(gaPS2Mouse_Bytes[0] & 0x08) )\r
                return ;\r
 \r
-       giMouse_Cycle = 0;\r
+       // 3 bytes per packet\r
+       giPS2Mouse_Cycle++;\r
+       if(giPS2Mouse_Cycle < 3)\r
+               return ;\r
+       giPS2Mouse_Cycle = 0;\r
 \r
        // Actual Processing (once we have all bytes)   \r
-       flags = gaMouse_Bytes[0];\r
+       flags = gaPS2Mouse_Bytes[0];\r
 \r
        LOG("flags = 0x%x", flags);\r
        \r
@@ -102,105 +66,18 @@ void PS2Mouse_HandleInterrupt(Uint8 InputByte)
        if(flags & 0xC0)        return;\r
                \r
        // Calculate dX and dY\r
-       d[0] = gaMouse_Bytes[1];        if(flags & 0x10) d[0] = -(256-d[0]);    // x\r
-       d[1] = gaMouse_Bytes[2];        if(flags & 0x20) d[1] = -(256-d[1]);    // y\r
+       d[0] = gaPS2Mouse_Bytes[1];     if(flags & 0x10) d[0] = -(256-d[0]);    // x\r
+       d[1] = gaPS2Mouse_Bytes[2];     if(flags & 0x20) d[1] = -(256-d[1]);    // y\r
        d[1] = -d[1];   // Y is negated\r
        LOG("RAW dx=%i, dy=%i\n", d[0], d[1]);\r
        // Apply scaling\r
        // TODO: Apply a form of curve to the mouse movement (dx*log(dx), dx^k?)\r
        // TODO: Independent sensitivities?\r
        // TODO: Disable acceleration via a flag?\r
-       d_accel[0] = d[0]*giMouse_Sensitivity;\r
-       d_accel[1] = d[1]*giMouse_Sensitivity;\r
+       d_accel[0] = d[0]*giPS2Mouse_Sensitivity;\r
+       d_accel[1] = d[1]*giPS2Mouse_Sensitivity;\r
        \r
-       // Set Buttons (Primary)\r
-       for( i = 0; i < 3; i ++ )\r
-       {\r
-               Uint8   newVal = (flags & (1 << i)) ? 0xFF : 0;\r
-               if(newVal != gMouse_Buttons[i]) {\r
-                       if( gMouse_Callback )\r
-                               gMouse_Callback(gMouse_CallbackArg, 0, i, newVal - gMouse_Buttons[i]);\r
-                       gMouse_Buttons[i] = newVal;\r
-               }\r
-       }\r
-       \r
-       // Update X and Y Positions\r
-       for( i = 0; i < 2; i ++ )\r
-       {\r
-               Sint16  newCursor = 0;\r
-               if( giMouse_AxisLimits[i] )\r
-                       newCursor = MIN( MAX(0, gMouse_Axies[i].CursorPos + d_accel[i]), giMouse_AxisLimits[i] );;\r
-               \r
-               if( gMouse_Callback )\r
-               {\r
-                       if(giMouse_AxisLimits[i] && gMouse_Axies[i].CursorPos != newCursor)\r
-                               gMouse_Callback(gMouse_CallbackArg, 1, i, newCursor - gMouse_Axies[i].CursorPos);\r
-                       if(!giMouse_AxisLimits[i] && gMouse_Axies[i].CurValue != d_accel[i])\r
-                               gMouse_Callback(gMouse_CallbackArg, 1, i, d_accel[i] - gMouse_Axies[i].CurValue);\r
-               }\r
-               \r
-               gMouse_Axies[i].CurValue = d_accel[i];\r
-               gMouse_Axies[i].CursorPos = newCursor;\r
-       }\r
-\r
-//     Log("Mouse at %ix%i", gMouse_Axies[0].CursorPos, gMouse_Axies[1].CursorPos);\r
-               \r
-       VFS_MarkAvaliable(&gMouse_DriverStruct.RootNode, 1);\r
-}\r
-\r
-/* Read mouse state (coordinates)\r
- */\r
-size_t PS2Mouse_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)\r
-{\r
-       if(Offset > sizeof(gMouse_FileData))    return 0;\r
-       if(Length > sizeof(gMouse_FileData))    Length = sizeof(gMouse_FileData);\r
-       if(Offset + Length > sizeof(gMouse_FileData))   Length = sizeof(gMouse_FileData) - Offset;\r
-\r
-       memcpy(Buffer, &gMouse_FileData[Offset], Length);\r
-       \r
-       VFS_MarkAvaliable(Node, 0);\r
-       return Length;\r
-}\r
-\r
-static const char *csaIOCtls[] = {DRV_IOCTLNAMES, DRV_JOY_IOCTLNAMES, NULL};\r
-/* Handle messages to the device\r
- */\r
-int PS2Mouse_IOCtl(tVFS_Node *Node, int ID, void *Data)\r
-{\r
-       tJoystick_NumValue      *info = Data;\r
-\r
-       switch(ID)\r
-       {\r
-       BASE_IOCTLS(DRV_TYPE_JOYSTICK, "PS2Mouse", 0x100, csaIOCtls);\r
-\r
-       case JOY_IOCTL_SETCALLBACK:     // TODO: Implement\r
-               return -1;\r
-       \r
-       case JOY_IOCTL_SETCALLBACKARG:  // TODO: Implement\r
-               return -1;\r
-       \r
-       case JOY_IOCTL_GETSETAXISLIMIT:\r
-               if(!info)       return 0;\r
-               if(info->Num < 0 || info->Num >= 2)     return 0;\r
-               if(info->Value != -1)\r
-                       giMouse_AxisLimits[info->Num] = info->Value;\r
-               return giMouse_AxisLimits[info->Num];\r
-       \r
-       case JOY_IOCTL_GETSETAXISPOSITION:\r
-               if(!info)       return 0;\r
-               if(info->Num < 0 || info->Num >= 2)     return 0;\r
-               if(info->Value != -1)\r
-                       gMouse_Axies[info->Num].CursorPos = info->Value;\r
-               return gMouse_Axies[info->Num].CursorPos;\r
-\r
-       case JOY_IOCTL_GETSETAXISFLAGS:\r
-               return -1;\r
-       \r
-       case JOY_IOCTL_GETSETBUTTONFLAGS:\r
-               return -1;\r
-\r
-       default:\r
-               return 0;\r
-       }\r
+       // TODO: Scroll wheel?  \r
+       Mouse_HandleEvent(gpPS2Mouse_Handle, (flags & 7), d_accel);\r
 }\r
 \r
index 6359665..9cdd6b4 100644 (file)
@@ -5,7 +5,7 @@
  * usb_poll.c
  * - Endpoint polling
  */
-#define DEBUG  1
+#define DEBUG  0
 #include <usb_core.h>
 #include "usb.h"
 #include <timers.h>
index 1b1ae09..6b36809 100644 (file)
@@ -5,7 +5,7 @@
  * main.c
  * - Driver Core
  */
-#define DEBUG  1
+#define DEBUG  0
 #define VERSION        VER2(0,1)
 #include <acess.h>
 #include <modules.h>
index 2dfbde5..d706a62 100644 (file)
@@ -8,7 +8,6 @@
 #define DEBUG  0
 #include <acess.h>
 #include "hid_reports.h"
-#include <fs_devfs.h>
 #include <Input/Mouse/include/mouse.h>
 
 // === CONSTANTS ===
index 9660dd0..9fe73ff 100644 (file)
@@ -99,6 +99,8 @@ void Input_HandleSelect(fd_set *set)
 
        if(FD_ISSET(giMouseFD, set))
        {
+               const int c_n_axies = 4;
+               const int c_n_buttons = 5;
                 int    i;
                struct sMouseAxis {
                         int16_t        MinValue;
@@ -111,17 +113,30 @@ void Input_HandleSelect(fd_set *set)
                        uint16_t        NAxies;
                        uint16_t        NButtons;
                }       *mouseinfo;
-               char    data[sizeof(*mouseinfo) + sizeof(*axies)*3 + 5];
+               char    data[sizeof(*mouseinfo) + sizeof(*axies)*c_n_axies + c_n_buttons];
 
                mouseinfo = (void*)data;
 
                seek(giMouseFD, 0, SEEK_SET);
                i = read(giMouseFD, data, sizeof(data));
                i -= sizeof(*mouseinfo);
-               if( i < 0 )
+               if( i < 0 ) {
+                       _SysDebug("Mouse data undersized (no header)");
                        return ;
-               if( i < sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons )
+               }
+               if( mouseinfo->NAxies > c_n_axies || mouseinfo->NButtons > c_n_buttons ) {
+                       _SysDebug(
+                               "%i axies, %i buttons above prealloc counts (%i, %i)",
+                               mouseinfo->NAxies, mouseinfo->NButtons, c_n_axies, c_n_buttons
+                               );
+                       return ;
+               }
+               if( i < sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons ) {
+                       _SysDebug("Mouse data undersized (body doesn't fit %i < %i)",
+                               i, sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons
+                               );
                        return ;
+               }
 
                // What? No X/Y?
                if( mouseinfo->NAxies < 2 )
@@ -133,7 +148,7 @@ void Input_HandleSelect(fd_set *set)
                // Handle movement
                Video_SetCursorPos( axies[0].CursorPos, axies[1].CursorPos );
 
-               _SysDebug("Mouse to %i,%i", axies[0].CursorPos, axies[1].CursorPos);
+//             _SysDebug("Mouse to %i,%i", axies[0].CursorPos, axies[1].CursorPos);
 
                WM_Input_MouseMoved(
                        giInput_MouseX, giInput_MouseY,
index b6fcf49..0d15046 100644 (file)
@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
                gsTerminalDevice = "/Devices/VTerm/6";
        }
        if( gsMouseDevice == NULL ) {
-               gsMouseDevice = "/Devices/PS2Mouse";
+               gsMouseDevice = "/Devices/Mouse/system";
        }
        
        Video_Setup();

UCC git Repository :: git.ucc.asn.au