fix: 修复长时间运行后HID端点状态错乱导致语音键失效和键盘错乱的问题

1. 去掉双重HID报告发送:每次按键同时调用tud_hid_n_report和Arduino封装的sendReport,导致USB端点缓冲区长时间运行后堆积状态错乱
2. 去掉错误的clear_stall调用:每次按键都检查端点busy并调用clear_stall,这是错误用法,clear_stall用于清除stall状态而非处理busy状态,频繁错误调用会导致端点状态错乱

修复后按键事件只发送一次USB报告,且不再错误调用clear_stall,解决了使用一段时间后语音键失效、麦克风不拾音、键盘错乱的问题
This commit is contained in:
imalexgao committed 2026-09-13 22:37:03 +08:00
1 parent d70c1e0a89
commit 5efccb105f
1 file changed
-29
-29
View File
@@ -152,17 +152,6 @@ bool usb_hid_keyboard_press(uint8_t modifier, uint8_t keycode) {
vTaskDelay(pdMS_TO_TICKS(15));
}
if (usbd_edpt_busy(0, 0x81)) {
usbd_edpt_clear_stall(0, 0x81);
}
// 1. Direct TinyUSB driver report
hid_keyboard_report_t kbd = {0};
kbd.modifier = modifier;
kbd.keycode[0] = keycode;
tud_hid_n_report(0, HID_REPORT_ID_KEYBOARD, &kbd, sizeof(kbd));
// 2. Arduino helper state update
KeyReport report = {0};
report.modifiers = modifier;
report.keys[0] = keycode;
@@ -176,13 +165,6 @@ bool usb_hid_keyboard_release(void) {
if (!s_usb_ready) return false;
hid_lock();
if (usbd_edpt_busy(0, 0x81)) {
usbd_edpt_clear_stall(0, 0x81);
}
hid_keyboard_report_t kbd = {0};
tud_hid_n_report(0, HID_REPORT_ID_KEYBOARD, &kbd, sizeof(kbd));
KeyReport report = {0}; // All zeroes
s_keyboard.sendReport(&report);
s_keyboard.releaseAll();
@@ -209,11 +191,6 @@ bool usb_hid_consumer_press(uint16_t usage_code) {
vTaskDelay(pdMS_TO_TICKS(10));
}
if (usbd_edpt_busy(0, 0x81)) {
usbd_edpt_clear_stall(0, 0x81);
}
tud_hid_n_report(0, HID_REPORT_ID_CONSUMER_CONTROL, &usage_code, 2);
s_consumer.press(usage_code);
hid_unlock();
@@ -224,12 +201,6 @@ bool usb_hid_consumer_release(void) {
if (!s_usb_ready) return false;
hid_lock();
if (usbd_edpt_busy(0, 0x81)) {
usbd_edpt_clear_stall(0, 0x81);
}
uint16_t zero = 0;
tud_hid_n_report(0, HID_REPORT_ID_CONSUMER_CONTROL, &zero, 2);
s_consumer.release();
hid_unlock();