X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FUSB%2FCore%2Fusb.c;h=b3195804c129892969048d4ea29e7c87e1ce11f2;hb=4c717bb526a0a7b1aa44ed7fc4f07a6b7da5d2f9;hp=ab9a48940e8748ae31839a6ed34eb0b2bdb84396;hpb=1474ce5c1ba164bbccfefa411883805d12a0dc62;p=tpg%2Facess2.git diff --git a/Modules/USB/Core/usb.c b/Modules/USB/Core/usb.c index ab9a4894..b3195804 100644 --- a/Modules/USB/Core/usb.c +++ b/Modules/USB/Core/usb.c @@ -1,6 +1,9 @@ /* - * Acess 2 USB Stack - * USB Packet Control + * Acess2 USB Stack + * - By John Hodge (thePowersGang) + * + * usb.c + * - USB Structure */ #define DEBUG 1 #include @@ -8,23 +11,98 @@ #include #include "usb.h" +// === IMPORTS === +extern tUSBHost *gUSB_Hosts; +extern tUSBDriver gUSBHub_Driver; + +// === STRUCTURES === + +// === PROTOTYPES === +tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts); + +// === GLOBALS === +tUSBDriver *gpUSB_InterfaceDrivers = &gUSBHub_Driver; // === CODE === -void USB_RegisterHost(tUSBHost *HostDef, void *ControllerPtr) +tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts) { - // TODO: + tUSBHost *host; + + host = malloc(sizeof(tUSBHost) + nPorts*sizeof(void*)); + if(!host) { + // Oh, bugger. + return NULL; + } + host->HostDef = HostDef; + host->Ptr = ControllerPtr; + memset(host->AddressBitmap, 0, sizeof(host->AddressBitmap)); + + host->RootHubDev.ParentHub = NULL; + host->RootHubDev.Host = host; + host->RootHubDev.Address = 0; + +// 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); + + // TODO: Lock + host->Next = gUSB_Hosts; + gUSB_Hosts = host; + + return &host->RootHub; } -int USB_int_SendSetupSetAddress(tUSBHost *Host, void *Ptr, int Address) +// --- Drivers --- +void USB_RegisterDriver(tUSBDriver *Driver) { - Uint8 data[8]; - data[0] = 0; // bmRequestType - data[1] = 5; // SET_ADDRESS - data[2] = Address & 0x7F; // wValue (low) - data[3] = 0; // wValue (high) - data[4] = 0; // wLength - data[6] = 0; // wLength + Log_Warning("USB", "TODO: Implement USB_RegisterDriver"); +} + +tUSBDriver *USB_int_FindDriverByClass(Uint32 ClassCode) +{ + ENTER("xClassCode", ClassCode); + for( tUSBDriver *ret = gpUSB_InterfaceDrivers; ret; ret = ret->Next ) + { + LOG(" 0x%x & 0x%x == 0x%x?", ClassCode, ret->Match.Class.ClassMask, ret->Match.Class.ClassCode); + if( (ClassCode & ret->Match.Class.ClassMask) == ret->Match.Class.ClassCode ) + { + LOG("Found '%s'", ret->Name); + LEAVE('p', ret); + return ret; + } + } + LEAVE('n'); + return NULL; +} + +// --- Hub Registration --- +// NOTE: Doesn't do much nowdays +tUSBHub *USB_RegisterHub(tUSBInterface *Device, int PortCount) +{ + tUSBHub *ret; - // Addr 0:0, Data Toggle = 0, no interrupt - return Host->SendSETUP(Ptr, 0, 0, 0, FALSE, data, 8) == NULL; + ret = malloc(sizeof(tUSBHub) + sizeof(ret->Devices[0])*PortCount); + ret->Interface = Device; + ret->nPorts = PortCount; + memset(ret->Devices, 0, sizeof(ret->Devices[0])*PortCount); + return ret; } + +void USB_RemoveHub(tUSBHub *Hub) +{ + for( int i = 0; i < Hub->nPorts; i ++ ) + { + if( Hub->Devices[i] ) + { + USB_DeviceDisconnected( Hub, i ); + } + } + free(Hub); +} +