mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-08 22:01:42 +00:00
usb: Add HID device example
Closes https://github.com/espressif/esp-idf/issues/6839 Closes https://github.com/espressif/esp-idf/issues/7700
This commit is contained in:
@@ -56,8 +56,7 @@ tusb_desc_strarray_device_t descriptor_str_tinyusb = {
|
||||
"123456", // 3: Serials, should use chip ID
|
||||
"TinyUSB CDC", // 4: CDC Interface
|
||||
"TinyUSB MSC", // 5: MSC Interface
|
||||
"TinyUSB HID", // 6: HID
|
||||
"TinyUSB MIDI" // 7: MIDI
|
||||
"TinyUSB MIDI" // 6: MIDI
|
||||
};
|
||||
/* End of TinyUSB default */
|
||||
|
||||
@@ -121,28 +120,14 @@ tusb_desc_strarray_device_t descriptor_str_kconfig = {
|
||||
"",
|
||||
#endif
|
||||
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
CONFIG_TINYUSB_DESC_HID_STRING // 6: HIDs
|
||||
#else
|
||||
"",
|
||||
#endif
|
||||
|
||||
#if CONFIG_TINYUSB_MIDI_ENABLED
|
||||
CONFIG_TINYUSB_DESC_MIDI_STRING // 7: MIDI
|
||||
CONFIG_TINYUSB_DESC_MIDI_STRING // 6: MIDI
|
||||
#else
|
||||
"",
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
//------------- HID Report Descriptor -------------//
|
||||
#if CFG_TUD_HID
|
||||
enum {
|
||||
REPORT_ID_KEYBOARD = 1,
|
||||
REPORT_ID_MOUSE
|
||||
};
|
||||
#endif
|
||||
|
||||
//------------- Configuration Descriptor -------------//
|
||||
enum {
|
||||
#if CFG_TUD_CDC
|
||||
@@ -159,10 +144,6 @@ enum {
|
||||
ITF_NUM_MSC,
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID
|
||||
ITF_NUM_HID,
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_MIDI
|
||||
ITF_NUM_MIDI,
|
||||
ITF_NUM_MIDI_STREAMING,
|
||||
@@ -175,7 +156,6 @@ enum {
|
||||
TUSB_DESC_TOTAL_LEN = TUD_CONFIG_DESC_LEN +
|
||||
CFG_TUD_CDC * TUD_CDC_DESC_LEN +
|
||||
CFG_TUD_MSC * TUD_MSC_DESC_LEN +
|
||||
CFG_TUD_HID * TUD_HID_DESC_LEN +
|
||||
CFG_TUD_MIDI * TUD_MIDI_DESC_LEN
|
||||
};
|
||||
|
||||
@@ -197,24 +177,13 @@ enum {
|
||||
EPNUM_MSC,
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID
|
||||
EPNUM_HID,
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_MIDI
|
||||
EPNUM_MIDI,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if CFG_TUD_HID //HID Report Descriptor
|
||||
uint8_t const desc_hid_report[] = {
|
||||
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(REPORT_ID_KEYBOARD), ),
|
||||
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(REPORT_ID_MOUSE), )
|
||||
};
|
||||
#endif
|
||||
|
||||
uint8_t const descriptor_cfg_kconfig[] = {
|
||||
// interface count, string index, total length, attribute, power in mA
|
||||
// Configuration number, interface count, string index, total length, attribute, power in mA
|
||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, TUSB_DESC_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
||||
|
||||
#if CFG_TUD_CDC
|
||||
@@ -232,14 +201,9 @@ uint8_t const descriptor_cfg_kconfig[] = {
|
||||
TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC, 0x80 | EPNUM_MSC, 64), // highspeed 512
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID
|
||||
// Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
|
||||
TUD_HID_DESCRIPTOR(ITF_NUM_HID, 6, HID_PROTOCOL_NONE, sizeof(desc_hid_report), 0x80 | EPNUM_HID, 16, 10)
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_MIDI
|
||||
// Interface number, string index, EP Out & EP In address, EP size
|
||||
TUD_MIDI_DESCRIPTOR(ITF_NUM_MIDI, 7, EPNUM_MIDI, 0x80 | EPNUM_MIDI, 64) // highspeed 512
|
||||
TUD_MIDI_DESCRIPTOR(ITF_NUM_MIDI, 6, EPNUM_MIDI, 0x80 | EPNUM_MIDI, 64) // highspeed 512
|
||||
#endif
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user