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:
hathach
2021-02-08 19:08:16 +07:00
parent b2019e4d71
commit 72bcc0685c
7 changed files with 65 additions and 15 deletions

View File

@@ -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;
}
}
}