//------------------------------------------------------------------------------ /// Configures the device by setting it into the Configured state and /// initializing all endpoints. /// \param pDriver Pointer to a USBDDriver instance. /// \param cfgnum Configuration number to set. //------------------------------------------------------------------------------ static void SetConfiguration(USBDDriver *pDriver, unsigned char cfgnum) { USBEndpointDescriptor *pEndpoints[BOARD_USB_NUMENDPOINTS+1]; const USBConfigurationDescriptor *pConfiguration; pConfiguration = pDriver->pDescriptors->pFsConfiguration; // Set & save the desired configuration USBD_SetConfiguration(cfgnum); pDriver->cfgnum = cfgnum; // If the configuration is not 0, configure endpoints if (cfgnum != 0) { // Parse configuration to get endpoint descriptors USBConfigurationDescriptor_Parse(pConfiguration, 0, pEndpoints, 0); // Configure endpoints int i = 0; while (pEndpoints[i] != 0) { USBD_ConfigureEndpoint(pEndpoints[i]); i++; } } // Should be done before send the ZLP USBDDriverCallbacks_ConfigurationChanged(cfgnum); // Acknowledge the request USBD_Write(0, // Endpoint #0 0, // No data buffer 0, // No data buffer (TransferCallback) 0, (void *) 0); }
/** * Returns the descriptor requested by the host. * \param type Descriptor type. * \param length Maximum number of bytes to send. * \return 1 if the request has been handled by this function, otherwise 0. */ static uint8_t HIDDTransferDriver_GetDescriptor(uint8_t type, uint8_t length) { HIDDTransferDriver *pDrv = &hiddTransferDriver; HIDDFunction *pHidd = &pDrv->hidFunction; const USBConfigurationDescriptor *pConfiguration; HIDDescriptor *hidDescriptors[2]; switch (type) { case HIDGenericDescriptor_REPORT: TRACE_INFO("Report "); /* Adjust length and send report descriptor */ if (length > HIDDTransferDriver_REPORTDESCRIPTORSIZE) { length = HIDDTransferDriver_REPORTDESCRIPTORSIZE; } USBD_Write(0, &hiddTransferReportDescriptor, length, 0, 0); break; case HIDGenericDescriptor_HID: TRACE_INFO("HID "); /* Configuration descriptor is different depending on configuration */ if (USBD_IsHighSpeed()) { pConfiguration = pHidd->pUsbd->pDescriptors->pHsConfiguration; } else { pConfiguration = pHidd->pUsbd->pDescriptors->pFsConfiguration; } /* Parse the device configuration to get the HID descriptor */ USBConfigurationDescriptor_Parse(pConfiguration, 0, 0, (USBGenericDescriptor **) hidDescriptors); /* Adjust length and send HID descriptor */ if (length > sizeof(HIDDescriptor)) { length = sizeof(HIDDescriptor); } USBD_Write(0, hidDescriptors[0], length, 0, 0); break; default: return 0; } return 1; }
/** * Configures the device by setting it into the Configured state and * initializing all endpoints. * \param pDriver Pointer to a USBDDriver instance. * \param cfgnum Configuration number to set. */ static void SetConfiguration(USBDDriver *pDriver, uint8_t cfgnum) { USBEndpointDescriptor *pEndpoints[17]; const USBConfigurationDescriptor *pConfiguration; /* Use different descriptor depending on device speed */ if ( USBD_HAL_IsHighSpeed() && pDriver->pDescriptors->pHsConfiguration) { pConfiguration = pDriver->pDescriptors->pHsConfiguration; } else { pConfiguration = pDriver->pDescriptors->pFsConfiguration; } /* Set & save the desired configuration */ USBD_SetConfiguration(cfgnum); pDriver->cfgnum = cfgnum; pDriver->isRemoteWakeUpEnabled = ((pConfiguration->bmAttributes & 0x20) > 0); /* If the configuration is not 0, configure endpoints */ if (cfgnum != 0) { /* Parse configuration to get endpoint descriptors */ USBConfigurationDescriptor_Parse(pConfiguration, 0, pEndpoints, 0); /* Configure endpoints */ int i = 0; while (pEndpoints[i] != 0) { USBD_ConfigureEndpoint(pEndpoints[i]); i++; } } /* Should be done before send the ZLP */ if (NULL != USBDDriverCallbacks_ConfigurationChanged) USBDDriverCallbacks_ConfigurationChanged(cfgnum); /* Acknowledge the request */ USBD_Write(0, /* Endpoint #0 */ 0, /* No data buffer */ 0, /* No data buffer */ (TransferCallback) 0, (void *) 0); }
//------------------------------------------------------------------------------ /// Configures the device by setting it into the Configured state and /// initializing all endpoints. /// \param pDriver Pointer to a USBDDriver instance. /// \param cfgnum Configuration number to set. //------------------------------------------------------------------------------ static void SetConfiguration(USBDDriver *pDriver, unsigned char cfgnum) { USBEndpointDescriptor *pEndpoints[BOARD_USB_NUMENDPOINTS+1]; const USBConfigurationDescriptor *pConfiguration; // Use different descriptor depending on device speed if (USBD_IsHighSpeed()) { pConfiguration = pDriver->pDescriptors->pHsConfiguration; } else { pConfiguration = pDriver->pDescriptors->pFsConfiguration; } // Set & save the desired configuration USBD_SetConfiguration(cfgnum); pDriver->cfgnum = cfgnum; // If the configuration is not 0, configure endpoints if (cfgnum != 0) { // Parse configuration to get endpoint descriptors USBConfigurationDescriptor_Parse(pConfiguration, 0, pEndpoints, 0); // Configure endpoints int i = 0; while (pEndpoints[i] != 0) { USBD_ConfigureEndpoint(pEndpoints[i]); i++; } } // Acknowledge the request USBD_Write(0, // Endpoint #0 0, // No data buffer 0, // No data buffer (TransferCallback) USBDDriverCallbacks_ConfigurationChanged, (void *) (unsigned int) cfgnum); }