XilinxProcessorIPLib/drivers/usbps/examples/xusbps_ch9_audio.c
void XUsbPs_SetInterfaceHandler(XUsbPs *InstancePtr,
		XUsbPs_SetupData *SetupData)
{
	s32 RetVal;
	u16 MaxPktSize = 1024;

#ifdef XUSBPS_UAC1

	if ((SetupData->wIndex & 0xff) != 1) {
		return;
	}

#ifdef XUSBPS_MICROPHONE

	if ((SetupData->wValue & 0xff) == 1) {
		XUsbPs_SetEpInterval(InstancePtr, ISO_EP,
				XUSBPS_EP_DIRECTION_IN,
				AUDIO_INTERVAL);
		Index = 0;
		Residue = 0;
		FirstPktFrame = 1;
		/* Endpoint enables - not needed for Control EP */
		RetVal = EpEnable((XUsbPs *)InstancePtr, ISO_EP,
				XUSBPS_EP_DIRECTION_IN,
				MaxPktSize, USB_EP_TYPE_ISOCHRONOUS);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to enable ISOC IN Ep\r\n");
			return;
		}
		XUsbPs_StreamOn(InstancePtr, ISO_EP, XUSBPS_EP_DIRECTION_IN,
				BufferPtrTemp);
	} else {
		XUsbPs_StreamOff(InstancePtr, ISO_EP, XUSBPS_EP_DIRECTION_IN);
		/* Endpoint disables - not needed for Control EP */
		XUsbPs_EpDisable((XUsbPs *)InstancePtr, ISO_EP,
				XUSBPS_EP_DIRECTION_IN);
	}

#else	/* SPEAKER */

	if ((SetupData->wValue & 0xff) == 1) {
		XUsbPs_SetEpInterval(InstancePtr, ISO_EP,
				XUSBPS_EP_DIRECTION_OUT,
				AUDIO_INTERVAL);
		Index = 0;
		Residue = 0;
		FirstPktFrame = 1;
		/* Endpoint enables - not needed for Control EP */
		RetVal = EpEnable(InstancePtr,
				ISO_EP, XUSBPS_EP_DIRECTION_OUT,
				MaxPktSize, USB_EP_TYPE_ISOCHRONOUS);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to enable ISOC OUT Ep\r\n");
			return;
		}
		XUsbPs_StreamOn(InstancePtr, ISO_EP, XUSBPS_EP_DIRECTION_OUT,
				BufferPtrTemp);
	} else {
		XUsbPs_StreamOff(InstancePtr, ISO_EP, XUSBPS_EP_DIRECTION_OUT);
		/* Endpoint disables - not needed for Control EP */
		XUsbPs_EpDisable((XUsbPs *)InstancePtr, ISO_EP,
				XUSBPS_EP_DIRECTION_OUT);
	}

#endif  /* end of SPEAKER */

#else	/*	UAC2 */

	if ((SetupData->wIndex & 0xff) == 1) {
		if ((SetupData->wValue & 0xff) == 1) {
			XUsbPs_SetEpInterval(InstancePtr,
					ISO_EP, XUSBPS_EP_DIRECTION_OUT,
					AUDIO_INTERVAL);
			Index = 0;
			Residue = 0;
			FirstPktFrame = 1;
			/* Endpoint enables - not needed for Control EP */
			RetVal = EpEnable((XUsbPs *)InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_OUT,
					MaxPktSize, USB_EP_TYPE_ISOCHRONOUS);
			if (RetVal != XST_SUCCESS) {
				xil_printf("failed to enable ISOC OUT Ep\r\n");
				return;
			}
			XUsbPs_StreamOn(InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_OUT,
					BufferPtrTemp);
		} else {
			XUsbPs_StreamOff(InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_OUT);
			/* Endpoint disables - not needed for Control EP */
			XUsbPs_EpDisable((XUsbPs *)InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_OUT);
		}
	}

	if ((SetupData->wIndex & 0xff) == 2) {
		if ((SetupData->wValue & 0xff) == 1) {
			XUsbPs_SetEpInterval(InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_IN, AUDIO_INTERVAL);
			Index = 0;
			Residue = 0;
			FirstPktFrame = 1;
			/* Endpoint enables - not needed for Control EP */
			RetVal = EpEnable((XUsbPs *)InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_IN,
					MaxPktSize, USB_EP_TYPE_ISOCHRONOUS);
			if (RetVal != XST_SUCCESS) {
				xil_printf("failed to enable ISOC IN Ep\r\n");
				return;
			}
			XUsbPs_StreamOn(InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_IN,
					BufferPtrTemp);
		} else {
			XUsbPs_StreamOff(InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_IN);
			/* Endpoint disables - not needed for Control EP */
			XUsbPs_EpDisable((XUsbPs *)InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_IN);
		}
	}
#endif	// end of UAC2
}
/****************************************************************************/
/**
 * This function is called by Chapter9 handler when SET_CONFIGURATION command
 * or SET_INTERFACE command is received from Host.
 *
 * @param	InstancePtr is pointer to Usb_DevData instance.
 * @param	SetupData is the setup packet received from Host.
 *
 * @note
 *		Non control endpoints must be enabled after SET_INTERFACE
 *		command since hardware clears all previously enabled endpoints
 *		except control endpoints when this command is received.
 *
 *****************************************************************************/
This function is called by Chapter9 handler when SET_CONFIGURATION command
or SET_INTERFACE command is received from Host.

@param       InstancePtr is pointer to Usb_DevData instance.
@param       SetupData is the setup packet received from Host.

@note
Non control endpoints must be enabled after SET_INTERFACE
command since hardware clears all previously enabled endpoints
except control endpoints when this command is received.
This function is called by Chapter9 handler when SET_CONFIGURATION command or SET_INTERFACE command is received from Host . @param InstancePtr is pointer to Usb_DevData instance . @param SetupData is the setup packet received from Host . @note Non control endpoints must be enabled after SET_INTERFACE command since hardware clears all previously enabled endpoints except control endpoints when this command is received .
void XUsbPs_SetInterfaceHandler(XUsbPs *InstancePtr,
		XUsbPs_SetupData *SetupData)
{
	s32 RetVal;
	u16 MaxPktSize = 1024;
#ifdef XUSBPS_UAC1
	if ((SetupData->wIndex & 0xff) != 1) {
		return;
	}
#ifdef XUSBPS_MICROPHONE
	if ((SetupData->wValue & 0xff) == 1) {
		XUsbPs_SetEpInterval(InstancePtr, ISO_EP,
				XUSBPS_EP_DIRECTION_IN,
				AUDIO_INTERVAL);
		Index = 0;
		Residue = 0;
		FirstPktFrame = 1;
		RetVal = EpEnable((XUsbPs *)InstancePtr, ISO_EP,
				XUSBPS_EP_DIRECTION_IN,
				MaxPktSize, USB_EP_TYPE_ISOCHRONOUS);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to enable ISOC IN Ep\r\n");
			return;
		}
		XUsbPs_StreamOn(InstancePtr, ISO_EP, XUSBPS_EP_DIRECTION_IN,
				BufferPtrTemp);
	} else {
		XUsbPs_StreamOff(InstancePtr, ISO_EP, XUSBPS_EP_DIRECTION_IN);
		XUsbPs_EpDisable((XUsbPs *)InstancePtr, ISO_EP,
				XUSBPS_EP_DIRECTION_IN);
	}
#else	
	if ((SetupData->wValue & 0xff) == 1) {
		XUsbPs_SetEpInterval(InstancePtr, ISO_EP,
				XUSBPS_EP_DIRECTION_OUT,
				AUDIO_INTERVAL);
		Index = 0;
		Residue = 0;
		FirstPktFrame = 1;
		RetVal = EpEnable(InstancePtr,
				ISO_EP, XUSBPS_EP_DIRECTION_OUT,
				MaxPktSize, USB_EP_TYPE_ISOCHRONOUS);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to enable ISOC OUT Ep\r\n");
			return;
		}
		XUsbPs_StreamOn(InstancePtr, ISO_EP, XUSBPS_EP_DIRECTION_OUT,
				BufferPtrTemp);
	} else {
		XUsbPs_StreamOff(InstancePtr, ISO_EP, XUSBPS_EP_DIRECTION_OUT);
		XUsbPs_EpDisable((XUsbPs *)InstancePtr, ISO_EP,
				XUSBPS_EP_DIRECTION_OUT);
	}
#endif  
#else	
	if ((SetupData->wIndex & 0xff) == 1) {
		if ((SetupData->wValue & 0xff) == 1) {
			XUsbPs_SetEpInterval(InstancePtr,
					ISO_EP, XUSBPS_EP_DIRECTION_OUT,
					AUDIO_INTERVAL);
			Index = 0;
			Residue = 0;
			FirstPktFrame = 1;
			RetVal = EpEnable((XUsbPs *)InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_OUT,
					MaxPktSize, USB_EP_TYPE_ISOCHRONOUS);
			if (RetVal != XST_SUCCESS) {
				xil_printf("failed to enable ISOC OUT Ep\r\n");
				return;
			}
			XUsbPs_StreamOn(InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_OUT,
					BufferPtrTemp);
		} else {
			XUsbPs_StreamOff(InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_OUT);
			XUsbPs_EpDisable((XUsbPs *)InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_OUT);
		}
	}
	if ((SetupData->wIndex & 0xff) == 2) {
		if ((SetupData->wValue & 0xff) == 1) {
			XUsbPs_SetEpInterval(InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_IN, AUDIO_INTERVAL);
			Index = 0;
			Residue = 0;
			FirstPktFrame = 1;
			RetVal = EpEnable((XUsbPs *)InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_IN,
					MaxPktSize, USB_EP_TYPE_ISOCHRONOUS);
			if (RetVal != XST_SUCCESS) {
				xil_printf("failed to enable ISOC IN Ep\r\n");
				return;
			}
			XUsbPs_StreamOn(InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_IN,
					BufferPtrTemp);
		} else {
			XUsbPs_StreamOff(InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_IN);
			XUsbPs_EpDisable((XUsbPs *)InstancePtr, ISO_EP,
					XUSBPS_EP_DIRECTION_IN);
		}
	}
#endif	
}
void XUsbPs_SetInterfaceHandler ( XUsbPs * InstancePtr , XUsbPs_SetupData * SetupData ) { s32 RetVal ; u16 MaxPktSize = 1024 ; #ifdef XUSBPS_UAC1 if ( ( SetupData -> wIndex & 0xff ) != 1 ) { return ; } #ifdef XUSBPS_MICROPHONE if ( ( SetupData -> wValue & 0xff ) == 1 ) { XUsbPs_SetEpInterval ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_IN , AUDIO_INTERVAL ) ; Index = 0 ; Residue = 0 ; FirstPktFrame = 1 ; RetVal = EpEnable ( ( XUsbPs * ) InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_IN , MaxPktSize , USB_EP_TYPE_ISOCHRONOUS ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return ; } XUsbPs_StreamOn ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_IN , BufferPtrTemp ) ; } else { XUsbPs_StreamOff ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_IN ) ; XUsbPs_EpDisable ( ( XUsbPs * ) InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_IN ) ; } #else if ( ( SetupData -> wValue & 0xff ) == 1 ) { XUsbPs_SetEpInterval ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_OUT , AUDIO_INTERVAL ) ; Index = 0 ; Residue = 0 ; FirstPktFrame = 1 ; RetVal = EpEnable ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_OUT , MaxPktSize , USB_EP_TYPE_ISOCHRONOUS ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return ; } XUsbPs_StreamOn ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_OUT , BufferPtrTemp ) ; } else { XUsbPs_StreamOff ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_OUT ) ; XUsbPs_EpDisable ( ( XUsbPs * ) InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_OUT ) ; } #endif #else if ( ( SetupData -> wIndex & 0xff ) == 1 ) { if ( ( SetupData -> wValue & 0xff ) == 1 ) { XUsbPs_SetEpInterval ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_OUT , AUDIO_INTERVAL ) ; Index = 0 ; Residue = 0 ; FirstPktFrame = 1 ; RetVal = EpEnable ( ( XUsbPs * ) InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_OUT , MaxPktSize , USB_EP_TYPE_ISOCHRONOUS ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return ; } XUsbPs_StreamOn ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_OUT , BufferPtrTemp ) ; } else { XUsbPs_StreamOff ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_OUT ) ; XUsbPs_EpDisable ( ( XUsbPs * ) InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_OUT ) ; } } if ( ( SetupData -> wIndex & 0xff ) == 2 ) { if ( ( SetupData -> wValue & 0xff ) == 1 ) { XUsbPs_SetEpInterval ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_IN , AUDIO_INTERVAL ) ; Index = 0 ; Residue = 0 ; FirstPktFrame = 1 ; RetVal = EpEnable ( ( XUsbPs * ) InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_IN , MaxPktSize , USB_EP_TYPE_ISOCHRONOUS ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return ; } XUsbPs_StreamOn ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_IN , BufferPtrTemp ) ; } else { XUsbPs_StreamOff ( InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_IN ) ; XUsbPs_EpDisable ( ( XUsbPs * ) InstancePtr , ISO_EP , XUSBPS_EP_DIRECTION_IN ) ; } } #endif }
This function is called by Chapter9 handler when SET_CONFIGURATION command
 or SET_INTERFACE command is received from Host.
This function is called by Chapter9 handler when SET_CONFIGURATION command or SET_INTERFACE command is received from Host .
/* Endpoint enables - not needed for Control EP */ /* Endpoint disables - not needed for Control EP */ /* SPEAKER */ /* Endpoint enables - not needed for Control EP */ /* Endpoint disables - not needed for Control EP */ /* end of SPEAKER */ /*	UAC2 */ /* 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 */ // end of UAC2