From: John Hodge Date: Mon, 28 Nov 2011 12:13:09 +0000 (+0800) Subject: Modules/USB - Cleaning up code X-Git-Tag: rel0.14~62 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=34c3e84b154675d1cef9098ba05b8b291241c37e;p=tpg%2Facess2.git Modules/USB - Cleaning up code --- diff --git a/Modules/USB/Core/hub.c b/Modules/USB/Core/hub.c index 4afde693..552ab96e 100644 --- a/Modules/USB/Core/hub.c +++ b/Modules/USB/Core/hub.c @@ -7,9 +7,17 @@ */ #include -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 === @@ -32,10 +40,21 @@ tUSBDriver gUSBHub_Driver = { // === 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 - USB_PollEndpoint(Dev, 0); + USB_PollEndpoint(Dev, 1); - USB_RegisterHub(Dev, nPorts); + USB_RegisterHub(Dev, hub_desc->NbrPorts); } void Hub_Disconnected(tUSBInterface *Dev) @@ -44,9 +63,10 @@ void Hub_Disconnected(tUSBInterface *Dev) void Hub_PortStatusChange(tUSBInterface *Dev, int Length, void *Data) { - int i; 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; diff --git a/Modules/USB/Core/usb.c b/Modules/USB/Core/usb.c index 7713435b..f090f634 100644 --- a/Modules/USB/Core/usb.c +++ b/Modules/USB/Core/usb.c @@ -41,15 +41,17 @@ tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts) 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.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); @@ -72,12 +74,9 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) // Create structure dev = malloc(sizeof(tUSBDevice)); -// dev->Next = NULL; dev->ParentHub = Hub; - dev->Host = Hub->Device->Host; + dev->Host = Hub->Interface->Dev->Host; dev->Address = 0; -// dev->Driver = 0; -// dev->Data = 0; // 1. Assign an address dev->Address = USB_int_AllocateAddress(dev->Host); diff --git a/Modules/USB/Core/usb.h b/Modules/USB/Core/usb.h index c293c7db..9f4384d9 100644 --- a/Modules/USB/Core/usb.h +++ b/Modules/USB/Core/usb.h @@ -19,9 +19,7 @@ typedef struct sUSBEndpoint tUSBEndpoint; */ struct sUSBHub { - tUSBDevice *Device; - - tUSB_HubPoll CheckPorts; + tUSBInterface *Interface; int nPorts; tUSBDevice *Devices[]; @@ -29,8 +27,10 @@ struct sUSBHub struct sUSBEndpoint { - tUSBInterface *Interface; tUSBEndpoint *Next; // In the poll list + tUSBInterface *Interface; + int EndpointNum; + int PollingPeriod; // In 1ms intervals int MaxPacketSize; // In bytes @@ -81,6 +81,7 @@ struct sUSBHost Uint8 AddressBitmap[128/8]; tUSBDevice RootHubDev; + tUSBInterface RootHubIf; tUSBHub RootHub; };