开发环境:win7
开发板 :51单片机 + pdiusbd12 芯片
5,对接收到的主机的数据的解析的实现
-
int32_t packet_device_discriptor(standard_request_t* req)
-
{
-
int32_t ret = 0;
-
uint8_t desc_type = (req->wValue >> 8) & 0xFF;
-
-
switch(desc_type)
-
{
-
case DESC_TYPE_DEVICE:
-
Prints("设备描述符.\r\n");
-
{
-
device_descriptor_t mouse;
-
init_device_descriptor(&mouse);
-
-
send_buffer2host(ENDPOINT_CONTROL_IN,(uint8_t*)&mouse,mouse.bLength);
-
}
-
break;
-
-
case DESC_TYPE_CONFIGURATION:
-
Prints("配置描述符.\r\n");
-
break;
-
-
case DESC_TYPE_STRING:
-
Prints("字符串描述符.\r\n");
-
break;
-
-
case DESC_TYPE_INTERFACE:
-
Prints("接口描述符.\r\n");
-
break;
-
-
case DESC_TYPE_ENDPOINT:
-
Prints("端点描述符.\r\n");
-
break;
-
-
default:
-
Prints("其他描述符.\r\n");
-
break;
-
}
-
-
return ret;
-
}
-
//高低字节交换
-
#define SWAP16(x) ((((uint16_t)(x))<<8)|(((uint16_t)(x))>>8))
-
-
int32_t init_device_descriptor(device_descriptor_t * dev)
-
{
-
int32_t ret = 0;
-
-
dev->bLength = sizeof(device_descriptor_t); //设备描述符的字节数大小
-
dev->bDescriptorType = DESC_TYPE_DEVICE; //设备描述符类型编号
-
dev->bcdUSB = SWAP16(0x0110); //USB版本号
-
dev->bDeviceClass = 0x00; //USB分配的设备类代码
-
dev->bDeviceSubClass = 0x00; //USB分配的子类代码
-
dev->bDeviceProtocol = 0x00; //USB分配的设备协议代码
-
dev->bMaxPacketSize0 = PACKET_SIZE_MAX; //端点0的最大包大小
-
dev->idVendor = SWAP16(0x8888); //厂商编号
-
dev->idProduct = SWAP16(0x0001); //产品编号
-
dev->bcdDevice = SWAP16(0x0100); //设备出厂编号
-
dev->iManufacturer = 0x01; //设备厂商字符串的索引
-
dev->iProduct = 0x02; //描述产品字符串的索引
-
dev->iSerialNumber = 0x03; //描述设备序列号字符串的索引
-
dev->bNumConfigurations = 0x01; //可能的配置数量
-
-
return ret;
-
}
-
int32_t send_buffer2host(uint8_t endpoint,uint8_t *buffer,int8_t len)
-
{
-
int32_t ret = 0;
-
uint8_t index = 0;
-
-
static uint8_t *buf_ptr = NULL;
-
static int8_t sended_len = 0;
-
int8_t packet_len = 0;
-
static int8_t is_end = 0;
-
-
if(!is_end)
-
{
-
buf_ptr = buffer;
-
-
if((len-sended_len) > PACKET_SIZE_MAX)
-
{
-
packet_len = PACKET_SIZE_MAX;
-
}
-
else
-
{
-
packet_len = len - sended_len;
-
is_end = 1;
-
}
-
-
-
write_endpoint_buffer(endpoint,&buffer[sended_len],packet_len);
-
-
sended_len += packet_len;
-
}
-
else
-
{
-
buf_ptr = NULL;
-
sended_len = 0;
-
is_end = 0;
-
}
-
-
return ret;
-
}
6,运行结果
7,总结
Acknowledge Setup 命令对控制输入和控制输出都要发送。
8
,疑问
对设置地址的实现
欲了解以下内容,请看下回分解。。。
阅读(937) | 评论(0) | 转发(0) |