X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FUSB%2FCore%2Fhub.c;h=08295b1f2233e3a7a09040b24c4628663eb12740;hb=9c8d1751ca2eb1470a1707e42896262d19efe31d;hp=22fed9dd912afb0088f4090bae83227b8673075d;hpb=3e39f3e998538521830c10da09fe14c7a7dc66bd;p=tpg%2Facess2.git diff --git a/Modules/USB/Core/hub.c b/Modules/USB/Core/hub.c index 22fed9dd..08295b1f 100644 --- a/Modules/USB/Core/hub.c +++ b/Modules/USB/Core/hub.c @@ -9,6 +9,14 @@ #define MAX_PORTS 32 // Not actually a max, but used for DeviceRemovable +#define GET_STATUS 0 +#define SET_FEATURE 3 + +#define PORT_CONNECTION 0 +#define PORT_ENABLE 1 +#define PORT_RESET 4 +#define PORT_POWER 8 + struct sHubDescriptor { Uint8 DescLength; @@ -26,12 +34,13 @@ struct sHubInfo int PowerOnDelay; // in ms int nPorts; Uint8 DeviceRemovable[]; -} +}; // === PROTOTYPES === void Hub_Connected(tUSBInterface *Dev); void Hub_Disconnected(tUSBInterface *Dev); void Hub_PortStatusChange(tUSBInterface *Dev, int Length, void *Data); +void Hub_int_HandleChange(tUSBInterface *Dev, int Port); // === GLOBALS === tUSBDriver gUSBHub_Driver = { @@ -42,17 +51,28 @@ tUSBDriver gUSBHub_Driver = { .MaxEndpoints = 1, .Endpoints = { {0x83, Hub_PortStatusChange} - }; + } }; // === CODE === +#if 0 +int Hub_DriverInitialise(char **Arguments) +{ + USB_RegisterDriver( &gUSBHub_Driver ); + return 0; +} +#endif + void Hub_Connected(tUSBInterface *Dev) { struct sHubDescriptor hub_desc; struct sHubInfo *info; // Read hub descriptor - USB_ReadDescriptor(Dev, 0x29, 0, sizeof(*hub_desc), hub_desc); + USB_ReadDescriptor(Dev, 0x29, 0, sizeof(hub_desc), &hub_desc); + + LOG("%i Ports", hub_desc.NbrPorts); + LOG("Takes %i ms for power to stabilise", hub_desc.PwrOn2PwrGood*2); // Allocate infomation structure info = malloc(sizeof(*info) + (hub_desc.NbrPorts+7)/8); @@ -75,7 +95,9 @@ void Hub_Connected(tUSBInterface *Dev) void Hub_Disconnected(tUSBInterface *Dev) { - USB_RemoveHub(Dev); + struct sHubInfo *info = USB_GetDeviceDataPtr(Dev); + USB_RemoveHub(info->HubPtr); + free(info); } void Hub_PortStatusChange(tUSBInterface *Dev, int Length, void *Data) @@ -96,11 +118,32 @@ void Hub_PortStatusChange(tUSBInterface *Dev, int Length, void *Data) void Hub_int_HandleChange(tUSBInterface *Dev, int Port) { + struct sHubInfo *info = USB_GetDeviceDataPtr(Dev); Uint16 status[2]; // Status, Change // Get port status - USB_Request(Dev, 0, 0xA3, 0, 0, Port, 4, status); + USB_Request(Dev, 0, 0xA3, GET_STATUS, 0, Port, 4, status); // Handle connections / disconnections + if( status[1] & 0x0001 ) + { + if( status[0] & 0x0001 ) { + // Connected + // - Power on port + USB_Request(Dev, 0, 0x23, SET_FEATURE, PORT_POWER, Port, 0, NULL); + Time_Delay(info->PowerOnDelay); + // - Reset + USB_Request(Dev, 0, 0x23, SET_FEATURE, PORT_RESET, Port, 0, NULL); + Time_Delay(20); // Spec says 10ms after reset, but how long is reset? + // - Enable + USB_Request(Dev, 0, 0x23, SET_FEATURE, PORT_ENABLE, Port, 0, NULL); + // - Poke USB Stack + USB_DeviceConnected(info->HubPtr, Port); + } + else { + // Disconnected + USB_DeviceDisconnected(info->HubPtr, Port); + } + } }