在 dmesg 中报告了一个设备:
[ 7679.312788] hid-generic 0003:16D0:0E70.0012: hiddev0,hidraw0: USB HID v1.01 Device [.de.nonchip TinyStick HIDSTM1640] on usb-0000:00:13.0-3/input0
实际的 HID 描述符(我将其放入设备的固件中,未嗅探+解码)如下:
PROGMEM const char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { /* USB report descriptor */
0x06, 0x00, 0xff, // USAGE_PAGE (Generic Desktop)
0x09, 0x01, // USAGE (Vendor Usage 1)
0xa1, 0x01, // COLLECTION (Application)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x08, // REPORT_COUNT (8)
0x09, 0x00, // USAGE (Undefined)
0x82, 0x02, 0x01, // INPUT (Data,Var,Abs,Buf)
0x95, 32, // REPORT_COUNT (32)
0x09, 0x00, // USAGE (Undefined)
0xb2, 0x02, 0x01, // FEATURE (Data,Var,Abs,Buf)
0xc0 // END_COLLECTION
};
字符串描述符定义为:
#define USB_CFG_VENDOR_NAME '.','d','e','.','n','o','n','c','h','i','p'
#define USB_CFG_VENDOR_NAME_LEN 11
#define USB_CFG_DEVICE_NAME 'T','i','n','y','S','t','i','c','k',' ','H','I','D','S','T','M','1','6','4','0'
#define USB_CFG_DEVICE_NAME_LEN 20
我在 hidapi 中使用以下代码来(尝试)找到它:
#define HIDSERIAL_VENDOR_ID 0x16d0
#define HIDSERIAL_PRODUCT_ID 0x0E70
#define HIDSERIAL_MANUFACTURER_STRING L".de.nonchip"
#define HIDSERIAL_PRODUCT_STRING L"TinyStick HIDSTM1640"
hid_device* hidserial_find_device(void){
hid_device *handle = NULL;
hid_init();
// Enumerate and print the HID devices on the system
struct hid_device_info *devs, *cur_dev;
devs = hid_enumerate(HIDSERIAL_VENDOR_ID, HIDSERIAL_PRODUCT_ID);
cur_dev = devs;
while (cur_dev) {
wprintf(L"%ls %ls\n", cur_dev->manufacturer_string, cur_dev->product_string); // <------ DEBUG
if( cur_dev->manufacturer_string!=NULL && cur_dev->product_string!=NULL &&
0==wcscmp(HIDSERIAL_MANUFACTURER_STRING,cur_dev->manufacturer_string) &&
0==wcscmp(HIDSERIAL_PRODUCT_STRING,cur_dev->product_string)){
handle = hid_open_path(cur_dev->path);
break;
}
cur_dev = cur_dev->next;
}
hid_free_enumeration(devs);
return handle;
}
我的问题是,虽然内核正确报告了该设备,但未找到该设备。调试输出显示单行(null) (null)
,这表明设备已通过其 VID:PID 对枚举,但字符串突然为空。我没有收到任何错误(人们可能会期待“权限被拒绝”之类的东西,但没有报告任何内容,甚至以 root 身份运行它似乎也无济于事)......