启动时等待usb连接

This commit is contained in:
zqm
2026-04-09 08:55:43 +08:00
parent 708a7c8bf0
commit cd7d033e3e
45 changed files with 7843 additions and 11716 deletions

View File

@@ -92,7 +92,9 @@ void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_
// 暴露给 Rust 的函数
bool rust_is_usb_mounted() {
return tud_mounted();
bool mounted = tud_mounted();
ESP_LOGD(TAG, "USB mounted state: %d", mounted);
return mounted;
}
void rust_send_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t const* keycode) {
@@ -145,12 +147,29 @@ void app_main(void)
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
ESP_LOGI(TAG, "✅ USB HID 设备启动成功");
ESP_LOGI(TAG, "请连接 USB OTG 线到电脑");
ESP_LOGI(TAG, "启动 Rust 应用...");
rust_app_wrapper_init();
// 暂时禁用 Rust 应用,先测试 USB 稳定性
// rust_app_wrapper_init();
int count = 0;
bool last_mounted = false;
while (1) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
ESP_LOGI(TAG, "USB 设备运行中...");
bool mounted = tud_mounted();
if (mounted != last_mounted) {
if (mounted) {
ESP_LOGI(TAG, "🔌 USB 已连接到主机");
} else {
ESP_LOGI(TAG, "🔌 USB 已断开");
}
last_mounted = mounted;
}
if (count % 10 == 0) {
ESP_LOGI(TAG, "USB 设备运行中... 挂载状态: %s", mounted ? "已连接" : "未连接");
}
count++;
}
}