add tud_hid_n_gamepad_report() helper for gamepad report
- Add gamepad to hid_composite example. Though it needs a bit of extra work but it will come later as separated PR.
This commit is contained in:
@@ -183,6 +183,35 @@ void hid_task(void)
|
||||
if (has_consumer_key) tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &empty_key, 2);
|
||||
has_consumer_key = false;
|
||||
}
|
||||
|
||||
// delay a bit before sending next report
|
||||
board_delay(10);
|
||||
}
|
||||
|
||||
/*------------- Gamepad -------------*/
|
||||
if ( tud_hid_ready() )
|
||||
{
|
||||
// use to avoid send multiple consecutive zero report for keyboard
|
||||
static bool has_gamepad_key = false;
|
||||
|
||||
hid_gamepad_report_t report =
|
||||
{
|
||||
.x = 0, .y = 0, .z = 0, .rz = 0, .rx = 0, .ry = 0,
|
||||
.hat = 0, .buttons = 0
|
||||
};
|
||||
|
||||
if ( btn )
|
||||
{
|
||||
report.hat = GAMEPAD_HAT_UP;
|
||||
tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report));
|
||||
|
||||
has_gamepad_key = true;
|
||||
}else
|
||||
{
|
||||
report.hat = GAMEPAD_HAT_CENTERED;
|
||||
if (has_gamepad_key) tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report));
|
||||
has_gamepad_key = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -75,7 +75,8 @@ 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 )),
|
||||
TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(REPORT_ID_CONSUMER_CONTROL ))
|
||||
TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(REPORT_ID_CONSUMER_CONTROL )),
|
||||
TUD_HID_REPORT_DESC_GAMEPAD ( HID_REPORT_ID(REPORT_ID_GAMEPAD ))
|
||||
};
|
||||
|
||||
// Invoked when received GET HID REPORT DESCRIPTOR
|
||||
|
@@ -30,6 +30,7 @@ enum
|
||||
REPORT_ID_KEYBOARD = 1,
|
||||
REPORT_ID_MOUSE,
|
||||
REPORT_ID_CONSUMER_CONTROL,
|
||||
REPORT_ID_GAMEPAD
|
||||
};
|
||||
|
||||
#endif /* USB_DESCRIPTORS_H_ */
|
||||
|
@@ -140,11 +140,11 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
|
||||
char const* string_desc_arr [] =
|
||||
{
|
||||
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
||||
"TinyUSB", // 1: Manufacturer
|
||||
"TinyUSB Device", // 2: Product
|
||||
"123456", // 3: Serials, should use chip ID
|
||||
"Keyboard Interface", // 4: Interface 1 String
|
||||
"Mouse Interface", // 5: Interface 2 String
|
||||
"TinyUSB", // 1: Manufacturer
|
||||
"TinyUSB Device", // 2: Product
|
||||
"123456", // 3: Serials, should use chip ID
|
||||
"Keyboard Interface", // 4: Interface 1 String
|
||||
"Mouse Interface", // 5: Interface 2 String
|
||||
};
|
||||
|
||||
static uint16_t _desc_str[32];
|
||||
|
Reference in New Issue
Block a user