设置可高度的Relase版本,不然Usb没法枚举,Debug速度太慢

This commit is contained in:
zqm
2026-04-07 17:09:58 +08:00
parent 380d7e9130
commit faa0b3cb5e
2091 changed files with 23969 additions and 19851 deletions

View File

@@ -14,12 +14,62 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
}
}
// HID 键码常量
const HID_KEY_A: u8 = 0x04;
const REPORT_ID_KEYBOARD: u8 = 1;
const PD_MS_TO_TICKS: u32 = 1;
// FFI 函数声明
extern "C" {
fn rust_is_usb_mounted() -> bool;
fn rust_send_keyboard_report(report_id: u8, modifier: u8, keycode: *const u8);
fn rust_vTaskDelay(xTicksToDelay: u32);
}
#[no_mangle]
extern "C" fn rust_app_main() {
// 初始化代码
send_a_key();
return;
}
#[export_name = "rust_usb_callback"]
pub unsafe extern "C" fn usb_callback(_event: u32) {
}
/// 发送 A 键的按键事件
fn send_a_key() {
// 等待 USB 设备挂载
let mut mounted = false;
for _ in 0..10 {
mounted = unsafe {
rust_is_usb_mounted()
};
if mounted {
break;
}
// 等待 100ms
unsafe {
rust_vTaskDelay(100 * PD_MS_TO_TICKS);
}
}
if mounted {
// 发送 A 键按下事件
let keycode = [HID_KEY_A, 0, 0, 0, 0, 0];
unsafe {
rust_send_keyboard_report(REPORT_ID_KEYBOARD, 0, keycode.as_ptr());
}
// 等待 50ms
unsafe {
rust_vTaskDelay(50 * PD_MS_TO_TICKS);
}
// 发送 A 键释放事件
let keycode = [0, 0, 0, 0, 0, 0];
unsafe {
rust_send_keyboard_report(REPORT_ID_KEYBOARD, 0, keycode.as_ptr());
}
}
}