USB_COMMON_DESCRIPTOR * USBH_X_GetNextDescriptor(
USB_COMMON_DESCRIPTOR * pbCommDescriptor,
U32 * wNextDescriptorOffset )
{
USB_COMMON_DESCRIPTOR * pNextCommDescriptor;
U8 bLength = pbCommDescriptor->bLength;
*wNextDescriptorOffset += bLength;
pNextCommDescriptor = (USB_COMMON_DESCRIPTOR *) ( ( (U8 *) pbCommDescriptor ) + bLength );
return pNextCommDescriptor;
}
void USBH_X_SetEpDescriptor(
TUSBH_X_DEVICE * pDevice,
U8 bIfNumber,
U8 bEpNumber,
USB_ENDPOINT_DESCRIPTOR * pEpDescriptor )
{
pDevice->pEndpointDescriptorArray[ bIfNumber ][ bEpNumber ] = pEpDescriptor;
}
void USBH_X_SetIfDescriptor(
TUSBH_X_DEVICE * pDevice,
U8 bIfNumber,
USB_INTERFACE_DESCRIPTOR * pIfDescriptor )
{
pDevice->pInterfaceDescriptorArray[ bIfNumber ] = pIfDescriptor;
}
void USBH_X_SetCfgDescriptor(
TUSBH_X_DEVICE * pDevice )
{
U32 interfaceIndex = 0;
U32 endpointIndex = 0;
// Points to the current configuration descriptor
USB_COMMON_DESCRIPTOR * pNextDescriptor;
USB_CONFIGURATION_DESCRIPTOR * pCfgDescriptor;
USB_INTERFACE_DESCRIPTOR * pIfDescriptor;
USB_ENDPOINT_DESCRIPTOR * pEpDescriptor;
pCfgDescriptor = (USB_CONFIGURATION_DESCRIPTOR*) ( ( pDevice->pUsbDevice->pConfigDescriptor ) );
pNextDescriptor = (USB_COMMON_DESCRIPTOR*) ( pCfgDescriptor );
U32 wTotalLength = pCfgDescriptor->wTotalLength;
U32 wNextDescriptorOffset = USB_CONFIGURATION_DESCRIPTOR_LENGTH;
pDevice->pCurrentConfigurationDescriptor = pCfgDescriptor;
interfaceIndex = 0;
while ( wNextDescriptorOffset < wTotalLength )
{
pNextDescriptor = USBH_X_GetNextDescriptor( pNextDescriptor, &wNextDescriptorOffset );
if ( pNextDescriptor->bDescriptorType == USB_DESC_TYPE_INTERFACE )
{
pIfDescriptor = (USB_INTERFACE_DESCRIPTOR*) pNextDescriptor;
if ( pIfDescriptor->bAlternateSetting == 0 )
{
USBH_X_SetIfDescriptor( pDevice, interfaceIndex, pIfDescriptor );
// Parse Ep descriptors relative to the current interface
endpointIndex = 0;
while ( endpointIndex < pIfDescriptor->bNumEndpoints )
{
pNextDescriptor = USBH_X_GetNextDescriptor( pNextDescriptor, &wNextDescriptorOffset );
if ( pNextDescriptor->bDescriptorType == USB_DESC_TYPE_ENDPOINT )
{
pEpDescriptor = (USB_ENDPOINT_DESCRIPTOR *) pNextDescriptor;
USBH_X_SetEpDescriptor( pDevice, interfaceIndex, endpointIndex, pEpDescriptor );
endpointIndex++;
if ( ( endpointIndex == USBH_X_DEV_MAX_ENDPOINT )|| ( endpointIndex == pIfDescriptor->bNumEndpoints) )
break;
}
}
interfaceIndex++;
if ( ( interfaceIndex == USBH_X_DEV_MAX_IF )||( interfaceIndex == pDevice->pUsbDevice->InterfaceCount) )
return;
}
}
}
}
void USBH_X_SetDevDescriptor(
TUSBH_X_DEVICE * pDevice )
{
pDevice->pDeviceDescriptor = (USBH_DEVICE_DESCRIPTOR*) ( &( pDevice->pUsbDevice->DeviceDescriptor ) );
}