usb_core.c的文件里面,这里只是选取了GETDESCRIPTOR
的程序部分,其他的部分删除了
void Data_Setup0(void)
{
uint8_t *(*CopyRoutine)(uint16_t);
RESULT Result;
uint32_t Request_No =pInformation->USBbRequest;
uint32_tRelated_Endpoint, Reserved;
uint32_t wOffset, Status;
CopyRoutine =NULL;
wOffset = 0;
//看标准请求码格式就知道了
if (Request_No ==GET_DESCRIPTOR)
{
//pInformation->USBbmRequestType是下面的两种标准请求或设备请求
if(Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
{
uint8_t wValue1 =pInformation->USBwValue1; //高一字节得到描述表种类一共有5种
if (wValue1 ==DEVICE_DESCRIPTOR) //设备描述
{
CopyRoutine = pProperty->GetDeviceDescriptor;
}
else if (wValue1 == CONFIG_DESCRIPTOR)
{
CopyRoutine = pProperty->GetConfigDescriptor;//配置描述
}
else if (wValue1 == STRING_DESCRIPTOR)
{
CopyRoutine = pProperty->GetStringDescriptor;//字符串描述
}
}
}
if(CopyRoutine)
{
pInformation->Ctrl_Info.Usb_wOffset =wOffset; //本子程序的wOffset是0
pInformation->Ctrl_Info.CopyData = CopyRoutine;//使指针pInformation->Ctrl_Info.CopyData指向CopyRoutine
(*CopyRoutine)(0); //第一次执行时Length=0 返回的是有效数据的长度存储到pInformation->Ctrl_Info.Usb_wLength
Result =USB_SUCCESS;
}
else
{ //如果标准请求不存在 看类 厂商请求中是否有
Result =(*pProperty->Class_Data_Setup)(pInformation->USBbRequest);
if (Result== USB_NOT_READY)
{
pInformation->ControlState =PAUSE;
return;
}
}
if(pInformation->Ctrl_Info.Usb_wLength ==0xFFFF) //如果字符的长度是0xffff
{
pInformation->ControlState =PAUSE;
return;
}
if ((Result == USB_UNSUPPORT) ||(pInformation->Ctrl_Info.Usb_wLength == 0))
{
pInformation->ControlState =STALLED;
return;
}
if(ValBit(pInformation->USBbmRequestType,7)) //D7表示数据传输方向1:设备向主机
{
__IOuint32_t wLength = pInformation->USBwLength;
//设置使其为USB主机设置的长度 本程序HID 鼠标 pProperty->MaxPacketSize是0x40
if(pInformation->Ctrl_Info.Usb_wLength>wLength)
//字符的长度大于主机要求的长度
{
pInformation->Ctrl_Info.Usb_wLength =wLength;
//将其设置为主机要求的
}
else if(pInformation->Ctrl_Info.Usb_wLength<pInformation->USBwLength) //字符的长度小于主机要求的
{
if (pInformation->Ctrl_Info.Usb_wLength<pProperty->MaxPacketSize) //如果字符的长度长度小于每包数据最大字节数
{
Data_Mul_MaxPacketSize = FALSE;
}
else if ((pInformation->Ctrl_Info.Usb_wLength %pProperty->MaxPacketSize) == 0) //如果是其整数倍
{
Data_Mul_MaxPacketSize = TRUE;
}
}
pInformation->Ctrl_Info.PacketSize =pProperty->MaxPacketSize;
DataStageIn();
}
else //主机向设备
{
pInformation->ControlState = OUT_DATA;
vSetEPRxStatus(EP_RX_VALID);
}
return;
} |