mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
fix hid warning, move report descriptor template to hid.h
This commit is contained in:
parent
d1a9d52c05
commit
a2b7b9ddb9
@ -609,6 +609,106 @@ enum
|
|||||||
HID_USAGE_CONSUMER_AC_PAN = 0x0238,
|
HID_USAGE_CONSUMER_AC_PAN = 0x0238,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// HID Report Descriptor Template
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
/*------------- Keyboard Descriptor Template -------------*/
|
||||||
|
#define HID_REPORT_DESC_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) */ \
|
||||||
|
__VA_ARGS__ \
|
||||||
|
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 \
|
||||||
|
|
||||||
|
/*------------- Mouse Descriptor Template -------------*/
|
||||||
|
#define HID_REPORT_DESC_MOUSE(...) \
|
||||||
|
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
||||||
|
HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ) ,\
|
||||||
|
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
|
||||||
|
__VA_ARGS__ \
|
||||||
|
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 \
|
||||||
|
|
||||||
|
//------------- Consumer Control Report Template -------------//
|
||||||
|
#define HID_REPORT_DESC_CONSUMER(...) \
|
||||||
|
HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ) ,\
|
||||||
|
HID_USAGE ( HID_USAGE_CONSUMER_CONTROL ) ,\
|
||||||
|
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
|
||||||
|
__VA_ARGS__ \
|
||||||
|
HID_LOGICAL_MIN ( 0x00 ) ,\
|
||||||
|
HID_LOGICAL_MAX_N( 0x03FF, 2 ) ,\
|
||||||
|
HID_USAGE_MIN ( 0x00 ) ,\
|
||||||
|
HID_USAGE_MAX_N ( 0x03FF, 2 ) ,\
|
||||||
|
HID_REPORT_COUNT ( 1 ) ,\
|
||||||
|
HID_REPORT_SIZE ( 16 ) ,\
|
||||||
|
HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
|
||||||
|
HID_COLLECTION_END \
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -458,12 +458,12 @@ tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t cons
|
|||||||
}
|
}
|
||||||
else if ( HID_REQ_CONTROL_SET_REPORT == p_request->bRequest )
|
else if ( HID_REQ_CONTROL_SET_REPORT == p_request->bRequest )
|
||||||
{
|
{
|
||||||
|
usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, _usbd_ctrl_buf, p_request->wLength);
|
||||||
|
|
||||||
// wValue = Report Type | Report ID
|
// wValue = Report Type | Report ID
|
||||||
uint8_t const report_type = u16_high_u8(p_request->wValue);
|
uint8_t const report_type = u16_high_u8(p_request->wValue);
|
||||||
uint8_t const report_id = u16_low_u8(p_request->wValue);
|
uint8_t const report_id = u16_low_u8(p_request->wValue);
|
||||||
|
|
||||||
usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, _usbd_ctrl_buf, p_request->wLength);
|
|
||||||
|
|
||||||
if ( p_hid->set_report_cb )
|
if ( p_hid->set_report_cb )
|
||||||
{
|
{
|
||||||
p_hid->set_report_cb(report_id, (hid_report_type_t) report_type, _usbd_ctrl_buf, p_request->wLength);
|
p_hid->set_report_cb(report_id, (hid_report_type_t) report_type, _usbd_ctrl_buf, p_request->wLength);
|
||||||
|
@ -50,6 +50,10 @@
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Class Driver Default Configure & Validation
|
// Class Driver Default Configure & Validation
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
#ifndef CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP
|
||||||
|
#define CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
|
#if !CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
|
||||||
#error CFG_TUD_HID_KEYBOARD must be enabled
|
#error CFG_TUD_HID_KEYBOARD must be enabled
|
||||||
#endif
|
#endif
|
||||||
|
@ -118,109 +118,13 @@
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
|
||||||
/*------------- Keyboard Descriptor Template -------------*/
|
|
||||||
#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) */ \
|
|
||||||
__VA_ARGS__ \
|
|
||||||
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 \
|
|
||||||
|
|
||||||
/*------------- Mouse Descriptor Template -------------*/
|
|
||||||
#define HID_REPORT_MOUSE(...) \
|
|
||||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
|
||||||
HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ) ,\
|
|
||||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
|
|
||||||
__VA_ARGS__ \
|
|
||||||
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 \
|
|
||||||
|
|
||||||
//------------- Consumer Control Report Template -------------//
|
|
||||||
// HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ),
|
|
||||||
// HID_USAGE ( HID_USAGE_CONSUMER_CONTROL ),
|
|
||||||
// HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
|
|
||||||
// HID_REPORT_ID( REPORT_ID_CONSUMER_CONTROL ),
|
|
||||||
// HID_LOGICAL_MIN ( 0x00 ),
|
|
||||||
// HID_LOGICAL_MAX_N( 0x03FF, 2 ),
|
|
||||||
// HID_USAGE_MIN ( 0x00 ),
|
|
||||||
// HID_USAGE_MAX_N ( 0x03FF, 2 ),
|
|
||||||
// HID_REPORT_COUNT ( 1 ),
|
|
||||||
// HID_REPORT_SIZE ( 16 ),
|
|
||||||
// HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ),
|
|
||||||
// HID_COLLECTION_END,
|
|
||||||
|
|
||||||
|
|
||||||
/*------------- Boot Protocol Report Descriptor -------------*/
|
/*------------- Boot Protocol Report Descriptor -------------*/
|
||||||
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
|
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
|
||||||
uint8_t const _desc_auto_hid_boot_kbd_report[] = { HID_REPORT_KEYBOARD() };
|
uint8_t const _desc_auto_hid_boot_kbd_report[] = { HID_REPORT_DESC_KEYBOARD() };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT
|
#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT
|
||||||
uint8_t const _desc_auto_hid_boot_mse_report[] = { HID_REPORT_MOUSE() };
|
uint8_t const _desc_auto_hid_boot_mse_report[] = { HID_REPORT_DESC_MOUSE() };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -235,11 +139,11 @@ uint8_t const _desc_auto_hid_boot_mse_report[] = { HID_REPORT_MOUSE() };
|
|||||||
uint8_t const _desc_auto_hid_generic_report[] =
|
uint8_t const _desc_auto_hid_generic_report[] =
|
||||||
{
|
{
|
||||||
#if CFG_TUD_HID_KEYBOARD && !CFG_TUD_HID_KEYBOARD_BOOT
|
#if CFG_TUD_HID_KEYBOARD && !CFG_TUD_HID_KEYBOARD_BOOT
|
||||||
HID_REPORT_KEYBOARD( HID_REPORT_ID(1), ),
|
HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(1), ),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CFG_TUD_HID_MOUSE && !CFG_TUD_HID_MOUSE_BOOT
|
#if CFG_TUD_HID_MOUSE && !CFG_TUD_HID_MOUSE_BOOT
|
||||||
HID_REPORT_MOUSE( HID_REPORT_ID(2), )
|
HID_REPORT_DESC_MOUSE( HID_REPORT_ID(2), )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user