XilinxProcessorIPLib/drivers/usbpsu/examples/xusb_class_composite.c
void Usb_SetIntf(struct Usb_DevData *InstancePtr,  SetupPacket *SetupData)
{
	Xil_AssertVoid(InstancePtr != NULL);

	s32 RetVal;
	u16 MaxPktSize = 1024;
	USBCH9_DATA *ch9_ptr =
		(USBCH9_DATA *)Get_DrvData(InstancePtr->PrivateData);
	struct composite_dev *interface = (struct composite_dev *)(ch9_ptr->data_ptr);
	struct audio_if *f_audio = &interface->f_audio;
	struct dfu_if *f_dfu = &interface->f_dfu;

	switch (SetupData->wIndex & 0xff) {

	case DFU_INTF:		/* DFU */
		/* Setting the alternate setting requested */
		f_dfu->current_inf = SetupData->wValue;
		if ((f_dfu->current_inf >= DFU_ALT_SETTING) ||
				(f_dfu->runtime_to_dfu == 1)) {

			/* Clear the flag , before entering into
			 * DFU mode from runtime mode
			 */
			if (f_dfu->runtime_to_dfu == 1)
				f_dfu->runtime_to_dfu = 0;

			/* Entering DFU_IDLE state */
			Usb_DfuSetState(f_dfu, STATE_DFU_IDLE);
		} else {
			/* Entering APP_IDLE state */
			Usb_DfuSetState(f_dfu, STATE_APP_IDLE);
		}
		break;

	case AUDIO_INTF_IN:	/* AUDIO */
		if ((SetupData->wValue & 0xff) == 1) {

			f_audio->index = 0;
			f_audio->residue = 0;
			f_audio->firstpkt = 1;

			SetEpInterval(InstancePtr->PrivateData, ISO_EP,
					USB_EP_DIR_IN, AUDIO_INTERVAL);

			/* Endpoint enables - not needed for Control EP */
			RetVal = EpEnable(InstancePtr->PrivateData, ISO_EP,
					USB_EP_DIR_IN, MaxPktSize,
					USB_EP_TYPE_ISOCHRONOUS);
			if (RetVal != XST_SUCCESS) {
				xil_printf("failed to enable ISOC IN Ep\r\n");
				return;
			}
		} else {

			StreamOff(InstancePtr->PrivateData, ISO_EP, USB_EP_DIR_IN);

			/* Endpoint disables - not needed for Control EP */
			RetVal = EpDisable(InstancePtr->PrivateData, ISO_EP,
					USB_EP_DIR_IN);
			if (RetVal != XST_SUCCESS) {
				xil_printf("failed to disable ISOC IN Ep\r\n");
				return;
			}
		}

		break;

	case AUDIO_INTF_OUT:
		if ((SetupData->wValue & 0xff) == 1) {

			f_audio->index = 0;
			f_audio->residue = 0;
			f_audio->firstpkt = 1;

			SetEpInterval(InstancePtr->PrivateData, ISO_EP,
					USB_EP_DIR_OUT, AUDIO_INTERVAL);

			/* Endpoint enables - not needed for Control EP */
			RetVal = EpEnable(InstancePtr->PrivateData, ISO_EP,
					USB_EP_DIR_OUT, MaxPktSize,
					USB_EP_TYPE_ISOCHRONOUS);
			if (RetVal != XST_SUCCESS) {
				xil_printf("failed to enable ISOC OUT Ep\r\n");
				return;
			}
		} else {

			StreamOff(InstancePtr->PrivateData, ISO_EP, USB_EP_DIR_OUT);

			/* Endpoint disables - not needed for Control EP */
			RetVal = EpDisable(InstancePtr->PrivateData, ISO_EP,
					USB_EP_DIR_OUT);
			if (RetVal != XST_SUCCESS) {
				xil_printf("failed to disable ISOC OUT Ep\r\n");
				return;
			}
		}

		break;

	default:
		xil_printf("Invalid number for set interface request\r\n");
		break;
	}
}
/*****************************************************************************/
/**
* This function handles set interface request.
*
* @param	InstancePtr is a pointer to Usb_DevData instance of the controller
* @param	SetupData is a pointer to setup token of control transfer
*
* @return	None.
*
* @note		None.
*
******************************************************************************/
This function handles set interface request.
This function handles set interface request .
void Usb_SetIntf(struct Usb_DevData *InstancePtr,  SetupPacket *SetupData)
{
	Xil_AssertVoid(InstancePtr != NULL);
	s32 RetVal;
	u16 MaxPktSize = 1024;
	USBCH9_DATA *ch9_ptr =
		(USBCH9_DATA *)Get_DrvData(InstancePtr->PrivateData);
	struct composite_dev *interface = (struct composite_dev *)(ch9_ptr->data_ptr);
	struct audio_if *f_audio = &interface->f_audio;
	struct dfu_if *f_dfu = &interface->f_dfu;
	switch (SetupData->wIndex & 0xff) {
	case DFU_INTF:		
		f_dfu->current_inf = SetupData->wValue;
		if ((f_dfu->current_inf >= DFU_ALT_SETTING) ||
				(f_dfu->runtime_to_dfu == 1)) {
			if (f_dfu->runtime_to_dfu == 1)
				f_dfu->runtime_to_dfu = 0;
			Usb_DfuSetState(f_dfu, STATE_DFU_IDLE);
		} else {
			Usb_DfuSetState(f_dfu, STATE_APP_IDLE);
		}
		break;
	case AUDIO_INTF_IN:	
		if ((SetupData->wValue & 0xff) == 1) {
			f_audio->index = 0;
			f_audio->residue = 0;
			f_audio->firstpkt = 1;
			SetEpInterval(InstancePtr->PrivateData, ISO_EP,
					USB_EP_DIR_IN, AUDIO_INTERVAL);
			RetVal = EpEnable(InstancePtr->PrivateData, ISO_EP,
					USB_EP_DIR_IN, MaxPktSize,
					USB_EP_TYPE_ISOCHRONOUS);
			if (RetVal != XST_SUCCESS) {
				xil_printf("failed to enable ISOC IN Ep\r\n");
				return;
			}
		} else {
			StreamOff(InstancePtr->PrivateData, ISO_EP, USB_EP_DIR_IN);
			RetVal = EpDisable(InstancePtr->PrivateData, ISO_EP,
					USB_EP_DIR_IN);
			if (RetVal != XST_SUCCESS) {
				xil_printf("failed to disable ISOC IN Ep\r\n");
				return;
			}
		}
		break;
	case AUDIO_INTF_OUT:
		if ((SetupData->wValue & 0xff) == 1) {
			f_audio->index = 0;
			f_audio->residue = 0;
			f_audio->firstpkt = 1;
			SetEpInterval(InstancePtr->PrivateData, ISO_EP,
					USB_EP_DIR_OUT, AUDIO_INTERVAL);
			RetVal = EpEnable(InstancePtr->PrivateData, ISO_EP,
					USB_EP_DIR_OUT, MaxPktSize,
					USB_EP_TYPE_ISOCHRONOUS);
			if (RetVal != XST_SUCCESS) {
				xil_printf("failed to enable ISOC OUT Ep\r\n");
				return;
			}
		} else {
			StreamOff(InstancePtr->PrivateData, ISO_EP, USB_EP_DIR_OUT);
			RetVal = EpDisable(InstancePtr->PrivateData, ISO_EP,
					USB_EP_DIR_OUT);
			if (RetVal != XST_SUCCESS) {
				xil_printf("failed to disable ISOC OUT Ep\r\n");
				return;
			}
		}
		break;
	default:
		xil_printf("Invalid number for set interface request\r\n");
		break;
	}
}
void Usb_SetIntf ( struct Usb_DevData * InstancePtr , SetupPacket * SetupData ) { Xil_AssertVoid ( InstancePtr != NULL ) ; s32 RetVal ; u16 MaxPktSize = 1024 ; USBCH9_DATA * ch9_ptr = ( USBCH9_DATA * ) Get_DrvData ( InstancePtr -> PrivateData ) ; struct composite_dev * interface = ( struct composite_dev * ) ( ch9_ptr -> data_ptr ) ; struct audio_if * f_audio = & interface -> f_audio ; struct dfu_if * f_dfu = & interface -> f_dfu ; switch ( SetupData -> wIndex & 0xff ) { case DFU_INTF : f_dfu -> current_inf = SetupData -> wValue ; if ( ( f_dfu -> current_inf >= DFU_ALT_SETTING ) || ( f_dfu -> runtime_to_dfu == 1 ) ) { if ( f_dfu -> runtime_to_dfu == 1 ) f_dfu -> runtime_to_dfu = 0 ; Usb_DfuSetState ( f_dfu , STATE_DFU_IDLE ) ; } else { Usb_DfuSetState ( f_dfu , STATE_APP_IDLE ) ; } break ; case AUDIO_INTF_IN : if ( ( SetupData -> wValue & 0xff ) == 1 ) { f_audio -> index = 0 ; f_audio -> residue = 0 ; f_audio -> firstpkt = 1 ; SetEpInterval ( InstancePtr -> PrivateData , ISO_EP , USB_EP_DIR_IN , AUDIO_INTERVAL ) ; RetVal = EpEnable ( InstancePtr -> PrivateData , ISO_EP , USB_EP_DIR_IN , MaxPktSize , USB_EP_TYPE_ISOCHRONOUS ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return ; } } else { StreamOff ( InstancePtr -> PrivateData , ISO_EP , USB_EP_DIR_IN ) ; RetVal = EpDisable ( InstancePtr -> PrivateData , ISO_EP , USB_EP_DIR_IN ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return ; } } break ; case AUDIO_INTF_OUT : if ( ( SetupData -> wValue & 0xff ) == 1 ) { f_audio -> index = 0 ; f_audio -> residue = 0 ; f_audio -> firstpkt = 1 ; SetEpInterval ( InstancePtr -> PrivateData , ISO_EP , USB_EP_DIR_OUT , AUDIO_INTERVAL ) ; RetVal = EpEnable ( InstancePtr -> PrivateData , ISO_EP , USB_EP_DIR_OUT , MaxPktSize , USB_EP_TYPE_ISOCHRONOUS ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return ; } } else { StreamOff ( InstancePtr -> PrivateData , ISO_EP , USB_EP_DIR_OUT ) ; RetVal = EpDisable ( InstancePtr -> PrivateData , ISO_EP , USB_EP_DIR_OUT ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return ; } } break ; default : xil_printf ( " \r \n " ) ; break ; } }
This function handles set interface request.
This function handles set interface request .
/* DFU */ /* Setting the alternate setting requested */ /* Clear the flag , before entering into
			 * DFU mode from runtime mode
			 */ /* Entering DFU_IDLE state */ /* Entering APP_IDLE state */ /* AUDIO */ /* Endpoint enables - not needed for Control EP */ /* Endpoint disables - not needed for Control EP */ /* Endpoint enables - not needed for Control EP */ /* Endpoint disables - not needed for Control EP */