subsys/usb/usb_device.c
/*
 * @brief set USB configuration
 *
 * This function configures the device according to the specified configuration
 * index and alternate setting by parsing the installed USB descriptor list.
 * A configuration index of 0 unconfigures the device.
 *
 * @param [in] config_index Configuration index
 * @param [in] alt_setting  Alternate setting number
 *
 * @return true if successfully configured false if error or unconfigured
 */
@brief set USB configuration
This function configures the device according to the specified configuration
index and alternate setting by parsing the installed USB descriptor list.
A configuration index of 0 unconfigures the device.

@param [in] config_index Configuration index
@param [in] alt_setting  Alternate setting number

@return true if successfully configured false if error or unconfigured
@brief set USB configuration This function configures the device according to the specified configuration index and alternate setting by parsing the installed USB descriptor list . A configuration index of 0 unconfigures the device . @param [ in ] config_index Configuration index @param [ in ] alt_setting Alternate setting number @return true if successfully configured false if error or unconfigured
static bool usb_set_configuration(u8_t config_index, u8_t alt_setting)
{
	u8_t *p = NULL;
	u8_t cur_config = 0;
	u8_t cur_alt_setting = 0;
	if (config_index == 0) {
		SYS_LOG_DBG("Device not configured - invalid configuration "
			    "offset\n");
		return true;
	}
	p = (u8_t *)usb_dev.descriptors;
	cur_config = 0xFF;
	cur_alt_setting = 0xFF;
	while (p[DESC_bLength] != 0) {
		switch (p[DESC_bDescriptorType]) {
		case DESC_CONFIGURATION:
			cur_config = p[CONF_DESC_bConfigurationValue];
			break;
		case DESC_INTERFACE:
			cur_alt_setting =
			    p[INTF_DESC_bAlternateSetting];
			break;
		case DESC_ENDPOINT:
			if ((cur_config == config_index) &&
			    (cur_alt_setting == alt_setting)) {
				struct usb_dc_ep_cfg_data ep_cfg;
				ep_cfg.ep_type =
				    p[ENDP_DESC_bmAttributes];
				ep_cfg.ep_mps =
				    (p[ENDP_DESC_wMaxPacketSize]) |
				    (p[ENDP_DESC_wMaxPacketSize + 1]
					    << 8);
				ep_cfg.ep_addr =
				    p[ENDP_DESC_bEndpointAddress];
				usb_dc_ep_configure(&ep_cfg);
				usb_dc_ep_enable(ep_cfg.ep_addr);
			}
			break;
		default:
			break;
		}
		p += p[DESC_bLength];
	}
	if (usb_dev.status_callback)
		usb_dev.status_callback(USB_DC_CONFIGURED);
	return true;
}
static bool usb_set_configuration ( u8_t config_index , u8_t alt_setting ) { u8_t * p = NULL ; u8_t cur_config = 0 ; u8_t cur_alt_setting = 0 ; if ( config_index == 0 ) { SYS_LOG_DBG ( " " " \n " ) ; return true ; } p = ( u8_t * ) usb_dev . descriptors ; cur_config = 0xFF ; cur_alt_setting = 0xFF ; while ( p [ DESC_bLength ] != 0 ) { switch ( p [ DESC_bDescriptorType ] ) { case DESC_CONFIGURATION : cur_config = p [ CONF_DESC_bConfigurationValue ] ; break ; case DESC_INTERFACE : cur_alt_setting = p [ INTF_DESC_bAlternateSetting ] ; break ; case DESC_ENDPOINT : if ( ( cur_config == config_index ) && ( cur_alt_setting == alt_setting ) ) { struct usb_dc_ep_cfg_data ep_cfg ; ep_cfg . ep_type = p [ ENDP_DESC_bmAttributes ] ; ep_cfg . ep_mps = ( p [ ENDP_DESC_wMaxPacketSize ] ) | ( p [ ENDP_DESC_wMaxPacketSize + 1 ] << 8 ) ; ep_cfg . ep_addr = p [ ENDP_DESC_bEndpointAddress ] ; usb_dc_ep_configure ( & ep_cfg ) ; usb_dc_ep_enable ( ep_cfg . ep_addr ) ; } break ; default : break ; } p += p [ DESC_bLength ] ; } if ( usb_dev . status_callback ) usb_dev . status_callback ( USB_DC_CONFIGURED ) ; return true ; }
@brief set USB configuration
 This function configures the device according to the specified configuration
 index and alternate setting by parsing the installed USB descriptor list.
@brief set USB configuration This function configures the device according to the specified configuration index and alternate setting by parsing the installed USB descriptor list .
/* unconfigure device */ /* configure endpoints for this configuration/altsetting */ /* remember current configuration index */ /* remember current alternate setting */ /* endpoint found for desired config
				 * and alternate setting
				 */ /* skip to next descriptor */