//***************************************************************************** // //! This function is used to open an instance of the CDC driver. //! //! \param pDevice is a pointer to the device information structure. //! //! This function will attempt to open an instance of the CDC driver based on //! the information contained in the pDevice structure. This call can fail if //! there are not sufficient resources to open the device. The function will //! return a value that should be passed back into USBCDCClose() when the //! driver is no longer needed. //! //! \return The function will return a pointer to a CDC driver instance. // //***************************************************************************** static void * USBHCDCOpen(tUSBHostDevice *psDevice) { //printf("USBHCDCOpen: Start\n"); int32_t i32Idx, i32Idz; tEndpointDescriptor *psEndpointDescriptor; tInterfaceDescriptor *psInterface; // // Don't allow the device to be opened without closing first. // if(g_USBHCDCDevice.psDevice) { //printf("USBHCDCOpen: For Loop: i32Idx, %d\n", i32Idx); return(0); } // // Save the device pointer. // g_USBHCDCDevice.psDevice = psDevice; // // Loop Through the first 3 Interfaces Searching for Endpoints // for(i32Idz = 0; i32Idz < 3; i32Idz++) { // // Get the interface descriptor. // psInterface = USBDescGetInterface(psDevice->psConfigDescriptor, i32Idz, 0); // // Loop through the endpoints of the device. // bNumEndPoints returning 1, should be 3 - will set manually, as there is always 3...then it works!!! // for(i32Idx = 0; i32Idx < 3; i32Idx++) //psInterface->bNumEndpoints; i32Idx++) { // // Get the first endpoint descriptor. // psEndpointDescriptor = USBDescGetInterfaceEndpoint(psInterface, i32Idx, psDevice->ui32ConfigDescriptorSize); //System_printf("USBHCDCOpen: psEndPointDecriptor: %d bmAttribute: %d\n", psEndpointDescriptor, psEndpointDescriptor->bmAttributes); //System_flush(); // // If no more endpoints then break out. // if(psEndpointDescriptor == 0) { break; } // // See if this is an Interrupt endpoint. // if((psEndpointDescriptor->bmAttributes & USB_EP_ATTR_TYPE_M) == USB_EP_ATTR_INT) { // // Interrupt IN. // if(psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_IN) { g_USBHCDCDevice.ui32IntInPipe = USBHCDPipeAlloc(0, USBHCD_PIPE_INTR_IN, psDevice, USBHCDCInterruptCallback); USBHCDPipeConfig(g_USBHCDCDevice.ui32IntInPipe, psEndpointDescriptor->wMaxPacketSize, psEndpointDescriptor->bInterval, (psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_NUM_M)); //System_printf("USBHCDCOpen: Allocated and Configured Interrupt In Endpoint: Interface Index: %d bEndPointAddress: %d ui32BulkOutPipe: %d\n", i32Idz, psEndpointDescriptor->bEndpointAddress, g_USBHCDCDevice.ui32IntInPipe); //System_flush(); } } // // See if this is a bulk endpoint. // if((psEndpointDescriptor->bmAttributes & USB_EP_ATTR_TYPE_M) == USB_EP_ATTR_BULK) { // // See if this is bulk IN or bulk OUT or Interrupt // //if((psEndpointDescriptor->bmAttributes & USB_EP_ATTR_INT) == USB_EP_ATTR_INT) //{ // // // // Allocate the USB Pipe for this Bulk IN Interrupt endpoint. // // // g_USBHCDCDevice.ui32BulkInPipe = // USBHCDPipeAllocSize(0, USBHCD_PIPE_BULK_IN, // psDevice, // psEndpointDescriptor->wMaxPacketSize, // USBHCDCInterruptCallback); // // // // Configure the USB pipe as a Bulk IN endpoint. // // // USBHCDPipeConfig(g_USBHCDCDevice.ui32BulkInPipe, // psEndpointDescriptor->wMaxPacketSize, // 1, // (psEndpointDescriptor->bEndpointAddress & // USB_EP_DESC_NUM_M)); // // System_printf("USBHCDCOpen: Allocated and Configured Interrupt EndPoint**: Interface Index: %d bEndPointAddress: %d ui32BulkOutPipe: %d\n", i32Idz, psEndpointDescriptor->bEndpointAddress, g_USBHCDCDevice.ui32BulkOutPipe); // System_flush(); // // } if(psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_IN) { // // Allocate the USB Pipe for this Bulk IN endpoint. // g_USBHCDCDevice.ui32BulkInPipe = USBHCDPipeAllocSize(0, USBHCD_PIPE_BULK_IN, psDevice, psEndpointDescriptor->wMaxPacketSize, USBHCDCINCallback); // // Configure the USB pipe as a Bulk IN endpoint. // USBHCDPipeConfig(g_USBHCDCDevice.ui32BulkInPipe, psEndpointDescriptor->wMaxPacketSize, 64, (psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_NUM_M)); //System_printf("USBHCDCOpen: Allocated and Configured Bulk In EndPoint: Interface Index: %d bEndPointAddress: %d ui32BulkOutPipe: %d\n", i32Idz, psEndpointDescriptor->bEndpointAddress, g_USBHCDCDevice.ui32BulkOutPipe); //System_flush(); } else { // // Allocate the USB Pipe for this Bulk OUT endpoint. // g_USBHCDCDevice.ui32BulkOutPipe = USBHCDPipeAllocSize(0, USBHCD_PIPE_BULK_OUT, psDevice, psEndpointDescriptor->wMaxPacketSize, 0); // // Configure the USB pipe as a Bulk OUT endpoint. // USBHCDPipeConfig(g_USBHCDCDevice.ui32BulkOutPipe, psEndpointDescriptor->wMaxPacketSize, 0, (psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_NUM_M)); //System_printf("USBHCDCOpen: Allocated and Configured Bulk Out EndPoint: Interface Index: %d bEndPointAddress: %d ui32BulkOutPipe: %d\n", i32Idz, psEndpointDescriptor->bEndpointAddress, g_USBHCDCDevice.ui32BulkOutPipe); //System_flush(); } } } } // // If there is a callback function call it to inform the application that // the device has been enumerated. // // To be used with the RTOS callback handler example. // // if(g_USBCDCDevice.pfnCallback != 0) // { // g_psHIDDevice[i32Dev].pfnCallback( // g_psHIDDevice[i32Dev].pvCBData, // USB_EVENT_CONNECTED, // (uint32_t)&g_psHIDDevice[i32Dev], 0); // } // // If the callback exists, call it with an Open event. // if(g_USBHCDCDevice.pfnCallback != 0) { // printf("USBHCDCOpen: Callback Exists: Calling\n"); // System_flush(); g_USBHCDCDevice.pfnCallback(&g_USBHCDCDevice, CDC_EVENT_OPEN, 0, 0); } // // Return the only instance of this device. // return(&g_USBHCDCDevice); }
//***************************************************************************** // //! This function is used to open an instance of the HID driver. //! //! \param psDevice is a pointer to the device information structure. //! //! This function will attempt to open an instance of the HID driver based on //! the information contained in the psDevice structure. This call can fail if //! there are not sufficient resources to open the device. The function will //! return a value that should be passed back into USBHIDClose() when the //! driver is no longer needed. //! //! \return The function will return a pointer to a HID driver instance. // //***************************************************************************** static void * HIDDriverOpen(tUSBHostDevice *psDevice) { int32_t i32Idx, i32Dev; tEndpointDescriptor *psEndpointDescriptor; tInterfaceDescriptor *psInterface; // // Get the interface descriptor. // psInterface = USBDescGetInterface(psDevice->psConfigDescriptor, 0, 0); // // Search the currently open instances for one that supports the protocol // of this device. // for(i32Dev = 0; i32Dev < MAX_HID_DEVICES; i32Dev++) { if(g_psHIDDevice[i32Dev].iDeviceType == psInterface->bInterfaceProtocol) { // // Save the device pointer. // g_psHIDDevice[i32Dev].psDevice = psDevice; for(i32Idx = 0; i32Idx < 3; i32Idx++) { // // Get the first endpoint descriptor. // psEndpointDescriptor = USBDescGetInterfaceEndpoint(psInterface, i32Idx, 256); // // If no more endpoints then break out. // if(psEndpointDescriptor == 0) { break; } // // Interrupt // if((psEndpointDescriptor->bmAttributes & USB_EP_ATTR_TYPE_M) == USB_EP_ATTR_INT) { // // Interrupt IN. // if(psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_IN) { g_psHIDDevice[i32Dev].ui32IntInPipe = USBHCDPipeAlloc(0, USBHCD_PIPE_INTR_IN, psDevice, HIDIntINCallback); USBHCDPipeConfig(g_psHIDDevice[i32Dev].ui32IntInPipe, psEndpointDescriptor->wMaxPacketSize, psEndpointDescriptor->bInterval, (psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_NUM_M)); } } } // // If there is a callback function call it to inform the application that // the device has been enumerated. // if(g_psHIDDevice[i32Dev].pfnCallback != 0) { g_psHIDDevice[i32Dev].pfnCallback( g_psHIDDevice[i32Dev].pvCBData, USB_EVENT_CONNECTED, (uint32_t)&g_psHIDDevice[i32Dev], 0); } // // Save the device pointer. // g_psHIDDevice[i32Dev].psDevice = psDevice; return (&g_psHIDDevice[i32Dev]); } } // // If we get here, no user has registered an interest in this particular // HID device so we return an error. // return(0); }
//***************************************************************************** // //! This function is used to open an instance of the HID driver. //! //! \param pDevice is a pointer to the device information structure. //! //! This function will attempt to open an instance of the HID driver based on //! the information contained in the pDevice structure. This call can fail if //! there are not sufficient resources to open the device. The function will //! return a value that should be passed back into USBHIDClose() when the //! driver is no longer needed. //! //! \return The function will return a pointer to a HID driver instance. // //***************************************************************************** static void * HIDDriverOpen(tUSBHostDevice *pDevice) { int iIdx; tEndpointDescriptor *pEndpointDescriptor; tInterfaceDescriptor *pInterface; // // Don't allow the device to be opened without closing first. // if(g_HIDDevice.pDevice) { return (0); } // // Get the interface descriptor. // pInterface = USBDescGetInterface(pDevice->pConfigDescriptor, 0, 0); if((pInterface->bInterfaceSubClass != USB_HID_SCLASS_BOOT) || (pInterface->bInterfaceProtocol != g_HIDDevice.eDeviceType)) { return(0); } // // Save the device pointer. // g_HIDDevice.pDevice = pDevice; for(iIdx = 0; iIdx < 3; iIdx++) { // // Get the first endpoint descriptor. // pEndpointDescriptor = USBDescGetInterfaceEndpoint(pInterface, iIdx, 256); // // If no more endpoints then break out. // if(pEndpointDescriptor == 0) { break; } // // Interrupt // if((pEndpointDescriptor->bmAttributes & USB_EP_ATTR_TYPE_M) == USB_EP_ATTR_INT) { // // Interrupt IN. // if(pEndpointDescriptor->bEndpointAddress & USB_EP_DESC_IN) { g_HIDDevice.ulIntInPipe = USBHCDPipeAlloc(0, USBHCD_PIPE_INTR_IN, pDevice->ulAddress, HIDIntINCallback); USBHCDPipeConfig(g_HIDDevice.ulIntInPipe, pEndpointDescriptor->wMaxPacketSize, pEndpointDescriptor->bInterval, (pEndpointDescriptor->bEndpointAddress & USB_EP_DESC_NUM_M)); } } } // // If there is a callback function call it to inform the application that // the device has been enumerated. // if(g_HIDDevice.pfnCallback != 0) { g_HIDDevice.pfnCallback((void *)g_HIDDevice.ulCBData, USB_EVENT_CONNECTED, (unsigned long)&g_HIDDevice, 0); } // // Save the device pointer. // g_HIDDevice.pDevice = pDevice; return (&g_HIDDevice); }
//***************************************************************************** // //! This function is used to open an instance of the MSC driver. //! //! \param pDevice is a pointer to the device information structure. //! //! This function will attempt to open an instance of the MSC driver based on //! the information contained in the pDevice structure. This call can fail if //! there are not sufficient resources to open the device. The function will //! return a value that should be passed back into USBMSCClose() when the //! driver is no longer needed. //! //! \return The function will return a pointer to a MSC driver instance. // //***************************************************************************** static void * USBHMSCOpen(tUSBHostDevice *pDevice) { long lIdx; tEndpointDescriptor *pEndpointDescriptor; tInterfaceDescriptor *pInterface; // // Don't allow the device to be opened without closing first. // if(g_USBHMSCDevice.pDevice) { return(0); } // // Save the device pointer. // g_USBHMSCDevice.pDevice = pDevice; // // Get the interface descriptor. // pInterface = USBDescGetInterface(pDevice->pConfigDescriptor, 0, 0); // // Loop through the endpoints of the device. // for(lIdx = 0; lIdx < 3; lIdx++) { // // Get the first endpoint descriptor. // pEndpointDescriptor = USBDescGetInterfaceEndpoint(pInterface, lIdx, pDevice->ulConfigDescriptorSize); // // If no more endpoints then break out. // if(pEndpointDescriptor == 0) { break; } // // See if this is a bulk endpoint. // if((pEndpointDescriptor->bmAttributes & USB_EP_ATTR_TYPE_M) == USB_EP_ATTR_BULK) { // // See if this is bulk IN or bulk OUT. // if(pEndpointDescriptor->bEndpointAddress & USB_EP_DESC_IN) { // // Allocate the USB Pipe for this Bulk IN endpoint. // g_USBHMSCDevice.ulBulkInPipe = USBHCDPipeAllocSize(0, USBHCD_PIPE_BULK_IN_DMA, pDevice->ulAddress, pEndpointDescriptor->wMaxPacketSize, 0); // // Configure the USB pipe as a Bulk IN endpoint. // USBHCDPipeConfig(g_USBHMSCDevice.ulBulkInPipe, pEndpointDescriptor->wMaxPacketSize, 0, (pEndpointDescriptor->bEndpointAddress & USB_EP_DESC_NUM_M)); } else { // // Allocate the USB Pipe for this Bulk OUT endpoint. // g_USBHMSCDevice.ulBulkOutPipe = USBHCDPipeAllocSize(0, USBHCD_PIPE_BULK_OUT_DMA, pDevice->ulAddress, pEndpointDescriptor->wMaxPacketSize, 0); // // Configure the USB pipe as a Bulk OUT endpoint. // USBHCDPipeConfig(g_USBHMSCDevice.ulBulkOutPipe, pEndpointDescriptor->wMaxPacketSize, 0, (pEndpointDescriptor->bEndpointAddress & USB_EP_DESC_NUM_M)); } } } // // If the callback exists, call it with an Open event. // if(g_USBHMSCDevice.pfnCallback != 0) { g_USBHMSCDevice.pfnCallback((unsigned long)&g_USBHMSCDevice, MSC_EVENT_OPEN, 0); } // // Return the only instance of this device. // return(&g_USBHMSCDevice); }
//***************************************************************************** // //! This function is used to open an instance of the ANDROID driver and configure it as Open Accessory. //! //! \param pDevice is a pointer to the device information structure. //! //! This function will attempt to open an instance of the ANDROID driver based on //! the information contained in the pDevice structure. This call can fail if //! there are not sufficient resources to open the device. The function will //! return a value that should be passed back into USBANDROIDClose() when the //! driver is no longer needed. //! //! \return The function will return a pointer to a ANDROID driver instance. // //***************************************************************************** static void * USBHANDROIDOpen(tUSBHostDevice *pDevice) { int iIdx; tEndpointDescriptor *pEndpointDescriptor; tInterfaceDescriptor *pInterface; UARTprintf("\nStart USBHANDROIDOpen Time=%d\n", g_ulSysTickCount); /* For Debug purpose you can also list full Configuration Descriptor & Device Descriptor */ getConfigDesc(pDevice); getDeviceDesc(pDevice); /* UARTprintf("Start pDevice->pConfigDescriptor details Time=%d:\n", g_ulSysTickCount); UARTprintf(" bLength=0x%02X (shall be 0x09)\n", pDevice->pConfigDescriptor->bLength); UARTprintf(" wTotalLength=0x%04X\n", pDevice->pConfigDescriptor->wTotalLength); UARTprintf(" bDescriptorType=0x%02X\n", pDevice->pConfigDescriptor->bDescriptorType); UARTprintf(" bNumInterfaces=0x%02X\n", pDevice->pConfigDescriptor->bNumInterfaces); UARTprintf(" bConfigurationValue=0x%02X\n", pDevice->pConfigDescriptor->bConfigurationValue); UARTprintf(" iConfiguration=0x%02X\n", pDevice->pConfigDescriptor->iConfiguration); UARTprintf(" bmAttributes=0x%02X\n", pDevice->pConfigDescriptor->bmAttributes); UARTprintf(" bMaxPower=0x%02X (unit of 2mA)\n\n", pDevice->pConfigDescriptor->bMaxPower); UARTprintf("pDevice->DeviceDescriptor details:\n"); UARTprintf(" bLength=0x%02X (shall be 0x12)\n", pDevice->DeviceDescriptor.bLength); UARTprintf(" bDescriptorType=0x%02X\n", pDevice->DeviceDescriptor.bDescriptorType); UARTprintf(" bcdUSB=0x%02X (USB2.0=0x200)\n", pDevice->DeviceDescriptor.bcdUSB); UARTprintf(" bDeviceClass=0x%02X\n", pDevice->DeviceDescriptor.bDeviceClass); UARTprintf(" bDeviceSubClass=0x%02X\n", pDevice->DeviceDescriptor.bDeviceSubClass); UARTprintf(" bDeviceProtocol=0x%02X\n", pDevice->DeviceDescriptor.bDeviceProtocol); UARTprintf(" bMaxPacketSize0=0x%02X\n", pDevice->DeviceDescriptor.bMaxPacketSize0); UARTprintf(" idVendor=0x%02X\n", pDevice->DeviceDescriptor.idVendor); UARTprintf(" idProduct=0x%02X\n", pDevice->DeviceDescriptor.idProduct); UARTprintf(" bcdDevice=0x%02X\n", pDevice->DeviceDescriptor.bcdDevice); UARTprintf(" iManufacturer=0x%02X\n", pDevice->DeviceDescriptor.iManufacturer); UARTprintf(" iProduct=0x%02X\n", pDevice->DeviceDescriptor.iProduct); UARTprintf(" iSerialNumber=0x%02X\n", pDevice->DeviceDescriptor.iSerialNumber); UARTprintf(" bNumConfigurations=0x%02X\n", pDevice->DeviceDescriptor.bNumConfigurations); UARTprintf("End pDevice->pConfigDescriptor details Time=%d:\n\n", g_ulSysTickCount); */ // Don't allow the device to be opened without closing first. if(g_USBHANDROIDDevice.pDevice) { UARTprintf("\nUSBHANDROIDOpen return 0 device already opened\n"); return(0); } // Save the device pointer. g_USBHANDROIDDevice.pDevice = pDevice; // Save the callback. // The CallBack is the driver callback for any Android ADK events. // // This function is called to open an instance of an android device. It // should be called before any devices are connected to allow for proper // notification of android connection and disconnection. The // application should also provide the \e pfnCallback to be notified of Andoid // ADK related events like device enumeration and device removal. g_USBHANDROIDDevice.pfnCallback = USBHANDROIDCallback; /* Check Android Accessory device */ if (isAccessoryDevice(&pDevice->DeviceDescriptor)) { UARTprintf("Found Android Accessory device Time=%d\n", g_ulSysTickCount); // Get the interface descriptor. pInterface = USBDescGetInterface(pDevice->pConfigDescriptor, 0, 0); // Loop through the endpoints of the device. for(iIdx = 0; iIdx < 3; iIdx++) { // Get the first endpoint descriptor. pEndpointDescriptor = USBDescGetInterfaceEndpoint(pInterface, iIdx, pDevice->ulConfigDescriptorSize); UARTprintf("\nEndpoint%d USBDescGetInterfaceEndpoint()=pEndpointDescriptor res=0x%08X\n", iIdx, pEndpointDescriptor); // If no more endpoints then break out. if(pEndpointDescriptor == 0) { break; } UARTprintf("pEndpointDescriptor details:\n"); UARTprintf(" bLength=0x%02X (shall be 0x07)\n", pEndpointDescriptor->bLength); UARTprintf(" bDescriptorType=0x%02X\n", pEndpointDescriptor->bDescriptorType); UARTprintf(" bEndpointAddress=0x%02X\n", pEndpointDescriptor->bEndpointAddress); UARTprintf(" bmAttributes=0x%02X (0x00=CTRL, 0x01=ISOC, 0x02=BULK, 0x03=INT\n", pEndpointDescriptor->bmAttributes); UARTprintf(" wMaxPacketSize=0x%04X\n", pEndpointDescriptor->wMaxPacketSize); UARTprintf(" bInterval=0x%04X\n", pEndpointDescriptor->bInterval); // See if this is a bulk endpoint. if((pEndpointDescriptor->bmAttributes & USB_EP_ATTR_TYPE_M) == USB_EP_ATTR_BULK) { // See if this is bulk IN or bulk OUT. if(pEndpointDescriptor->bEndpointAddress & USB_EP_DESC_IN) { UARTprintf("Endpoint Bulk In alloc USB Pipe\n"); // Allocate the USB Pipe for this Bulk IN endpoint. g_USBHANDROIDDevice.ulBulkInPipe = USBHCDPipeAllocSize(0, USBHCD_PIPE_BULK_IN_DMA, pDevice->ulAddress, pEndpointDescriptor->wMaxPacketSize, 0); // Configure the USB pipe as a Bulk IN endpoint. USBHCDPipeConfig(g_USBHANDROIDDevice.ulBulkInPipe, pEndpointDescriptor->wMaxPacketSize, BULK_READ_TIMEOUT, (pEndpointDescriptor->bEndpointAddress & USB_EP_DESC_NUM_M)); } else { UARTprintf("Endpoint Bulk OUT alloc USB Pipe\n"); // Allocate the USB Pipe for this Bulk OUT endpoint. g_USBHANDROIDDevice.ulBulkOutPipe = USBHCDPipeAllocSize(0, USBHCD_PIPE_BULK_OUT_DMA, pDevice->ulAddress, pEndpointDescriptor->wMaxPacketSize, 0); // Configure the USB pipe as a Bulk OUT endpoint. USBHCDPipeConfig(g_USBHANDROIDDevice.ulBulkOutPipe, pEndpointDescriptor->wMaxPacketSize, BULK_WRITE_TIMEOUT, (pEndpointDescriptor->bEndpointAddress & USB_EP_DESC_NUM_M)); } } } // If the callback exists, call it with an Open event. if(g_USBHANDROIDDevice.pfnCallback != 0) { g_USBHANDROIDDevice.pfnCallback((t_u32)&g_USBHANDROIDDevice, ANDROID_EVENT_OPEN, 0); } // Set Flag isConnected g_USBHANDROIDDevice.connected = true; } else { UARTprintf("Found possible device. switching to serial mode Time=%d\n", g_ulSysTickCount); switchDevice(pDevice); // Set Flag isConnected g_USBHANDROIDDevice.connected = false; } UARTprintf("\nEnd USBHANDROIDOpen Time=%d\n", g_ulSysTickCount); // Return the only instance of this device. return(&g_USBHANDROIDDevice); }
//***************************************************************************** // // Open an instance of the hub driver. This is called when the USB host // has enumerated a new hub device. // //***************************************************************************** static void * HubDriverOpen(tUSBHostDevice *psDevice) { tEndpointDescriptor *psEndpointDescriptor; tInterfaceDescriptor *psInterface; tUsbHubDescriptor sHubDesc; bool bRetcode; uint32_t ui32Loop; // // If we are already talking to a hub, fail the call. We only support // a single hub. // if(g_sRootHub.ui32Flags & USBLIB_HUB_ACTIVE) { return(0); } // // Get pointers to the device descriptors we need to look at. // psInterface = USBDescGetInterface(psDevice->psConfigDescriptor, 0, 0); psEndpointDescriptor = USBDescGetInterfaceEndpoint(psInterface, 0, psDevice->ui32ConfigDescriptorSize); // // If there are no endpoints, something is wrong since a hub must have // a single INT endpoint for signaling. // if(psEndpointDescriptor == 0) { return 0; } // // Make sure we really are talking to a hub. // if((psInterface->bInterfaceClass != USB_CLASS_HUB) || (psInterface->bInterfaceSubClass != 0)) { // // Something is wrong - this isn't a hub or, if it is, we don't // understand the protocol it is using. // return(0); } // // Remember that this is a high speed hub with either single or multiple // transaction translators. // if(psInterface->bInterfaceProtocol == USB_HUB_PROTOCOL_SINGLE) { g_sRootHub.ui32Flags |= USBLIB_HUB_HS; } else if(psInterface->bInterfaceProtocol == USB_HUB_PROTOCOL_MULTI) { g_sRootHub.ui32Flags |= USBLIB_HUB_HS | USBLIB_HUB_MULTI_TT; } // // Remember the device information for later. // g_sRootHub.psDevice = psDevice; // // A hub must support an interrupt endpoint so check this. // if((psEndpointDescriptor->bmAttributes & USB_EP_ATTR_TYPE_M) == USB_EP_ATTR_INT) { // // The endpoint is the correct type. Is it an IN endpoint? // if(psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_IN) { // // Yes - all is well with the hub endpoint so allocate a pipe to // handle traffic from the hub. // g_sRootHub.ui32IntInPipe = USBHCDPipeAlloc(0, USBHCD_PIPE_INTR_IN, psDevice, HubIntINCallback); USBHCDPipeConfig(g_sRootHub.ui32IntInPipe, psEndpointDescriptor->wMaxPacketSize, psEndpointDescriptor->bInterval, psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_NUM_M); } } // // Did we allocate the endpoint successfully? // if(!g_sRootHub.ui32IntInPipe) { // // No - return an error. // return 0; } // // Assuming we have a callback, call it to tell the owner that a hub is // now connected. // if(g_sRootHub.pfnCallback != 0) { g_sRootHub.pfnCallback((void *)g_sRootHub.ui32CBData, USB_EVENT_CONNECTED, (uint32_t)&g_sRootHub, 0); } // // Get the hub descriptor and store information we'll need for later. // bRetcode = GetHubDescriptor(&sHubDesc); if(bRetcode) { // // We read the descriptor successfully so extract the parts we need. // g_sRootHub.ui8NumPorts = sHubDesc.bNbrPorts; g_sRootHub.ui16HubCharacteristics = sHubDesc.wHubCharacteristics; g_sRootHub.ui8NumPortsInUse = (sHubDesc.bNbrPorts > MAX_USB_DEVICES) ? MAX_USB_DEVICES : sHubDesc.bNbrPorts; // // The size of the status change report that the hub sends is dependent // upon the number of ports that the hub supports. Calculate this by // adding 1 to the number of ports (bit 0 of the report is the hub // status, higher bits are one per port) then dividing by 8 (bits per // byte) and rounding up. // g_sRootHub.ui8ReportSize = ((sHubDesc.bNbrPorts + 1) + 7) / 8; // // Enable power to all ports on the hub. // for(ui32Loop = 1; ui32Loop <= sHubDesc.bNbrPorts; ui32Loop++) { // // Turn on power to this port. // HubSetPortFeature(&g_sRootHub, ui32Loop, HUB_FEATURE_PORT_POWER); } // // Clear out our port state structures. // for(ui32Loop = 0; ui32Loop < MAX_USB_DEVICES; ui32Loop++) { g_sRootHub.psPorts[ui32Loop].bChanged = false; g_sRootHub.psPorts[ui32Loop].iState = ePortIdle; } } else { // // Oops - we can't read the hub descriptor! Tidy up and return // an error. // USBHCDPipeFree(g_sRootHub.ui32IntInPipe); g_sRootHub.pfnCallback = 0; g_sRootHub.ui32Flags &= ~USBLIB_HUB_ACTIVE; return(0); } // // If we get here, all is well so remember that the hub is connected and // active. // g_sRootHub.ui32Flags |= USBLIB_HUB_ACTIVE; // // Return our instance data pointer to the caller to use as a handle. // return((void *)&g_sRootHub); }
//***************************************************************************** // //! This function is used to open an instance of the MSC driver. //! //! \param psDevice is a pointer to the device information structure. //! //! This function will attempt to open an instance of the MSC driver based on //! the information contained in the \e psDevice structure. This call can fail //! if there are not sufficient resources to open the device. The function //! returns a value that should be passed back into USBMSCClose() when the //! driver is no longer needed. //! //! \return The function will return a pointer to a MSC driver instance. // //***************************************************************************** static void * USBHMSCOpen(tUSBHostDevice *psDevice) { int32_t i32Idx; tEndpointDescriptor *psEndpointDescriptor; tInterfaceDescriptor *psInterface; // // Don't allow the device to be opened without closing first. // if(g_sUSBHMSCDevice.psDevice) { return(0); } // // Save the device pointer. // g_sUSBHMSCDevice.psDevice = psDevice; // // Get the interface descriptor. // psInterface = USBDescGetInterface(psDevice->psConfigDescriptor, 0, 0); // // Loop through the endpoints of the device. // for(i32Idx = 0; i32Idx < 3; i32Idx++) { // // Get the first endpoint descriptor. // psEndpointDescriptor = USBDescGetInterfaceEndpoint(psInterface, i32Idx, psDevice->ui32ConfigDescriptorSize); // // If no more endpoints then break out. // if(psEndpointDescriptor == 0) { break; } // // See if this is a bulk endpoint. // if((psEndpointDescriptor->bmAttributes & USB_EP_ATTR_TYPE_M) == USB_EP_ATTR_BULK) { // // See if this is bulk IN or bulk OUT. // if(psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_IN) { // // Allocate the USB Pipe for this Bulk IN endpoint. // g_sUSBHMSCDevice.ui32BulkInPipe = USBHCDPipeAllocSize(0, USBHCD_PIPE_BULK_IN, psDevice, readusb16_t(&(psEndpointDescriptor->wMaxPacketSize)), 0); // // Configure the USB pipe as a Bulk IN endpoint. // USBHCDPipeConfig(g_sUSBHMSCDevice.ui32BulkInPipe, readusb16_t(&(psEndpointDescriptor->wMaxPacketSize)), 0, (psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_NUM_M)); } else { // // Allocate the USB Pipe for this Bulk OUT endpoint. // g_sUSBHMSCDevice.ui32BulkOutPipe = USBHCDPipeAllocSize(0, USBHCD_PIPE_BULK_OUT, psDevice, readusb16_t(&(psEndpointDescriptor->wMaxPacketSize)), 0); // // Configure the USB pipe as a Bulk OUT endpoint. // USBHCDPipeConfig(g_sUSBHMSCDevice.ui32BulkOutPipe, readusb16_t(&(psEndpointDescriptor->wMaxPacketSize)), 0, (psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_NUM_M)); } } } // // If the callback exists, call it with an Open event. // if(g_sUSBHMSCDevice.pfnCallback != 0) { g_sUSBHMSCDevice.pfnCallback(&g_sUSBHMSCDevice, MSC_EVENT_OPEN, 0); } g_sUSBHMSCDevice.ui32MaxLUN = 0xffffffff; // // Return the only instance of this device. // return(&g_sUSBHMSCDevice); }