感觉书上UsbEp0SendData函数写得太麻烦,于是修改了一下,感觉还是可以用的,呵呵!
1.
UsbEp0SendData的代码
-
uint8* pSendBuf;
-
uint8 remain_len;
-
void UsbEp0SendData()
-
{
-
//SendBuf[7]是端点0最大包长
-
if(remain_len == DevDesc[7])
-
{
-
print_hex_buf(pSendBuf, DevDesc[7]);
-
D12WriteEndpBuf(pSendBuf, DevDesc[7], 1);
-
D12WriteEndpBuf(pSendBuf, 0, 1);
-
remain_len = 0;
-
return ;
-
}
-
-
if(remain_len < DevDesc[7])
-
{
-
print_hex_buf(pSendBuf, remain_len);
-
D12WriteEndpBuf(pSendBuf, remain_len, 1);
-
remain_len = 0;
-
pSendBuf = NULL;
-
return ;
-
}
-
if(remain_len > DevDesc[7])
-
{
-
print_hex_buf(pSendBuf, DevDesc[7]);
-
D12WriteEndpBuf(pSendBuf, DevDesc[7], 1);
-
pSendBuf += DevDesc[7];
-
remain_len -= DevDesc[7];
-
return ;
-
}
-
return ;
-
}
每次要发送时(以发送设备描述符DeviceDesc为例):
-
case GD_DEVICE:
-
my_printf("GD_DEVICE=0x%x\n",GD_DEVICE);
-
pSendBuf = DevDesc;
-
remain_len = DevDesc[0];
-
UsbEp0SendData();
-
break;
pSendData指向要发送的描述符,remain_len是指要发送的数据长度
2. 为了让程序上看起来更清晰一些,增加UsbEp0SendAck函数。
-
void UsbEp0SendAck(void)
-
{
-
D12WriteEndpBuf(pSendBuf, 0, 1); //pSendBuf没有用到,即使为空也没有关系
-
}
阅读(3060) | 评论(0) | 转发(0) |