Modules/USB - Cleaning up code
authorJohn Hodge <[email protected]>
Mon, 28 Nov 2011 12:13:09 +0000 (20:13 +0800)
committerJohn Hodge <[email protected]>
Mon, 28 Nov 2011 12:13:09 +0000 (20:13 +0800)
Modules/USB/Core/hub.c
Modules/USB/Core/usb.c
Modules/USB/Core/usb.h

index 4afde69..552ab96 100644 (file)
@@ -7,9 +7,17 @@
  */
 #include <usb_hub.h>
 
  */
 #include <usb_hub.h>
 
-struct sHubInfo
+#define MAX_PORTS      32      // Not actually a max, but used for DeviceRemovable
+
+struct sHubDescriptor
 {
 {
-        int    nPorts;
+       Uint8   DescLength;
+       Uint8   DescType;       // = 0x29
+       Uint8   NbrPorts;
+       Uint16  HubCharacteristics;
+       Uint8   PwrOn2PwrGood;  // 2 ms intervals
+       Uint8   HubContrCurrent;        // Max internal current (mA)
+       Uint8   DeviceRemovable[MAX_PORTS];
 };
 
 // === PROTOTYPES ===
 };
 
 // === PROTOTYPES ===
@@ -32,10 +40,21 @@ tUSBDriver  gUSBHub_Driver = {
 // === CODE ===
 void Hub_Connected(tUSBInterface *Dev)
 {
 // === CODE ===
 void Hub_Connected(tUSBInterface *Dev)
 {
+       struct sHubDescriptor   *hub_desc;
+       
+       hub_desc = malloc(sizeof(*hub_desc));
+       if(!hub_desc) {
+               Log_Error("USBHub", "malloc() failed");
+               return ;
+       }
+       USB_SetDeviceDataPtr(Dev, hub_desc);
+
+       USB_ReadDescriptor(Dev, 0, 0x29, 0, sizeof(hub_desc), hub_desc);
+
        // Register poll on endpoint
        // Register poll on endpoint
-       USB_PollEndpoint(Dev, 0);
+       USB_PollEndpoint(Dev, 1);
        
        
-       USB_RegisterHub(Dev, nPorts);
+       USB_RegisterHub(Dev, hub_desc->NbrPorts);
 }
 
 void Hub_Disconnected(tUSBInterface *Dev)
 }
 
 void Hub_Disconnected(tUSBInterface *Dev)
@@ -44,9 +63,10 @@ void Hub_Disconnected(tUSBInterface *Dev)
 
 void Hub_PortStatusChange(tUSBInterface *Dev, int Length, void *Data)
 {
 
 void Hub_PortStatusChange(tUSBInterface *Dev, int Length, void *Data)
 {
-        int    i;
        Uint8   *status = Data;
        Uint8   *status = Data;
-       for( i = 0; i < info->nPorts; i += 8, status ++ )
+       struct sHubDescriptor   *info = USB_GetDeviceDataPtr(Dev);
+        int    i;
+       for( i = 0; i < info->NbrPorts; i += 8, status ++ )
        {
                if( i/8 >= Length )     break;
                if( *status == 0 )      continue;
        {
                if( i/8 >= Length )     break;
                if( *status == 0 )      continue;
index 7713435..f090f63 100644 (file)
@@ -41,15 +41,17 @@ tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts)
        host->Ptr = ControllerPtr;
        memset(host->AddressBitmap, 0, sizeof(host->AddressBitmap));
 
        host->Ptr = ControllerPtr;
        memset(host->AddressBitmap, 0, sizeof(host->AddressBitmap));
 
-//     host->RootHubDev.Next = NULL;
        host->RootHubDev.ParentHub = NULL;
        host->RootHubDev.Host = host;
        host->RootHubDev.Address = 0;
        host->RootHubDev.ParentHub = NULL;
        host->RootHubDev.Host = host;
        host->RootHubDev.Address = 0;
-//     host->RootHubDev.Driver = NULL;
-//     host->RootHubDev.Data = NULL;
 
 
-       host->RootHub.Device = &host->RootHubDev;
-       host->RootHub.CheckPorts = NULL;
+       host->RootHubIf.Next = NULL;
+       host->RootHubIf.Dev = &host->RootHubDev;
+       host->RootHubIf.Driver = NULL;
+       host->RootHubIf.Data = NULL;
+       host->RootHubIf.nEndpoints = 0;
+
+       host->RootHub.Interface = &host->RootHubIf;
        host->RootHub.nPorts = nPorts;
        memset(host->RootHub.Devices, 0, sizeof(void*)*nPorts);
 
        host->RootHub.nPorts = nPorts;
        memset(host->RootHub.Devices, 0, sizeof(void*)*nPorts);
 
@@ -72,12 +74,9 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port)
        
        // Create structure
        dev = malloc(sizeof(tUSBDevice));
        
        // Create structure
        dev = malloc(sizeof(tUSBDevice));
-//     dev->Next = NULL;
        dev->ParentHub = Hub;
        dev->ParentHub = Hub;
-       dev->Host = Hub->Device->Host;
+       dev->Host = Hub->Interface->Dev->Host;
        dev->Address = 0;
        dev->Address = 0;
-//     dev->Driver = 0;
-//     dev->Data = 0;
 
        // 1. Assign an address
        dev->Address = USB_int_AllocateAddress(dev->Host);
 
        // 1. Assign an address
        dev->Address = USB_int_AllocateAddress(dev->Host);
index c293c7d..9f4384d 100644 (file)
@@ -19,9 +19,7 @@ typedef struct sUSBEndpoint   tUSBEndpoint;
  */
 struct sUSBHub
 {
  */
 struct sUSBHub
 {
-       tUSBDevice      *Device;
-       
-       tUSB_HubPoll    CheckPorts;
+       tUSBInterface   *Interface;
        
         int    nPorts;
        tUSBDevice      *Devices[];
        
         int    nPorts;
        tUSBDevice      *Devices[];
@@ -29,8 +27,10 @@ struct sUSBHub
 
 struct sUSBEndpoint
 {
 
 struct sUSBEndpoint
 {
-       tUSBInterface   *Interface;
        tUSBEndpoint    *Next;  // In the poll list
        tUSBEndpoint    *Next;  // In the poll list
+       tUSBInterface   *Interface;
+        int    EndpointNum;
+       
         int    PollingPeriod;  // In 1ms intervals
         int    MaxPacketSize;  // In bytes
 
         int    PollingPeriod;  // In 1ms intervals
         int    MaxPacketSize;  // In bytes
 
@@ -81,6 +81,7 @@ struct sUSBHost
        Uint8   AddressBitmap[128/8];
        
        tUSBDevice      RootHubDev;
        Uint8   AddressBitmap[128/8];
        
        tUSBDevice      RootHubDev;
+       tUSBInterface   RootHubIf;
        tUSBHub RootHub;
 };
 
        tUSBHub RootHub;
 };
 

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