HID报告请求



我在使用嵌入式控制器作为主机与USB读卡器通信时遇到了困难。有了极大的耐心,我已经能够发送控制事务并操纵led,并且当插入卡时,我能够在IN管道上接收状态更新。我不能做的是在控制管道上发送我认为应该是报告请求来请求卡片数据。

我的问题是如何设置此报告请求以获得HID读卡器向我发送卡数据(报告ID = 0x65,使用ID = 0x61C)?如果我的理解是正确的,这应该归结为对设置包中的标志的简单操作,但对于我的生命,我无法弄清楚哪些是正确的。

以下代码用于设置在控制EP上发送的set_config事务

:
//Format the setup transaction 
req.bmRequestType = USB_REQ_DIR_OUT         |   // 7    - Transfer is OUT   
USB_REQ_TYPE_CLASS      |   // 5,6  - Transfer type is Class 
USB_REQ_RECIP_INTERFACE;    // 4    - recipient is the device
//Set the request type to USB_REQ_SET_CONFIGURATION
req.bRequest = USB_REQ_SET_CONFIGURATION;   
//Set the descriptor type to string
req.wValue = (USB_DT_STRING << 8) | usb_dt;     //wValue type. On Linux ==> 0x302 for init msg,
//                          0x35f for led on control
req.wIndex = 0;                         
req.wLength = len;  

该函数使用0x302中传递的值作为初始化消息,0x35f用于LED控制。然后,它开始传输,为所需命令移动包含索引0处报告ID的缓冲区,然后是一些数据(RGB值)。

最后这里是我正在使用的设备的描述符:

设备描述符:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x6352
idProduct 0x240a
bcdDevice 3.01
immanufacturer1
iProduct 2
isserier3
bNumConfigurations 1
配置描述符:
bLength9
bDescriptorType 2
wTotalLength 0x0022
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 3
bmatattributes 0x80
(Bus Powered)
MaxPower 500mA

接口描述符:
长度9
bDescriptorType 4
bInterfaceNumber 0
balternatessetting 0
bNumEndpoints 1
bInterfaceClass 3人机接口设备
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 4

HID设备描述符:
长度9
bDescriptorType 33
bcdHID 1.11
bCountryCode 0不支持
bNumDescriptors 1
bDescriptorType 34报告
wDescriptorLength 730

端点描述符:
长度7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmatattributes 3
传输类型中断
同步类型无
使用类型Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 46


-Justin

啊哈!我没有意识到16位wValue字段需要包含报表Id。解决方案是双重的,首先将有效负载的第一个字节设置为应用程序级别的报告ID。然后,在问题设置中显示的低级请求描述符中,wValue字段如下所示:

点播。wValue = (USB_DT_STRING <<8) | pkt[0];

最新更新