*/
#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 ===
// === 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)
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;
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);
// 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);
*/
struct sUSBHub
{
- tUSBDevice *Device;
-
- tUSB_HubPoll CheckPorts;
+ tUSBInterface *Interface;
int nPorts;
tUSBDevice *Devices[];
struct sUSBEndpoint
{
- tUSBInterface *Interface;
tUSBEndpoint *Next; // In the poll list
+ tUSBInterface *Interface;
+ int EndpointNum;
+
int PollingPeriod; // In 1ms intervals
int MaxPacketSize; // In bytes
Uint8 AddressBitmap[128/8];
tUSBDevice RootHubDev;
+ tUSBInterface RootHubIf;
tUSBHub RootHub;
};