Kernel/PTYs - Add initial dims/mode to PTY_Create
[tpg/acess2.git] / KernelLand / Modules / USB / HID / main.c
index 68e301e..c280273 100644 (file)
@@ -5,13 +5,14 @@
  * main.c
  * - Driver Core
  */
-#define DEBUG  1
+#define DEBUG  0
 #define VERSION        VER2(0,1)
 #include <acess.h>
 #include <modules.h>
 #include <usb_core.h>
 #include "hid.h"
 #include "hid_reports.h"
+#include <fs_devfs.h>
 
 // === TYPES ===
 typedef struct sHID_Device     tHID_Device;
@@ -23,6 +24,10 @@ struct sHID_Device
        // ... Device-specific data
 };
 
+// === IMPORTS ===
+extern tHID_ReportCallbacks    gHID_Mouse_ReportCBs;
+extern tHID_ReportCallbacks    gHID_Kb_ReportCBs;
+
 // === PROTOTYPES ===
  int   HID_Initialise(char **Arguments);
 void   HID_InterruptCallback(tUSBInterface *Dev, int EndPt, int Length, void *Data);
@@ -35,7 +40,7 @@ static void   _AddItems(struct sHID_IntList *List, Uint32 First, Uint32 Last);
 static void    _FreeList(struct sHID_IntList *List);
 
 // === GLOBALS ===
-MODULE_DEFINE(0, VERSION, USB_HID, HID_Initialise, NULL, "USB_Core", NULL);
+MODULE_DEFINE(0, VERSION, USB_HID, HID_Initialise, NULL, "USB_Core", "Keyboard", "Mouse", NULL);
 tUSBDriver     gHID_USBDriver = {
        .Name = "HID",
        .Match = {.Class = {0x030000, 0xFF0000}},
@@ -54,6 +59,7 @@ tHID_ReportCallbacks  gHID_RootCallbacks = {
 int HID_Initialise(char **Arguments)
 {
        USB_RegisterDriver( &gHID_USBDriver );
+       
        return 0;
 }
 
@@ -71,7 +77,8 @@ void HID_InterruptCallback(tUSBInterface *Dev, int EndPt, int Length, void *Data
                Log_Error("USB HID", "Device %p doesn't have a data pointer.", Dev);
                return ;
        }
-       
+
+       LOG("Data for %p", info->DataAvail);    
        info->DataAvail(Dev, EndPt, Length, Data);
 }
 
@@ -142,10 +149,23 @@ void HID_DeviceConnected(tUSBInterface *Dev, void *Descriptors, size_t Descripto
        
        // --- Read and parse report descriptor ---
        // NOTE: Also does sub-driver selection and initialisation
-       Uint8   *report_data = alloca(report_len);
+       Uint8   report_data[report_len];
        USB_ReadDescriptor(Dev, 0x1022, 0, report_len, report_data);
        HID_int_ParseReport(Dev, report_data, report_len, &gHID_RootCallbacks);
        
+       // --- Start polling ---
+       // Only if the device was initialised
+       if( USB_GetDeviceDataPtr(Dev) )
+       {
+               // Poll Endpoint .+1 (interupt)
+               USB_StartPollingEndpoint(Dev, 1);
+       }
+       else
+       {
+               Log_Log("USB_HID", "Device not intitialised");
+       }
+       
+       
        LEAVE('-');
 }
 
@@ -178,19 +198,19 @@ tHID_ReportCallbacks *HID_RootCollection(
                        break;
                case 0x0002:    // Mouse
                        LOG("Desktop->Mouse");
-                       break;
+                       return &gHID_Mouse_ReportCBs;
                case 0x0004:    // Joystick
                case 0x0005:    // Game Pad
                        LOG("Desktop->Gamepad");
                        break;
                case 0x0006:    // Keyboard
                        LOG("Desktop->Keyboard");
-                       break;
+                       return &gHID_Kb_ReportCBs;
                }
                break;
        case 0x0007:    // Keyboard / Keypad
                LOG("Keyboard");
-               break;
+               return &gHID_Kb_ReportCBs;
        }
        return NULL;
 }
@@ -275,7 +295,7 @@ void HID_int_ParseReport(tUSBInterface *Dev, Uint8 *Data, size_t Length, tHID_Re
                        else
                                next_cbs = NULL;
                        cur_cbs = next_cbs;
-                       break;
+                       goto _clear_local;
                // - Feature
                case 0xB0:
                        LOG("Feature 0x%x", val);
@@ -321,14 +341,17 @@ void HID_int_ParseReport(tUSBInterface *Dev, Uint8 *Data, size_t Length, tHID_Re
                // - Usages
                case 0x08:      // Single
                        if( (byte & 3) != 3 )   val |= global_state.UsagePage;
+                       LOG("Usage %x", val);
                        _AddItem(&local_state.Usages, val);
                        break;
                case 0x18:      // Range start
                        if( (byte & 3) != 3 )   val |= global_state.UsagePage;
+                       LOG("Usage start %x", val);
                        local_state.UsageMin = val;
                        break;
                case 0x28:      // Range end (apply)
                        if( (byte & 3) != 3 )   val |= global_state.UsagePage;
+                       LOG("Usage end %x (from %x)", val, local_state.UsageMin);
                        _AddItems(&local_state.Usages, local_state.UsageMin, val);
                        break;
                // - Designators (Index into Physical report)
@@ -384,6 +407,7 @@ static void _AddItem(struct sHID_IntList *List, Uint32 Value)
                List->Items = realloc( List->Items, List->Space * sizeof(List->Items[0]) );
        }
        
+//     LOG("Added %x to %p", Value, List);
        List->Items[ List->nItems ] = Value;
        List->nItems ++;
 }

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