用鼠标做例子不好,大家很多时候都不是要一个Windows接管的设备,而是要自己控制。不知道楼主可曾仔细看过HID SPEC。你只要简单的在Report Descriptor里面定义一个发送buf和一个接收buf,然后就可以容易调用Windows的HID API 和你的下位机通讯了。如下例。
const U8 HID_ReportDescriptor[] =
{
HID_UsagePageVendor( 0x00 ),
HID_Usage ( 0x01 ),
HID_Collection ( HID_Application ),
HID_LogicalMin ( 0 ), /* value range: 0 - 0xFF */
HID_LogicalMaxS ( 0xFF ),
HID_ReportSize ( 8 ), /* 8 bits */
HID_ReportCount ( HID_INPUT_REPORT_BYTES ),
HID_Usage ( 0x01 ),
HID_Input ( HID_Data | HID_Variable | HID_Absolute ),
HID_ReportCount ( HID_OUTPUT_REPORT_BYTES ),
HID_Usage ( 0x01 ),
HID_Output ( HID_Data | HID_Variable | HID_Absolute ),
// HID_ReportCount ( HID_FEATURE_REPORT_BYTES ),
// HID_Usage ( 0x01 ),
// HID_Feature ( HID_Data | HID_Variable | HID_Absolute ),
HID_EndCollection,
}; |