3 * - By John Hodge (thePowersGang)
10 #define MAX_PORTS 32 // Not actually a max, but used for DeviceRemovable
15 Uint8 DescType; // = 0x29
17 Uint16 HubCharacteristics;
18 Uint8 PwrOn2PwrGood; // 2 ms intervals
19 Uint8 HubContrCurrent; // Max internal current (mA)
20 Uint8 DeviceRemovable[MAX_PORTS];
24 void Hub_Connected(tUSBInterface *Dev);
25 void Hub_Disconnected(tUSBInterface *Dev);
26 void Hub_PortStatusChange(tUSBInterface *Dev, int Length, void *Data);
29 tUSBDriver gUSBHub_Driver = {
31 .Match = {.Class = {0x090000, 0xFF0000}},
32 .Connected = Hub_Connected,
33 .Disconnected = Hub_Disconnected,
36 {0x83, Hub_PortStatusChange}
41 void Hub_Connected(tUSBInterface *Dev)
43 struct sHubDescriptor *hub_desc;
45 hub_desc = malloc(sizeof(*hub_desc));
47 Log_Error("USBHub", "malloc() failed");
50 USB_SetDeviceDataPtr(Dev, hub_desc);
52 USB_ReadDescriptor(Dev, 0, 0x29, 0, sizeof(hub_desc), hub_desc);
54 // Register poll on endpoint
55 USB_PollEndpoint(Dev, 1);
57 USB_RegisterHub(Dev, hub_desc->NbrPorts);
60 void Hub_Disconnected(tUSBInterface *Dev)
64 void Hub_PortStatusChange(tUSBInterface *Dev, int Length, void *Data)
67 struct sHubDescriptor *info = USB_GetDeviceDataPtr(Dev);
69 for( i = 0; i < info->NbrPorts; i += 8, status ++ )
71 if( i/8 >= Length ) break;
72 if( *status == 0 ) continue;
74 for( int j = 0; j < 8; j ++ )
75 if( *status & (1 << j) )
76 Hub_int_HandleChange(Dev, i+j);
80 void Hub_int_HandleChange(tUSBInterface *Dev, int Port)
82 Uint16 status[2]; // Status, Change
84 USB_Request(Dev, 0, 0xA3, 0, 0, Port, 4, status);