/* Configures the device by setting it into the Configured state and initializing all endpoints.  */
static void SetConfiguration(USBDDriver *pDriver, unsigned char cfgnum)
/* Configures the device by setting it into the Configured state and initializing all endpoints.  */
static void SetConfiguration(USBDDriver *pDriver, unsigned char cfgnum)
{
    USBEndpointDescriptor *pEndpoints[CHIP_USB_NUMENDPOINTS+1];
    const USBConfigurationDescriptor *pConfiguration;
    if (USBD_IsHighSpeed()) {
        pConfiguration = pDriver->pDescriptors->pHsConfiguration;
    }
    else {
        pConfiguration = pDriver->pDescriptors->pFsConfiguration;
    }
    USBD_SetConfiguration(cfgnum);
    pDriver->cfgnum = cfgnum;
    if (cfgnum != 0) {
        USBConfigurationDescriptor_Parse(pConfiguration, 0, pEndpoints, 0);
        int i = 0;
        while (pEndpoints[i] != 0) {
            USBD_ConfigureEndpoint(pEndpoints[i]);
            i++;
        }
    }
    USBDDriverCallbacks_ConfigurationChanged(cfgnum);
    USBD_Write(0,
               0,
               0,
               (TransferCallback) 0,
               (void *)  0);
}