mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
beter hid report
This commit is contained in:
parent
6034553be7
commit
c729db2294
@ -287,6 +287,7 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u
|
||||
|
||||
*p_len = 0;
|
||||
|
||||
/*------------- Boot protocol only keyboard & mouse -------------*/
|
||||
if (desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT)
|
||||
{
|
||||
TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE, ERR_TUD_INVALID_DESCRIPTOR);
|
||||
@ -326,6 +327,7 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u
|
||||
|
||||
*p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t);
|
||||
}
|
||||
/*------------- Generic (multiple report) -------------*/
|
||||
else
|
||||
{
|
||||
// TODO HID generic
|
||||
|
@ -319,13 +319,13 @@ static void usbd_reset(uint8_t rhport)
|
||||
tud_desc_set.config = _desc_auto_config;
|
||||
|
||||
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_DESC_BOOT_KEYBOARD
|
||||
extern uint8_t const _desc_auto_hid_kbd_report[];
|
||||
tud_desc_set.hid_report.boot_keyboard = _desc_auto_hid_kbd_report;
|
||||
extern uint8_t const _desc_auto_hid_boot_kbd_report[];
|
||||
tud_desc_set.hid_report.boot_keyboard = _desc_auto_hid_boot_kbd_report;
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID_MOUSE && CFG_TUD_DESC_BOOT_MOUSE
|
||||
extern uint8_t const _desc_auto_hid_mse_report[];
|
||||
tud_desc_set.hid_report.boot_mouse = _desc_auto_hid_mse_report;
|
||||
extern uint8_t const _desc_auto_hid_boot_mse_report[];
|
||||
tud_desc_set.hid_report.boot_mouse = _desc_auto_hid_boot_mse_report;
|
||||
#endif
|
||||
|
||||
#if 0 // CFG_TUD_HID_BOOT_PROTOCOL
|
||||
|
@ -122,110 +122,103 @@
|
||||
#endif
|
||||
|
||||
|
||||
// TODO HID Generic
|
||||
//--------------------------------------------------------------------+
|
||||
// HID Report Descriptors
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Keyboard Report Descriptor
|
||||
//--------------------------------------------------------------------+
|
||||
/*------------- Keyboard Descriptor -------------*/
|
||||
#if CFG_TUD_HID_KEYBOARD
|
||||
uint8_t const _desc_auto_hid_kbd_report[] = {
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ),
|
||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ),
|
||||
// 8 bits Modifier Keys (Shfit, Control, Alt)
|
||||
HID_USAGE_MIN ( 224 ),
|
||||
HID_USAGE_MAX ( 231 ),
|
||||
HID_LOGICAL_MIN ( 0 ),
|
||||
HID_LOGICAL_MAX ( 1 ),
|
||||
|
||||
HID_REPORT_COUNT ( 8 ),
|
||||
HID_REPORT_SIZE ( 1 ),
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),
|
||||
#define HID_REPORT_KEYBOARD(...) \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ) ,\
|
||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
|
||||
/* 8 bits Modifier Keys (Shfit, Control, Alt) */ \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ) ,\
|
||||
HID_USAGE_MIN ( 224 ) ,\
|
||||
HID_USAGE_MAX ( 231 ) ,\
|
||||
HID_LOGICAL_MIN ( 0 ) ,\
|
||||
HID_LOGICAL_MAX ( 1 ) ,\
|
||||
HID_REPORT_COUNT ( 8 ) ,\
|
||||
HID_REPORT_SIZE ( 1 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
|
||||
/* 8 bit reserved */ \
|
||||
HID_REPORT_COUNT ( 1 ) ,\
|
||||
HID_REPORT_SIZE ( 8 ) ,\
|
||||
HID_INPUT ( HID_CONSTANT ) ,\
|
||||
/* 6-byte Keycodes */ \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ) ,\
|
||||
HID_USAGE_MIN ( 0 ) ,\
|
||||
HID_USAGE_MAX ( 255 ) ,\
|
||||
HID_LOGICAL_MIN ( 0 ) ,\
|
||||
HID_LOGICAL_MAX ( 255 ) ,\
|
||||
HID_REPORT_COUNT ( 6 ) ,\
|
||||
HID_REPORT_SIZE ( 8 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
|
||||
/* 5-bit LED Indicator Kana | Compose | ScrollLock | CapsLock | NumLock */ \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_LED ) ,\
|
||||
HID_USAGE_MIN ( 1 ) ,\
|
||||
HID_USAGE_MAX ( 5 ) ,\
|
||||
HID_REPORT_COUNT ( 5 ) ,\
|
||||
HID_REPORT_SIZE ( 1 ) ,\
|
||||
HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
|
||||
/* led padding */ \
|
||||
HID_REPORT_COUNT ( 1 ) ,\
|
||||
HID_REPORT_SIZE ( 3 ) ,\
|
||||
HID_OUTPUT ( HID_CONSTANT ) ,\
|
||||
HID_COLLECTION_END \
|
||||
|
||||
// 8 bit reserved
|
||||
HID_REPORT_COUNT ( 1 ),
|
||||
HID_REPORT_SIZE ( 8 ),
|
||||
HID_INPUT ( HID_CONSTANT ),
|
||||
|
||||
// 6-byte Keycodes
|
||||
HID_USAGE_PAGE (HID_USAGE_PAGE_KEYBOARD),
|
||||
HID_USAGE_MIN ( 0 ),
|
||||
HID_USAGE_MAX ( 255 ),
|
||||
HID_LOGICAL_MIN ( 0 ),
|
||||
HID_LOGICAL_MAX ( 255 ),
|
||||
|
||||
HID_REPORT_COUNT ( 6 ),
|
||||
HID_REPORT_SIZE ( 8 ),
|
||||
HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ),
|
||||
|
||||
// LED Indicator Kana | Compose | Scroll Lock | CapsLock | NumLock
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_LED ),
|
||||
/* 5-bit Led report */
|
||||
HID_USAGE_MIN ( 1 ),
|
||||
HID_USAGE_MAX ( 5 ),
|
||||
HID_REPORT_COUNT ( 5 ),
|
||||
HID_REPORT_SIZE ( 1 ),
|
||||
HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),
|
||||
|
||||
/* led padding */
|
||||
HID_REPORT_COUNT ( 1 ),
|
||||
HID_REPORT_SIZE ( 3 ),
|
||||
HID_OUTPUT ( HID_CONSTANT ),
|
||||
HID_COLLECTION_END
|
||||
};
|
||||
#if CFG_TUD_DESC_BOOT_KEYBOARD
|
||||
uint8_t const _desc_auto_hid_boot_kbd_report[] = { HID_REPORT_KEYBOARD() };
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Mouse Report Descriptor
|
||||
//--------------------------------------------------------------------+
|
||||
#endif
|
||||
|
||||
/*------------- Mouse Descriptor -------------*/
|
||||
#if CFG_TUD_HID_MOUSE
|
||||
uint8_t const _desc_auto_hid_mse_report[] = {
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ),
|
||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
|
||||
HID_USAGE (HID_USAGE_DESKTOP_POINTER),
|
||||
#define HID_REPORT_MOUSE(...) \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ) ,\
|
||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_POINTER ) ,\
|
||||
HID_COLLECTION ( HID_COLLECTION_PHYSICAL ) ,\
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
|
||||
HID_USAGE_MIN ( 1 ) ,\
|
||||
HID_USAGE_MAX ( 3 ) ,\
|
||||
HID_LOGICAL_MIN ( 0 ) ,\
|
||||
HID_LOGICAL_MAX ( 1 ) ,\
|
||||
/* Left, Right, Middle, Backward, Forward mouse buttons */ \
|
||||
HID_REPORT_COUNT ( 3 ) ,\
|
||||
HID_REPORT_SIZE ( 1 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
|
||||
/* 3 bit padding */ \
|
||||
HID_REPORT_COUNT ( 1 ) ,\
|
||||
HID_REPORT_SIZE ( 5 ) ,\
|
||||
HID_INPUT ( HID_CONSTANT ) ,\
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
||||
/* X, Y position [-127, 127] */ \
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
|
||||
HID_LOGICAL_MIN ( 0x81 ) ,\
|
||||
HID_LOGICAL_MAX ( 0x7f ) ,\
|
||||
HID_REPORT_COUNT ( 2 ) ,\
|
||||
HID_REPORT_SIZE ( 8 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\
|
||||
/* Mouse scroll [-127, 127] */ \
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_WHEEL ) ,\
|
||||
HID_LOGICAL_MIN ( 0x81 ) ,\
|
||||
HID_LOGICAL_MAX ( 0x7f ) ,\
|
||||
HID_REPORT_COUNT( 1 ) ,\
|
||||
HID_REPORT_SIZE ( 8 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\
|
||||
HID_COLLECTION_END ,\
|
||||
HID_COLLECTION_END \
|
||||
|
||||
HID_COLLECTION ( HID_COLLECTION_PHYSICAL ),
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ),
|
||||
HID_USAGE_MIN ( 1 ),
|
||||
HID_USAGE_MAX ( 3 ),
|
||||
HID_LOGICAL_MIN ( 0 ),
|
||||
HID_LOGICAL_MAX ( 1 ),
|
||||
#if CFG_TUD_DESC_BOOT_MOUSE
|
||||
uint8_t const _desc_auto_hid_boot_mse_report[] = { HID_REPORT_MOUSE() };
|
||||
#endif
|
||||
|
||||
// Left, Right, Middle, Backward, Forward mouse buttons
|
||||
HID_REPORT_COUNT ( 3 ),
|
||||
HID_REPORT_SIZE ( 1 ),
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),
|
||||
|
||||
// 3 bit padding
|
||||
HID_REPORT_COUNT ( 1 ),
|
||||
HID_REPORT_SIZE ( 5 ),
|
||||
HID_INPUT ( HID_CONSTANT ),
|
||||
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
|
||||
/* X, Y position */
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_X ),
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_Y ),
|
||||
HID_LOGICAL_MIN ( 0x81 ), /* -127 */
|
||||
HID_LOGICAL_MAX ( 0x7f ), /* 127 */
|
||||
|
||||
HID_REPORT_COUNT ( 2 ),
|
||||
HID_REPORT_SIZE ( 8 ),
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ),
|
||||
|
||||
/* mouse scroll */
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_WHEEL ),
|
||||
HID_LOGICAL_MIN ( 0x81 ), /* -127 */
|
||||
HID_LOGICAL_MAX ( 0x7f ), /* 127 */
|
||||
HID_REPORT_COUNT( 1 ),
|
||||
HID_REPORT_SIZE ( 8 ),
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ),
|
||||
|
||||
HID_COLLECTION_END,
|
||||
HID_COLLECTION_END
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@ -540,7 +533,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
|
||||
.bCountryCode = HID_Local_NotSupported,
|
||||
.bNumDescriptors = 1,
|
||||
.bReportType = HID_DESC_TYPE_REPORT,
|
||||
.wReportLength = sizeof(_desc_auto_hid_kbd_report)
|
||||
.wReportLength = sizeof(_desc_auto_hid_boot_kbd_report)
|
||||
},
|
||||
|
||||
.ep_in =
|
||||
@ -580,7 +573,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
|
||||
.bCountryCode = HID_Local_NotSupported,
|
||||
.bNumDescriptors = 1,
|
||||
.bReportType = HID_DESC_TYPE_REPORT,
|
||||
.wReportLength = sizeof(_desc_auto_hid_mse_report)
|
||||
.wReportLength = sizeof(_desc_auto_hid_boot_mse_report)
|
||||
},
|
||||
|
||||
.ep_in =
|
||||
|
Loading…
x
Reference in New Issue
Block a user