Exemplo n.º 1
0
// Device request parser
void SetupCommand(void)
{
   void   *dscr_ptr;

   switch(SETUPDAT[1])
   {
      case SC_GET_DESCRIPTOR:                  // *** Get Descriptor
         if(DR_GetDescriptor())
#ifdef DEBUG
            printf("GetDescriptor\n");
#endif
            switch(SETUPDAT[3])         
            {
               case GD_DEVICE:            // Device
#ifdef DEBUG
                  printf("GetDeviceDescriptor\n");
                  DumpDscr(pDeviceDscr);
#endif
                  SUDPTRH = MSB(pDeviceDscr);
                  SUDPTRL = LSB(pDeviceDscr);
                  break;
               case GD_DEVICE_QUALIFIER:            // Device Qualifier
                  SUDPTRH = MSB(pDeviceQualDscr);
                  SUDPTRL = LSB(pDeviceQualDscr);
                  break;
               case GD_CONFIGURATION:         // Configuration
                  SUDPTRH = MSB(pConfigDscr);
                  SUDPTRL = LSB(pConfigDscr);
                  break;
               case GD_OTHER_SPEED_CONFIGURATION:  // Other Speed Configuration
                  SUDPTRH = MSB(pOtherConfigDscr);
                  SUDPTRL = LSB(pOtherConfigDscr);
                  break;
               case GD_STRING:            // String
                  if(dscr_ptr = (void *)EZUSB_GetStringDscr(SETUPDAT[2]))
                  {
                     SUDPTRH = MSB(dscr_ptr);
                     SUDPTRL = LSB(dscr_ptr);
                  }
                  else 
                     EZUSB_STALL_EP0();   // Stall End Point 0
                  break;
               default:            // Invalid request
                  EZUSB_STALL_EP0();      // Stall End Point 0
            }
         break;
      case SC_GET_INTERFACE:                  // *** Get Interface
         DR_GetInterface();
         break;
      case SC_SET_INTERFACE:                  // *** Set Interface
         DR_SetInterface();
         break;
      case SC_SET_CONFIGURATION:               // *** Set Configuration
         DR_SetConfiguration();
         break;
      case SC_GET_CONFIGURATION:               // *** Get Configuration
         DR_GetConfiguration();
         break;
      case SC_GET_STATUS:                  // *** Get Status
         if(DR_GetStatus())
            switch(SETUPDAT[0])
            {
               case GS_DEVICE:            // Device
                  EP0BUF[0] = ((BYTE)Rwuen << 1) | (BYTE)Selfpwr;
                  EP0BUF[1] = 0;
                  EP0BCH = 0;
                  EP0BCL = 2;
                  break;
               case GS_INTERFACE:         // Interface
                  EP0BUF[0] = 0;
                  EP0BUF[1] = 0;
                  EP0BCH = 0;
                  EP0BCL = 2;
                  break;
               case GS_ENDPOINT:         // End Point
                  EP0BUF[0] = *(BYTE xdata *) epcs(SETUPDAT[4]) & bmEPSTALL;
                  EP0BUF[1] = 0;
                  EP0BCH = 0;
                  EP0BCL = 2;
                  break;
               default:            // Invalid Command
                  EZUSB_STALL_EP0();      // Stall End Point 0
            }
         break;
      case SC_CLEAR_FEATURE:                  // *** Clear Feature
         if(DR_ClearFeature())
            switch(SETUPDAT[0])
            {
               case FT_DEVICE:            // Device
                  if(SETUPDAT[2] == 1)
                     Rwuen = FALSE;       // Disable Remote Wakeup
                  else
                     EZUSB_STALL_EP0();   // Stall End Point 0
                  break;
               case FT_ENDPOINT:         // End Point
                  if(SETUPDAT[2] == 0)
                  {
                     *(BYTE xdata *) epcs(SETUPDAT[4]) &= ~bmEPSTALL;
                     EZUSB_RESET_DATA_TOGGLE( SETUPDAT[4] );
                  }
                  else
                     EZUSB_STALL_EP0();   // Stall End Point 0
                  break;
            }
         break;
      case SC_SET_FEATURE:                  // *** Set Feature
         if(DR_SetFeature())
            switch(SETUPDAT[0])
            {
               case FT_DEVICE:            // Device
                  if(SETUPDAT[2] == 1)
                     Rwuen = TRUE;      // Enable Remote Wakeup
                  else if(SETUPDAT[2] == 2)
                     // Set Feature Test Mode.  The core handles this request.  However, it is
                     // necessary for the firmware to complete the handshake phase of the
                     // control transfer before the chip will enter test mode.  It is also
                     // necessary for FX2 to be physically disconnected (D+ and D-)
                     // from the host before it will enter test mode.
                     break;
                  else
                     EZUSB_STALL_EP0();   // Stall End Point 0
                  break;
               case FT_ENDPOINT:         // End Point
                  *(BYTE xdata *) epcs(SETUPDAT[4]) |= bmEPSTALL;
                  break;
            }
         break;
      default:                     // *** Invalid Command
         if(DR_VendorCmnd())
            EZUSB_STALL_EP0();            // Stall End Point 0
   }

   // Acknowledge handshake phase of device request
   EP0CS |= bmHSNAK;
}
Exemplo n.º 2
0
// Device request parser
void SetupCommand(void)
{
   void   *dscr_ptr;
   BYTE    i,length;

   if ((SETUPDAT[0]==UVC_SET_INTERFACE)|(SETUPDAT[0]==UVC_GET_INTERFACE)|(SETUPDAT[0]==UVC_SET_ENDPOINT)|(SETUPDAT[0]==UVC_GET_ENDPOINT))
   {
   length = 26;//SETUPDAT[7];
	if ((SETUPDAT[1]==GET_CUR)|(SETUPDAT[1]==GET_MIN)|(SETUPDAT[1]==GET_MAX))
	{	
		for (i=0;i<length-1;i++)
		EP0BUF[i] = valuesArray[i];
		EP0BCH = 0;
		EP0BCL = length;//SETUPDAT[7];	
		

	}
	else 
	{
		// for (i=0;i<length;i++)
		// valuesArray[i]=EP0BUF[i];
			
		EP0BCH = 0; // ACK
        EP0BCL = 0; // ACK 
        

	}

		// IOA = 0xFF; 
   
   }
   else
   switch(SETUPDAT[1])
   {
	  
      case SC_GET_DESCRIPTOR:                  // *** Get Descriptor
         if(DR_GetDescriptor())
            switch(SETUPDAT[3])         
            {
               case GD_DEVICE:            // Device
			   IOA = 0x00;
                  SUDPTRH = MSB(pDeviceDscr);
                  SUDPTRL = LSB(pDeviceDscr);
                  break;
               case GD_DEVICE_QUALIFIER:            // Device Qualifier
			   	  // only retuen a device qualifier if this is a high speed
				  // capable chip.
			   	  if (HighSpeedCapable())
				  {
	                  SUDPTRH = MSB(pDeviceQualDscr);
	                  SUDPTRL = LSB(pDeviceQualDscr);
				  }
				  else
				  {
					  EZUSB_STALL_EP0();
				  }
				  break;
               case GD_CONFIGURATION:         // Configuration
                  SUDPTRH = MSB(pConfigDscr);
                  SUDPTRL = LSB(pConfigDscr);
                  break;
               case GD_OTHER_SPEED_CONFIGURATION:  // Other Speed Configuration
                  SUDPTRH = MSB(pOtherConfigDscr);
                  SUDPTRL = LSB(pOtherConfigDscr);
                  break;
               case GD_STRING:            // String
                  if(dscr_ptr = (void *)EZUSB_GetStringDscr(SETUPDAT[2]))
                  {
                     SUDPTRH = MSB(dscr_ptr);
                     SUDPTRL = LSB(dscr_ptr);
                  }
                  else 
                     EZUSB_STALL_EP0();   // Stall End Point 0
                  break;
               default:            // Invalid request
                  EZUSB_STALL_EP0();      // Stall End Point 0
            }
         break;
      case SC_GET_INTERFACE:                  // *** Get Interface
         DR_GetInterface();
         break;
      case SC_SET_INTERFACE:                  // *** Set Interface
         DR_SetInterface();
         break;
      case SC_SET_CONFIGURATION:               // *** Set Configuration
         DR_SetConfiguration();
         break;
      case SC_GET_CONFIGURATION:               // *** Get Configuration
         DR_GetConfiguration();
         break;
      case SC_GET_STATUS:                  // *** Get Status
         if(DR_GetStatus())
            switch(SETUPDAT[0])
            {
               case GS_DEVICE:            // Device
                  EP0BUF[0] = ((BYTE)Rwuen << 1) | (BYTE)Selfpwr;
                  EP0BUF[1] = 0;
                  EP0BCH = 0;
                  EP0BCL = 2;
                  break;
               case GS_INTERFACE:         // Interface
                  EP0BUF[0] = 0;
                  EP0BUF[1] = 0;
                  EP0BCH = 0;
                  EP0BCL = 2;
                  break;
               case GS_ENDPOINT:         // End Point
                  EP0BUF[0] = *(BYTE xdata *) epcs(SETUPDAT[4]) & bmEPSTALL;
                  EP0BUF[1] = 0;
                  EP0BCH = 0;
                  EP0BCL = 2;
                  break;
               default:            // Invalid Command
                  EZUSB_STALL_EP0();      // Stall End Point 0
            }
         break;
      case SC_CLEAR_FEATURE:                  // *** Clear Feature
         if(DR_ClearFeature())
            switch(SETUPDAT[0])
            {
               case FT_DEVICE:            // Device
                  if(SETUPDAT[2] == 1)
                     Rwuen = FALSE;       // Disable Remote Wakeup
                  else
                     EZUSB_STALL_EP0();   // Stall End Point 0
                  break;
               case FT_ENDPOINT:         // End Point
                  if(SETUPDAT[2] == 0)
                  {
                     *(BYTE xdata *) epcs(SETUPDAT[4]) &= ~bmEPSTALL;
                     EZUSB_RESET_DATA_TOGGLE( SETUPDAT[4] );
                  }
                  else
                     EZUSB_STALL_EP0();   // Stall End Point 0
                  break;
            }
         break;
      case SC_SET_FEATURE:                  // *** Set Feature
         if(DR_SetFeature())
            switch(SETUPDAT[0])
            {
               case FT_DEVICE:            // Device
                  if(SETUPDAT[2] == 1)
                     Rwuen = TRUE;      // Enable Remote Wakeup
                  else if(SETUPDAT[2] == 2)
                     // Set Feature Test Mode.  The core handles this request.  However, it is
                     // necessary for the firmware to complete the handshake phase of the
                     // control transfer before the chip will enter test mode.  It is also
                     // necessary for FX2 to be physically disconnected (D+ and D-)
                     // from the host before it will enter test mode.
                     break;
                  else
                     EZUSB_STALL_EP0();   // Stall End Point 0
                  break;
               case FT_ENDPOINT:         // End Point
                  *(BYTE xdata *) epcs(SETUPDAT[4]) |= bmEPSTALL;
                  break;
               default:
                  EZUSB_STALL_EP0();      // Stall End Point 0
            }
         break;
      default:                     // *** Invalid Command
         if(DR_VendorCmnd())
            EZUSB_STALL_EP0();            // Stall End Point 0
   }

   // Acknowledge handshake phase of device request
   EP0CS |= bmHSNAK;
}
Exemplo n.º 3
0
Arquivo: fw.c Projeto: emusan/HDMI2USB
// Device request parser
void SetupCommand(void)
{

   void   *dscr_ptr;
   
   
	
  
	   switch(SETUPDAT[1])
	   {

			case GET_CUR:
			case GET_MIN:
			case GET_MAX:

			
				SUDPTRCTL = 0x01;
				for (i=0;i<26;i++)
				EP0BUF[i] = valuesArray[i];
				EP0BCH = 0x00;
				SYNCDELAY;
				EP0BCL = 26;


			break;
						
			
			case SET_LINE_CODING:
				
				EUSB = 0 ;
				SUDPTRCTL = 0x01;
				EP0BCL = 0x00;
				SUDPTRCTL = 0x00;
				EUSB = 1;
				
				while (EP0BCL != 7);
				SYNCDELAY;
				for (i=0;i<7;i++)
				LineCode[i] = EP0BUF[i];

			break;


			case GET_LINE_CODING:
				
				SUDPTRCTL = 0x01;
				
				for (i=0;i<7;i++)
				EP0BUF[i] = LineCode[i];

				EP0BCH = 0x00;
				SYNCDELAY;
				EP0BCL = 7;
				SYNCDELAY;
				while (EP0CS & 0x02);
				SUDPTRCTL = 0x00;
				
			break;

		   case SET_CONTROL_STATE:
		   break;


		  case SC_GET_DESCRIPTOR: 
					 // *** Get Descriptor
		  SUDPTRCTL = 0x01;
			 if(DR_GetDescriptor())
				switch(SETUPDAT[3])         
				{
				   case GD_DEVICE:            // Device
					  SUDPTRH = MSB(pDeviceDscr);
					  SUDPTRL = LSB(pDeviceDscr);
					  break;
				   case GD_DEVICE_QUALIFIER:            // Device Qualifier
					  SUDPTRH = MSB(pDeviceQualDscr);
					  SUDPTRL = LSB(pDeviceQualDscr);
					  break;
				   case GD_CONFIGURATION:         // Configuration
					  SUDPTRH = MSB(pConfigDscr);
					  SUDPTRL = LSB(pConfigDscr);
					  break;
				   case GD_OTHER_SPEED_CONFIGURATION:  // Other Speed Configuration
					  // fx2bug - need to support multi other configs
					  SUDPTRH = MSB(pOtherConfigDscr);
					  SUDPTRL = LSB(pOtherConfigDscr);
					  break;
				   case GD_STRING:            // String
					  if(dscr_ptr = (void *)EZUSB_GetStringDscr(SETUPDAT[2]))
					  {
						 SUDPTRH = MSB(dscr_ptr);
						 SUDPTRL = LSB(dscr_ptr);
					  }
					  else 
						 EZUSB_STALL_EP0();   // Stall End Point 0
					  break;
				   default:            // Invalid request
					  EZUSB_STALL_EP0();      // Stall End Point 0
				}
			 break;
		  case SC_GET_INTERFACE:                  // *** Get Interface
			 DR_GetInterface();
			 break;
		  case SC_SET_INTERFACE:                  // *** Set Interface
			 DR_SetInterface();
			 break;
		  case SC_SET_CONFIGURATION:               // *** Set Configuration
			 DR_SetConfiguration();
			 break;
		  case SC_GET_CONFIGURATION:               // *** Get Configuration
			 DR_GetConfiguration();
			 break;
		  case SC_GET_STATUS:                  // *** Get Status
			 if(DR_GetStatus())
				switch(SETUPDAT[0])
				{
				   case GS_DEVICE:            // Device
					  EP0BUF[0] = ((BYTE)Rwuen << 1) | (BYTE)Selfpwr;
					  EP0BUF[1] = 0;
					  EP0BCH = 0;
					  EP0BCL = 2;
					  break;
				   case GS_INTERFACE:         // Interface
					  EP0BUF[0] = 0;
					  EP0BUF[1] = 0;
					  EP0BCH = 0;
					  EP0BCL = 2;
					  break;
				   case GS_ENDPOINT:         // End Point
	// fx2bug                  EP0BUF[0] = EPIO[EPID(SETUPDAT[4])].cntrl & bmEPSTALL;

					  EP0BUF[1] = 0;
					  EP0BCH = 0;
					  EP0BCL = 2;
					  break;
				   default:            // Invalid Command
					  EZUSB_STALL_EP0();      // Stall End Point 0
				}
			 break;
		  case SC_CLEAR_FEATURE:                  // *** Clear Feature
			if (SETUPDAT[0]== 0x21)
			{				
				EP0BCH = 0;
				EP0BCL = 26;
				SYNCDELAY; 
				while(EP0CS & bmEPBUSY);
				while (EP0BCL != 26);

				valuesArray[2] = EP0BUF[2]; // formate
				valuesArray[3] = EP0BUF[3];	// frame
				
				// fps 
				valuesArray[4] = fps[EP0BUF[2]-1][0];
				valuesArray[5] = fps[EP0BUF[2]-1][1];
				valuesArray[6] = fps[EP0BUF[2]-1][2];
				valuesArray[7] = fps[EP0BUF[2]-1][3];
				
				valuesArray[18] = frameSize[EP0BUF[3]-1][0];
				valuesArray[19] = frameSize[EP0BUF[3]-1][1];
				valuesArray[20] = frameSize[EP0BUF[3]-1][2];
				valuesArray[21] = frameSize[EP0BUF[3]-1][3];
				
				
				EP0BCH = 0; // ACK
				EP0BCL = 0; // ACK
			}
			
			else 
			if(DR_ClearFeature())
				switch(SETUPDAT[0])
				{
				   case FT_DEVICE:            // Device
					  if(SETUPDAT[2] == 1)
						 Rwuen = FALSE;       // Disable Remote Wakeup
					  else
						 EZUSB_STALL_EP0();   // Stall End Point 0
					  break;
				   case FT_ENDPOINT:         // End Point
					  if(SETUPDAT[2] == 0)
					  {
	// fx2bug                     EZUSB_UNSTALL_EP( EPID(SETUPDAT[4]) );
	// fx2bug                     EZUSB_RESET_DATA_TOGGLE( SETUPDAT[4] );
					  }
					  else
						 EZUSB_STALL_EP0();   // Stall End Point 0
					  break;
				}
			 break;
		  case SC_SET_FEATURE:                  // *** Set Feature
			 if(DR_SetFeature())
				switch(SETUPDAT[0])
				{
				   case FT_DEVICE:            // Device
					  if(SETUPDAT[2] == 1)
						 Rwuen = TRUE;      // Enable Remote Wakeup
					  else
						 EZUSB_STALL_EP0();   // Stall End Point 0
					  break;
				   case FT_ENDPOINT:         // End Point
	// fx2bug                  if(SETUPDAT[2] == 0)
	// fx2bug                     EZUSB_STALL_EP( EPID(SETUPDAT[4]) );
	// fx2bug                  else
						 EZUSB_STALL_EP0();    // Stall End Point 0
					  break;
				}
			 break;
		  default:                     // *** Invalid Command
			 if(DR_VendorCmnd())
				EZUSB_STALL_EP0();            // Stall End Point 0
	   }
   



   // Acknowledge handshake phase of device request
   // Required for rev C does not effect rev B
// TGE fx2bug   EP0CS |= bmBIT1; 
    EP0CS |= bmHSNAK;
}