⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_descriptor.c

📁 IT projecotr reference design.
💻 C
📖 第 1 页 / 共 3 页
字号:

		switch(Mode)
		{
		case USBMAIN_FACTORYMODE:
			if (DevDescData_FactoryMode.bLength <= Req_Len)
				send_length = DevDescData_FactoryMode.bLength;
			else
				send_length = Req_Len;

			result = USB_WriteData(Ep, (uint32 *)(&DevDescData_FactoryMode), send_length);
            if (result != PASS)
                return(result);  
        
            /*Send zero length packet to end the transfer if required.*/
            if ((send_length < Req_Len) &&
                ((send_length % Max_Pkt) == 0))
                USB_WriteData(Ep, &zero_buffer, 0); 

			result = PASS;
			break;

		case USBMAIN_USERMODE:
			if (DevDescData_UserMode.bLength <= Req_Len)
				send_length = DevDescData_UserMode.bLength;
			else
				send_length = Req_Len;

			result = USB_WriteData(Ep, (uint32 *)(&DevDescData_UserMode), send_length);
            if (result != PASS)
                return(result);  
        
            /*Send zero length packet to end the transfer if required.*/
            if ((send_length < Req_Len) &&
                ((send_length % Max_Pkt) == 0))
                USB_WriteData(Ep, &zero_buffer, 0); 

			result = PASS;
			break;

		default:
			break;
		};
		break;

	case USB_CONFIG_DESC_TYPE:
		switch(Mode)
		{
		case USBMAIN_FACTORYMODE:
			if (ConfigDescData_FactoryMode.wTotalLength <= Req_Len)
				send_length = ConfigDescData_FactoryMode.wTotalLength;
			else
				send_length = Req_Len;

			/* Because the config desc data is > 64 bytes, we must transfer data twice
			   Once here and the second when we receive an IN from the Host */
			memcpy((void*)&ep->send_data[0], &ConfigDesc_Array_FactoryMode, send_length);
			
			ep->send_total_len = send_length;
			ep->send_actual_len = 0;
			
			if ((send_length < Req_Len) && ((send_length % Max_Pkt) == 0))
				ep->send_zero_byte = TRUE;
			else
			ep->send_zero_byte = FALSE;
				
			result = USBMAIN_SendDataHandler(Ep);						
        
			break;

		case USBMAIN_USERMODE:
			if (ConfigDescData_UserMode.wTotalLength <= Req_Len)
				send_length = ConfigDescData_UserMode.wTotalLength;
			else
				send_length = Req_Len;

			result = USB_WriteData(Ep, (uint32 *)(&ConfigDesc_Array_UserMode), send_length);
            if (result != PASS)
                return(result);  
        
            /*Send zero length packet to end the transfer if required.*/
            if ((send_length < Req_Len) && ((send_length % Max_Pkt) == 0))
                USB_WriteData(Ep, &zero_buffer, 0); 
			
			result = PASS;
			break;

		default:
			break;
		};

		break;

	case USB_STRING_DESC_TYPE:
		if ((Desc_Idx == USBDESC_STRING_LANGID_IDX) ||
			(wIndex == USBDESC_LANGID_US_ENGLISH))
		{
		    stringPtr = (USB_STRING_DESC*)StringDesc_Array[Desc_Idx];
       
            if (stringPtr->bLength <= Req_Len)
                send_length = stringPtr->bLength; 
            else
                send_length = Req_Len; 
              
            result = USB_WriteData(Ep, ((uint32 *)stringPtr), send_length);
            if (result != PASS)
                return(result);  
        
            /*Send zero length packet to end the transfer if required.*/
            if ((send_length < Req_Len) && ((send_length % Max_Pkt) == 0))
                USB_WriteData(Ep, &zero_buffer, 0);
		
			result = PASS;
		}
		else
		{
			/*unsupported language, and Desc_Idx != USBDESC_STRING_LANGID_IDX 
			(i.e. LANGID codes string descriptor not being requested*/
		}
		break;

	case USB_HID_DESC_TYPE:
		switch(Mode)
		{
		case USBMAIN_FACTORYMODE:
			if (wIndex == USB_INTERFACE_1)
			{
				if (USBDESC_HID_LENGTH_MOUSE <= Req_Len)
					send_length = USBDESC_HID_LENGTH_MOUSE;
				else
					send_length = Req_Len;
					
				result = USB_WriteData(Ep, ((uint32 *)&HidDescData_Mouse), send_length);
                if (result != PASS)
                    return(result);  
        
                /*Send zero length packet to end the transfer if required.*/
                if ((send_length < Req_Len) && ((send_length % Max_Pkt) == 0))
                    USB_WriteData(Ep, &zero_buffer, 0);	
                    
				result = PASS;
			}
			else if (wIndex == USB_INTERFACE_2)
			{
				if (USBDESC_HID_LENGTH_KEYBOARD <= Req_Len)
					send_length = USBDESC_HID_LENGTH_KEYBOARD;
				else
					send_length = Req_Len;
					
				result = USB_WriteData(Ep, ((uint32 *)&HidDescData_Keyboard), send_length);
                if (result != PASS)
                    return(result);  
        
                /*Send zero length packet to end the transfer if required.*/
                if ((send_length < Req_Len) && ((send_length % Max_Pkt) == 0))
                    USB_WriteData(Ep, &zero_buffer, 0);	
                    
				result = PASS;
			}
			break;

		case USBMAIN_USERMODE:
			if (wIndex == USB_INTERFACE_0)
			{
				if (USBDESC_HID_LENGTH_MOUSE <= Req_Len)
					send_length = USBDESC_HID_LENGTH_MOUSE;
				else
					send_length = Req_Len;
					
				result = USB_WriteData(Ep, ((uint32 *)&HidDescData_Mouse), send_length);
                if (result != PASS)
                    return(result);  
        
                /*Send zero length packet to end the transfer if required.*/
                if ((send_length < Req_Len) && ((send_length % Max_Pkt) == 0))
                    USB_WriteData(Ep, &zero_buffer, 0);	
                    
				result = PASS;
			}
			else if (wIndex == USB_INTERFACE_1)
			{
				if (USBDESC_HID_LENGTH_KEYBOARD <= Req_Len)
					send_length = USBDESC_HID_LENGTH_KEYBOARD;
				else
					send_length = Req_Len;
					
				result = USB_WriteData(Ep, ((uint32 *)&HidDescData_Keyboard), send_length);
                if (result != PASS)
                    return(result);  
        
                /*Send zero length packet to end the transfer if required.*/
                if ((send_length < Req_Len) && ((send_length % Max_Pkt) == 0))
                    USB_WriteData(Ep, &zero_buffer, 0);	
                    
				result = PASS;
			}
			break;

		default:
			break;
		};
		break;

	case USB_HID_REPORT_DESC_TYPE:
		switch(Mode)
		{
		case USBMAIN_FACTORYMODE:
			if (wIndex == USB_INTERFACE_1)
			{
				if (USBDESC_REPORT_LENGTH_MOUSE <= Req_Len)
					send_length = USBDESC_REPORT_LENGTH_MOUSE;
				else
					send_length = Req_Len;
					
				result = USB_WriteData(Ep, ((uint32 *)&ReportDescriptor_Mouse), send_length);
                if (result != PASS)
                    return(result);  
        
                /*Send zero length packet to end the transfer if required.*/
                if ((send_length < Req_Len) && ((send_length % Max_Pkt) == 0))
                    USB_WriteData(Ep, &zero_buffer, 0);		
					
				result = PASS;
			}
			else if ( wIndex == USB_INTERFACE_2 )
			{
				if (USBDESC_REPORT_LENGTH_KEYBOARD <= Req_Len)
					send_length = USBDESC_REPORT_LENGTH_KEYBOARD;
				else
					send_length = Req_Len;
					
				result = USB_WriteData(Ep, ((uint32 *)&ReportDescriptor_Keyboard), send_length);
                if (result != PASS)
                    return(result);  
        
                /*Send zero length packet to end the transfer if required.*/
                if ((send_length < Req_Len) && ((send_length % Max_Pkt) == 0))
                    USB_WriteData(Ep, &zero_buffer, 0);		
					
				result = PASS;
			}
			break;
			
		case USBMAIN_USERMODE:
			if (wIndex == USB_INTERFACE_0)
			{
				if (USBDESC_REPORT_LENGTH_MOUSE <= Req_Len)
					send_length = USBDESC_REPORT_LENGTH_MOUSE;
				else
					send_length = Req_Len;
					
				result = USB_WriteData(Ep, ((uint32 *)&ReportDescriptor_Mouse), send_length);
                if (result != PASS)
                    return(result);  
        
                /*Send zero length packet to end the transfer if required.*/
                if ((send_length < Req_Len) && ((send_length % Max_Pkt) == 0))
                    USB_WriteData(Ep, &zero_buffer, 0);		
					
				result = PASS;
			}
			else if ( wIndex == USB_INTERFACE_1 )
			{
				if (USBDESC_REPORT_LENGTH_KEYBOARD <= Req_Len)
					send_length = USBDESC_REPORT_LENGTH_KEYBOARD;
				else
					send_length = Req_Len;
					
				result = USB_WriteData(Ep, ((uint32 *)&ReportDescriptor_Keyboard), send_length);
                if (result != PASS)
                    return(result);  
        
                /*Send zero length packet to end the transfer if required.*/
                if ((send_length < Req_Len) && ((send_length % Max_Pkt) == 0))
                    USB_WriteData(Ep, &zero_buffer, 0);		
					
				result = PASS;
			}
			break;

		default:
			break;
		};
		break;

	default:
		break;
	};


	return(result);
}	
  
  










⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -