From b44ef2dc6fed44828da99cddb1152b39ebda50e3 Mon Sep 17 00:00:00 2001 From: Hrvoje Cavrak Date: Sun, 31 Mar 2024 23:42:13 +0200 Subject: [PATCH] Updates and fixes. - Implement fix for keyboards not switching to boot mode properly, until full report parsing gets done. This is expected to improve support for certain models that were reported problematic. - Implement fix for mouse acceleration omitting absolute mode - Provide pass_to_os = true to not capture shift+backspace from the OS, it's annoying when you hold shift and mistype something, then want to use backspace but couldn't. --- src/keyboard.c | 7 +++++++ src/mouse.c | 2 +- src/usb.c | 8 +++++++- src/user_config.h | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index 1a5469f..a234fa0 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -55,6 +55,7 @@ hotkey_combo_t hotkeys[] = { {.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT, .keys = {HID_KEY_BACKSPACE}, .key_count = 1, + .pass_to_os = true, .action_handler = &output_config_hotkey_handler}, /* Erase stored config */ @@ -191,6 +192,12 @@ void process_keyboard_report(uint8_t *raw_report, int length, device_t *state) { if (length < KBD_REPORT_LENGTH) return; + /* If the report is longer by 1 byte, we can assume the first byte is the report ID + and that the keyboard didn't switch to boot mode properly. Use this workaround + until full HID report parsing is implemented */ + if (length == KBD_REPORT_LENGTH + 1) + keyboard_report = (hid_keyboard_report_t *)(raw_report + 1); + /* Check if any hotkey was pressed */ hotkey = check_all_hotkeys(keyboard_report, state); diff --git a/src/mouse.c b/src/mouse.c index 2801b5f..f122e98 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -52,7 +52,7 @@ int32_t accelerate(int32_t offset) { return offset; for (int i = 0; i < 7; i++) { - if (offset < acceleration[i].value) { + if (abs(offset) < acceleration[i].value) { return offset * acceleration[i].factor; } } diff --git a/src/usb.c b/src/usb.c index 3fb3f27..834dc9e 100644 --- a/src/usb.c +++ b/src/usb.c @@ -103,6 +103,9 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const *desc_re switch (itf_protocol) { case HID_ITF_PROTOCOL_KEYBOARD: + if (ENFORCE_PORTS && BOARD_ROLE == PICO_B) + return; + /* Keeping this is required for setting leds from device set_report callback */ global_state.kbd_dev_addr = dev_addr; global_state.kbd_instance = instance; @@ -110,6 +113,9 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const *desc_re break; case HID_ITF_PROTOCOL_MOUSE: + if (ENFORCE_PORTS && BOARD_ROLE == PICO_A) + return; + /* Switch to using protocol report instead of boot report, it's more complicated but at least we get all the information we need (looking at you, mouse wheel) */ if (tuh_hid_get_protocol(dev_addr, instance) == HID_PROTOCOL_BOOT) { @@ -128,7 +134,7 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const *desc_re /* Also signal the other board to flash LED, to enable easy verification if serial works */ send_value(ENABLE, FLASH_LED_MSG); - /* Kick off the report querying */ + /* Kick off the report querying */ tuh_hid_receive_report(dev_addr, instance); } diff --git a/src/user_config.h b/src/user_config.h index bc3551a..aa45b76 100644 --- a/src/user_config.h +++ b/src/user_config.h @@ -158,3 +158,17 @@ #define OUTPUT_A_OS LINUX #define OUTPUT_B_OS LINUX + +/**================================================== * + * ================= Enforce Ports ================= * + * ================================================== + * + * If enabled, fixes some device incompatibilities by + * enforcing keyboard has to be in port A and mouse in port B. + * + * ENFORCE_PORTS: [0, 1] - 1 means keyboard has to plug in A and mouse in B + * 0 means no such layout is enforced + * + * */ + +#define ENFORCE_PORTS 0 \ No newline at end of file