终于,键盘鼠标都成功了

This commit is contained in:
zqm
2026-04-09 14:21:34 +08:00
parent aae527258a
commit 64a42bebbc
26 changed files with 7491 additions and 5659 deletions

View File

@@ -41,14 +41,14 @@ static tusb_desc_device_t const desc_device =
.bNumConfigurations = 0x01
};
// 独立键盘描述符
// 独立键盘描述符(去掉 Report ID使用单 Report 模式)
uint8_t const desc_hid_report_kb[] = {
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(REPORT_ID_KEYBOARD))
TUD_HID_REPORT_DESC_KEYBOARD()
};
// 独立鼠标描述符
// 独立鼠标描述符(去掉 Report ID使用单 Report 模式)
uint8_t const desc_hid_report_mouse[] = {
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(REPORT_ID_MOUSE))
TUD_HID_REPORT_DESC_MOUSE()
};
// 按接口返回正确描述符
@@ -131,17 +131,24 @@ bool rust_is_usb_mounted() {
}
//====================================================================
// 键盘函数(不动
// 键盘函数(修复:去掉 Report ID
//====================================================================
void rust_send_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t const* keycode) {
tud_hid_keyboard_report(report_id, modifier, keycode);
// 描述符现在没有 Report ID所以传入 0
tud_hid_keyboard_report(0, modifier, keycode);
}
//====================================================================
// 鼠标函数(正确 6 参数版
// 鼠标函数(修复:使用 tud_hid_n_mouse_report 指定 instance
//====================================================================
void rust_send_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t wheel, int8_t pan) {
tud_hid_mouse_report(report_id, buttons, x, y, wheel, pan);
ESP_LOGI(TAG, "Mouse report: btn=%d, x=%d, y=%d", buttons, x, y);
// 关键修复:使用 tud_hid_n_mouse_report 并指定正确的 instance
// ITF_NUM_KEYBOARD = 0 (键盘), ITF_NUM_MOUSE = 1 (鼠标)
// 描述符没有 Report ID所以 report_id 传 0
bool result = tud_hid_n_mouse_report(ITF_NUM_MOUSE, 0, buttons, x, y, wheel, pan);
ESP_LOGI(TAG, "tud_hid_n_mouse_report result: %s", result ? "success" : "failed");
}
// 暴露 FreeRTOS 函数给 Rust