XilinxProcessorIPLib/drivers/usbpsu/examples/xusb_composite_example.c
static int XUsbCompositeExample(struct Usb_DevData *UsbInstPtr,
		XScuGic *IntrInstPtr, u16 DeviceId, u16 IntcDeviceID, u16 UsbIntrId)
{
	s32 Status;
	u8 SendKey = 1;
	u8 NoKeyData[8]= {0,0,0,0,0,0,0,0};
	Usb_Config *UsbConfigPtr;

	xil_printf("USB Composite Device Start...\r\n");

	/* Initialize the USB driver so that it's ready to use,
	 * specify the controller ID that is generated in xparameters.h
	 */
	UsbConfigPtr = LookupConfig(DeviceId);
	if (NULL == UsbConfigPtr)
		return XST_FAILURE;

	/* We are passing the physical base address as the third argument
	 * because the physical and virtual base address are the same in our
	 * example.  For systems that support virtual memory, the third
	 * argument needs to be the virtual base address.
	 */
	Status = CfgInitialize(UsbInstPtr, UsbConfigPtr,
			UsbConfigPtr->BaseAddress);
	if (XST_SUCCESS != Status)
		return XST_FAILURE;

	/* hook up chapter9 handler */
	Set_Ch9Handler(UsbInstPtr->PrivateData, Ch9Handler);

	/* Set the disconnect event handler */
	Set_Disconnect(UsbInstPtr->PrivateData, Usb_DisconnectHandler);

	/* Set the reset event handler */
	Set_RstHandler(UsbInstPtr->PrivateData, Usb_ResetHandler);

	/* Assign the data to usb driver */
	Set_DrvData(UsbInstPtr->PrivateData, &composite_data);

	/* Initialize the DFU instance structure */
	comp_dev.f_dfu.InstancePtr = UsbInstPtr;

	/* Set DFU state to APP_IDLE */
	Usb_DfuSetState(&comp_dev.f_dfu, STATE_APP_IDLE);

	/* Set the DFU descriptor pointers, so we can use it when in DFU mode */
	comp_dev.f_dfu.total_transfers = 0;
	comp_dev.f_dfu.total_bytes_dnloaded = 0;
	comp_dev.f_dfu.total_bytes_uploaded = 0;

	/* set handler for in endpoint, will be called when data is sent*/
	SetEpHandler(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_IN,
			Usb_AudioInHandler);

	/* set handler for out endpoint, will be called when data is recv*/
	SetEpHandler(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_OUT,
			Usb_AudioOutHandler);

	set_audio_transfer_size(&comp_dev.f_audio);

	/* Mass storage endpoint event hadler registration */
	SetEpHandler(UsbInstance.PrivateData, STORAGE_EP, USB_EP_DIR_OUT,
			Usb_StorageOutHandler);
	SetEpHandler(UsbInstance.PrivateData, STORAGE_EP, USB_EP_DIR_IN,
			Usb_StorageInHandler);

	/* Keyboard endpoint event hadler */
	SetEpHandler(UsbInstPtr->PrivateData, KEYBOARD_EP, USB_EP_DIR_IN,
			Usb_KeyboardInHabdler);
	/* setup interrupts */
	Status = SetupInterruptSystem(UsbInstPtr->PrivateData, IntcDeviceID,
			UsbIntrId, (void *)IntrInstPtr);
	if (Status != XST_SUCCESS)
		return XST_FAILURE;

	/* Start the controller so that Host can see our device */
	Usb_Start(UsbInstPtr->PrivateData);

	while (1) {

		/* After configuration done start sending key */
		while(GetConfigDone(UsbInstPtr->PrivateData)) {
			if (KeySent) {
				if (SendKey) {
					static char KeyData[8] = {2,0,0,0,0,0,0,0};

					/* get key from serial and send key */
					KeyData[2] = (inbyte() - ('a' - 4));
					EpBufferSend(UsbInstance.PrivateData, KEYBOARD_EP,
							(u8 *)&KeyData[0], 8);
					SendKey = 0;
				} else {
					/* send key release */
					EpBufferSend(UsbInstance.PrivateData, KEYBOARD_EP,
							(u8 *)&NoKeyData[0], 8);
					SendKey = 1;
				}
				KeySent = 0;
			}
		}
	}
}
/****************************************************************************/
/**
* This function is implementing USB AUDIO-DFU composte example.
*
* @param	UsbInstPtr USB instance pointer.
*		IntrInstPtr Interrupt controller instance pointer
*		DeviceId USB Device ID
*		IntcDeviceID Interrupt controller Device ID
*
* @return 	- XST_SUCCESS if successful,
*		- XST_FAILURE if unsuccessful.
*
* @note		None.
*
*****************************************************************************/
This function is implementing USB AUDIO-DFU composte example.
This function is implementing USB AUDIO - DFU composte example .
static int XUsbCompositeExample(struct Usb_DevData *UsbInstPtr,
		XScuGic *IntrInstPtr, u16 DeviceId, u16 IntcDeviceID, u16 UsbIntrId)
{
	s32 Status;
	u8 SendKey = 1;
	u8 NoKeyData[8]= {0,0,0,0,0,0,0,0};
	Usb_Config *UsbConfigPtr;
	xil_printf("USB Composite Device Start...\r\n");
	UsbConfigPtr = LookupConfig(DeviceId);
	if (NULL == UsbConfigPtr)
		return XST_FAILURE;
	Status = CfgInitialize(UsbInstPtr, UsbConfigPtr,
			UsbConfigPtr->BaseAddress);
	if (XST_SUCCESS != Status)
		return XST_FAILURE;
	Set_Ch9Handler(UsbInstPtr->PrivateData, Ch9Handler);
	Set_Disconnect(UsbInstPtr->PrivateData, Usb_DisconnectHandler);
	Set_RstHandler(UsbInstPtr->PrivateData, Usb_ResetHandler);
	Set_DrvData(UsbInstPtr->PrivateData, &composite_data);
	comp_dev.f_dfu.InstancePtr = UsbInstPtr;
	Usb_DfuSetState(&comp_dev.f_dfu, STATE_APP_IDLE);
	comp_dev.f_dfu.total_transfers = 0;
	comp_dev.f_dfu.total_bytes_dnloaded = 0;
	comp_dev.f_dfu.total_bytes_uploaded = 0;
	SetEpHandler(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_IN,
			Usb_AudioInHandler);
	SetEpHandler(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_OUT,
			Usb_AudioOutHandler);
	set_audio_transfer_size(&comp_dev.f_audio);
	SetEpHandler(UsbInstance.PrivateData, STORAGE_EP, USB_EP_DIR_OUT,
			Usb_StorageOutHandler);
	SetEpHandler(UsbInstance.PrivateData, STORAGE_EP, USB_EP_DIR_IN,
			Usb_StorageInHandler);
	SetEpHandler(UsbInstPtr->PrivateData, KEYBOARD_EP, USB_EP_DIR_IN,
			Usb_KeyboardInHabdler);
	Status = SetupInterruptSystem(UsbInstPtr->PrivateData, IntcDeviceID,
			UsbIntrId, (void *)IntrInstPtr);
	if (Status != XST_SUCCESS)
		return XST_FAILURE;
	Usb_Start(UsbInstPtr->PrivateData);
	while (1) {
		while(GetConfigDone(UsbInstPtr->PrivateData)) {
			if (KeySent) {
				if (SendKey) {
					static char KeyData[8] = {2,0,0,0,0,0,0,0};
					KeyData[2] = (inbyte() - ('a' - 4));
					EpBufferSend(UsbInstance.PrivateData, KEYBOARD_EP,
							(u8 *)&KeyData[0], 8);
					SendKey = 0;
				} else {
					EpBufferSend(UsbInstance.PrivateData, KEYBOARD_EP,
							(u8 *)&NoKeyData[0], 8);
					SendKey = 1;
				}
				KeySent = 0;
			}
		}
	}
}
static int XUsbCompositeExample ( struct Usb_DevData * UsbInstPtr , XScuGic * IntrInstPtr , u16 DeviceId , u16 IntcDeviceID , u16 UsbIntrId ) { s32 Status ; u8 SendKey = 1 ; u8 NoKeyData [ 8 ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ; Usb_Config * UsbConfigPtr ; xil_printf ( " \r \n " ) ; UsbConfigPtr = LookupConfig ( DeviceId ) ; if ( NULL == UsbConfigPtr ) return XST_FAILURE ; Status = CfgInitialize ( UsbInstPtr , UsbConfigPtr , UsbConfigPtr -> BaseAddress ) ; if ( XST_SUCCESS != Status ) return XST_FAILURE ; Set_Ch9Handler ( UsbInstPtr -> PrivateData , Ch9Handler ) ; Set_Disconnect ( UsbInstPtr -> PrivateData , Usb_DisconnectHandler ) ; Set_RstHandler ( UsbInstPtr -> PrivateData , Usb_ResetHandler ) ; Set_DrvData ( UsbInstPtr -> PrivateData , & composite_data ) ; comp_dev . f_dfu . InstancePtr = UsbInstPtr ; Usb_DfuSetState ( & comp_dev . f_dfu , STATE_APP_IDLE ) ; comp_dev . f_dfu . total_transfers = 0 ; comp_dev . f_dfu . total_bytes_dnloaded = 0 ; comp_dev . f_dfu . total_bytes_uploaded = 0 ; SetEpHandler ( UsbInstPtr -> PrivateData , ISO_EP , USB_EP_DIR_IN , Usb_AudioInHandler ) ; SetEpHandler ( UsbInstPtr -> PrivateData , ISO_EP , USB_EP_DIR_OUT , Usb_AudioOutHandler ) ; set_audio_transfer_size ( & comp_dev . f_audio ) ; SetEpHandler ( UsbInstance . PrivateData , STORAGE_EP , USB_EP_DIR_OUT , Usb_StorageOutHandler ) ; SetEpHandler ( UsbInstance . PrivateData , STORAGE_EP , USB_EP_DIR_IN , Usb_StorageInHandler ) ; SetEpHandler ( UsbInstPtr -> PrivateData , KEYBOARD_EP , USB_EP_DIR_IN , Usb_KeyboardInHabdler ) ; Status = SetupInterruptSystem ( UsbInstPtr -> PrivateData , IntcDeviceID , UsbIntrId , ( void * ) IntrInstPtr ) ; if ( Status != XST_SUCCESS ) return XST_FAILURE ; Usb_Start ( UsbInstPtr -> PrivateData ) ; while ( 1 ) { while ( GetConfigDone ( UsbInstPtr -> PrivateData ) ) { if ( KeySent ) { if ( SendKey ) { static char KeyData [ 8 ] = { 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ; KeyData [ 2 ] = ( inbyte ( ) - ( ' ' - 4 ) ) ; EpBufferSend ( UsbInstance . PrivateData , KEYBOARD_EP , ( u8 * ) & KeyData [ 0 ] , 8 ) ; SendKey = 0 ; } else { EpBufferSend ( UsbInstance . PrivateData , KEYBOARD_EP , ( u8 * ) & NoKeyData [ 0 ] , 8 ) ; SendKey = 1 ; } KeySent = 0 ; } } } }
This function is implementing USB AUDIO-DFU composte example.
This function is implementing USB AUDIO - DFU composte example .
/* Initialize the USB driver so that it's ready to use,
	 * specify the controller ID that is generated in xparameters.h
	 */ /* We are passing the physical base address as the third argument
	 * because the physical and virtual base address are the same in our
	 * example.  For systems that support virtual memory, the third
	 * argument needs to be the virtual base address.
	 */ /* hook up chapter9 handler */ /* Set the disconnect event handler */ /* Set the reset event handler */ /* Assign the data to usb driver */ /* Initialize the DFU instance structure */ /* Set DFU state to APP_IDLE */ /* Set the DFU descriptor pointers, so we can use it when in DFU mode */ /* set handler for in endpoint, will be called when data is sent*/ /* set handler for out endpoint, will be called when data is recv*/ /* Mass storage endpoint event hadler registration */ /* Keyboard endpoint event hadler */ /* setup interrupts */ /* Start the controller so that Host can see our device */ /* After configuration done start sending key */ /* get key from serial and send key */ /* send key release */