Kernel - Slight reworks to timer code
[tpg/acess2.git] / Modules / Input / PS2KbMouse / ps2mouse.c
index cb26efe..44be3b7 100644 (file)
@@ -8,26 +8,22 @@
 #include <fs_devfs.h>\r
 #include <api_drv_common.h>\r
 #include <api_drv_joystick.h>\r
-\r
-static inline int MIN(int a, int b) { return (a < b) ? a : b; }\r
-static inline int MAX(int a, int b) { return (a > b) ? a : b; }\r
+#include "common.h"\r
 \r
 // == CONSTANTS ==\r
 #define NUM_AXIES      2       // X+Y\r
 #define NUM_BUTTONS    5       // Left, Right, Scroll Click, Scroll Up, Scroll Down\r
-#define PS2_IO_PORT    0x60\r
 \r
 // == PROTOTYPES ==\r
 // - Internal -\r
  int   PS2Mouse_Install(char **Arguments);\r
-void   PS2Mouse_IRQ(int Num);\r
-static void    mouseSendCommand(Uint8 cmd);\r
-void   PS2Mouse_Enable();\r
+void   PS2Mouse_HandleInterrupt(Uint8 InputByte);\r
 // - Filesystem -\r
 Uint64 PS2Mouse_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);\r
 int    PS2Mouse_IOCtl(tVFS_Node *Node, int ID, void *Data);\r
 \r
 // == GLOBALS ==\r
+void   (*gpMouse_EnableFcn)(void);\r
 // - Settings\r
  int   giMouse_Sensitivity = 1;\r
  int   giMouse_MaxX = 640, giMouse_MaxY = 480;\r
@@ -43,25 +39,34 @@ tJoystick_Callback  gMouse_Callback;
  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
-       .Read = PS2Mouse_Read, .IOCtl = PS2Mouse_IOCtl\r
+       .Type = &gMouse_NodeType\r
        }\r
 };\r
 \r
 // == CODE ==\r
 int PS2Mouse_Install(char **Arguments)\r
 {\r
+       \r
+\r
        // Set up variables\r
-       gMouse_Axies = (void*)&gMouse_FileData[1];\r
+       gMouse_Axies = (void*)&gMouse_FileData[4];\r
        gMouse_Buttons = (void*)&gMouse_Axies[NUM_AXIES];\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
-       IRQ_AddHandler(12, PS2Mouse_IRQ);       // Set IRQ\r
        giMouse_Cycle = 0;      // Set Current Cycle position\r
-       PS2Mouse_Enable();              // Enable the mouse\r
+       gpMouse_EnableFcn();\r
        \r
        DevFS_AddDevice(&gMouse_DriverStruct);\r
        \r
@@ -70,14 +75,14 @@ int PS2Mouse_Install(char **Arguments)
 \r
 /* Handle Mouse Interrupt\r
  */\r
-void PS2Mouse_IRQ(int Num)\r
+void PS2Mouse_HandleInterrupt(Uint8 InputByte)\r
 {\r
        Uint8   flags;\r
         int    d[2], d_accel[2];\r
         int    i;\r
        \r
        // Gather mouse data\r
-       gaMouse_Bytes[giMouse_Cycle] = inb(0x60);\r
+       gaMouse_Bytes[giMouse_Cycle] = InputByte;\r
        LOG("gaMouse_Bytes[%i] = 0x%02x", gMouse_Axies[0].MaxValue);\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
@@ -137,11 +142,9 @@ void PS2Mouse_IRQ(int Num)
                gMouse_Axies[i].CurValue = d_accel[i];\r
                gMouse_Axies[i].CursorPos = newCursor;\r
        }\r
-       \r
-//     Log_Debug("PS2Mouse", "gMouse_Buttons = {0x%x,0x%x,0x%x}, gMouse_Axies={%i,%i}", \r
-//             gMouse_Buttons[0], gMouse_Buttons[1], gMouse_Buttons[2],\r
-//             gMouse_Axies[0].CursorPos, gMouse_Axies[1].CursorPos);\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
@@ -201,47 +204,3 @@ int PS2Mouse_IOCtl(tVFS_Node *Node, int ID, void *Data)
        }\r
 }\r
 \r
-//== Internal Functions ==\r
-static inline void mouseOut64(Uint8 data)\r
-{\r
-       int timeout=100000;\r
-       while( timeout-- && inb(0x64) & 2 );    // Wait for Flag to clear\r
-       outb(0x64, data);       // Send Command\r
-}\r
-static inline void mouseOut60(Uint8 data)\r
-{\r
-       int timeout=100000;\r
-       while( timeout-- && inb(0x64) & 2 );    // Wait for Flag to clear\r
-       outb(0x60, data);       // Send Command\r
-}\r
-static inline Uint8 mouseIn60(void)\r
-{\r
-       int timeout=100000;\r
-       while( timeout-- && (inb(0x64) & 1) == 0);      // Wait for Flag to set\r
-       return inb(0x60);\r
-}\r
-static inline void mouseSendCommand(Uint8 cmd)\r
-{\r
-       mouseOut64(0xD4);\r
-       mouseOut60(cmd);\r
-}\r
-\r
-void PS2Mouse_Enable(void)\r
-{\r
-       Uint8   status;\r
-       Log_Log("PS2Mouse", "Enabling Mouse...");\r
-       \r
-       // Enable AUX PS/2\r
-       mouseOut64(0xA8);\r
-       \r
-       // Enable AUX PS/2 (Compaq Status Byte)\r
-       mouseOut64(0x20);       // Send Command\r
-       status = mouseIn60();   // Get Status\r
-       status &= ~0x20;        // Clear "Disable Mouse Clock"\r
-       status |= 0x02;         // Set IRQ12 Enable\r
-       mouseOut64(0x60);       // Send Command\r
-       mouseOut60(status);     // Set Status\r
-       \r
-       //mouseSendCommand(0xF6);       // Set Default Settings\r
-       mouseSendCommand(0xF4); // Enable Packets\r
-}\r

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