📄 usbgetdescriptor.c
字号:
#ifndef _USB_DEFINE
#include "USB.c"
#endif
void USBGetDescriptor(void)
{
switch (USBSetup->wValue&0x00ff)
{
case USB_GET_DESC_DEVICE :
USBEP0Buffer.Out=USBDeviceDescriptor;
USBEP0Buffer.OutLength=USBDeviceDescriptor[0]; //设备描述表长度
break;
case USB_GET_DESC_CONFIGURATION :
USBEP0Buffer.Out=USBConfigurationDescriptor;
if (USBSetup->wLength>0x1800) //配置描述标的长度
USBEP0Buffer.OutLength=sizeof(USBConfigurationDescriptor)
+ sizeof(USBInterfaceDescriptor)
+ sizeof(USBEndpoint1Descriptor)
+ sizeof(USBEndpoint2Descriptor);
else
USBEP0Buffer.OutLength=USBConfigurationDescriptor[0];
break;
case USB_GET_DESC_STRING :
switch (USBEP0Buffer.In[2])
{
case 0x00 :
USBEP0Buffer.Out=USBString1Descriptor;
USBEP0Buffer.OutLength=sizeof(USBString1Descriptor);
break;
case 0x01 :
USBEP0Buffer.Out=USBString3Descriptor;
USBEP0Buffer.OutLength=sizeof(USBString3Descriptor);
break;
case 0x02 :
USBEP0Buffer.Out=USBString3Descriptor;
USBEP0Buffer.OutLength=sizeof(USBString3Descriptor);
break;
case 0x03 :
USBEP0Buffer.Out=USBString3Descriptor;
USBEP0Buffer.OutLength=sizeof(USBString3Descriptor);
break;
}
break;
case USB_GET_DESC_INTERFACE :
USBEP0Buffer.Out=USBInterfaceDescriptor;
USBEP0Buffer.OutLength=sizeof(USBInterfaceDescriptor);
break;
case USB_GET_DESC_ENDPOINT :
USBEP0Buffer.Out=USBEndpoint1Descriptor;
USBEP0Buffer.OutLength=sizeof(USBEndpoint1Descriptor);
break;
default :
break;
}
USBEP0WritePacket();
if (USBEP0Buffer.OutLength==0x20&&USBSetup->wLength>0x2000) //发送0字节包
{
SET_BIT_7(UEPSTAX); //设置DIR
SET_BIT_4(UEPSTAX); //设置TXRDY
while(!( UEPSTAX & 0x01 )); //等待TXCMP
CLEAR_BIT_0(UEPSTAX); //清除TXCMP
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -