我正在STM3240f2上设置自定义HID设备。我主要关注的是STM的CustomHID示例。
我的报告描述符如下:
const uint8_t CustomHID_ReportDescriptor[CUSTOMHID_SIZ_REPORT_DESC] =
{
0x05, 0x01, // Global USAGE PAGE (Medical Device)
0x09, 0x05, // Local USAGE (Undefined: Cautery Board)
0xA1, 0x01, // Main COLLECTION (application)
// 6 bytes
// Output message 1 (sent from host to device)
// One bit per cautery control
0x85, 0x01, // REPORT_ID (1)
0x09, 0x05, // USAGE (Undefined: Set Cautery)
0x19, 0x01, // USAGE_MINIMUM (Ctrl 1)
0x29, 0x03, // USAGE_MAXIMUM (Ctrl 3)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x08, // REPORT_SIZE (1)
0x95, 0x01, // REPORT_COUNT (3)
0x91, 0x82, // OUTPUT (Data,Var,Abs,Vol)
// 24 bytes
// Reserved for board control
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x01, // REPORT_COUNT (1)
0x91, 0x82, // OUTPUT (Data,Var,Abs,Vol)
// 30 bytes
// Input message 1 (sent from device to host)
0x85, 0x02, // REPORT_ID (2)
0x09, 0x05, // USAGE (Push Button)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x82, // INPUT (Data,Var,Abs,Vol)
// 42 bytes
// End
0xC0 // Main END COLLECTION
//43 bytes
};
我的usbd_conf.h看起来像这样:
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
#define USBD_CFG_MAX_NUM 1
#define USBD_ITF_MAX_NUM 1
#define USB_MAX_STR_DESC_SIZ 64
#define USBD_SELF_POWERED
#define CUSTOMHID_SIZ_REPORT_DESC 43
#define CUSTOMHID_SIZ_CONFIG_DESC 41
#define HID_IN_EP 0x81
#define HID_OUT_EP 0x01
#define HID_IN_PACKET 2
#define HID_OUT_PACKET 2
我的USBD DataIn如下所示:
uint8_t USBD_HID_DataIn (void *pdev,
uint8_t epnum)
{
if (epnum == 1) PrevXferDone = 1;
return USBD_OK;
}
我像这样在systick中发送数据:
uint8_t Send_Buffer[4];
Send_Buffer[0] = 'b\x0d';
Send_Buffer[1] = 'b\x0e';
Send_Buffer[2] = 'b\x0a';
Send_Buffer[3] = 'b\x0d';
USBD_HID_SendReport (&USB_Device_dev, Send_Buffer, 4);
要尝试读取数据,我将python hid库与以下命令配合使用:
import hid
devbrd = hid.Device(0xffff,0x0001)
devbrd.read(64, 1000)
我的问题是读取总是超时并且返回空的b''
我试图弄清楚这一点的两次尝试是在gdb和wirehark中进行研究。在gdb中,我到处都放置了断点,但是当我调用devbrd.read()时,没有触发。在Wireshark中,当我devbrd.read()时,我同样也看不到任何活动。如果我调用devbrd.write(),我都会在Wireshark中看到活动并命中断点。
这是Python HID库问题吗?还是我的设备描述符有问题?还是完全其他?