cmd: poll rate switch

This commit is contained in:
awalol
2026-05-05 13:00:28 +08:00
parent a89618f463
commit 0d32db4d9f
3 changed files with 30 additions and 2 deletions
+13
View File
@@ -38,6 +38,14 @@ volatile bool report_dirty = false;
void interrupt_loop() {
if (!tud_hid_ready()) return;
// TODO: Refactor for better code reuse
if (get_config().polling_rate_mode != 2) {
if (!tud_hid_report(0x01, interrupt_in_data, 63)) {
printf("[USBHID] tud_hid_report error\n");
}
return;
}
bool should_send = false;
// Local buffer to hold the report data while we prepare it to send.
uint8_t safe_report[63];
@@ -72,6 +80,11 @@ void on_bt_data(CHANNEL_TYPE channel, uint8_t *data, uint16_t len) {
set_headset(data[56] & 1);
}
if (get_config().polling_rate_mode != 2) {
memcpy(interrupt_in_data, data + 3, 63);
return;
}
// We add the critical section here to avoid any race conditions when writing to the interrupt_in_data buffer,
// which is shared between the main loop and this callback.
// The critical section ensures that only one thread can access the buffer at a time,