From 342d83891301b1be53233a12c7723bb99cbe5ff6 Mon Sep 17 00:00:00 2001 From: Tobias Adolph <43353209+adolto@users.noreply.github.com> Date: Sun, 20 Jul 2025 17:13:18 +0200 Subject: [PATCH] fix(ble,hid): Fix smooth scrolling over BLE (#2998) - Use correct MIN16 value in hid report. -32768 in 2's compliment is 8000(hex) - Initialize resolution multiplier array - Properly implement `read_hids_mouse_feature_report` Fixes: #2957 Co-authored-by: Tobias Adolph <43353209+adolto@users.noreply.github.comgit> --- app/include/zmk/hid.h | 6 +++--- app/src/hog.c | 25 ++++++++++++++++++++--- app/src/pointing/resolution_multipliers.c | 8 +++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/include/zmk/hid.h b/app/include/zmk/hid.h index 8a3f40b1b..962180e70 100644 --- a/app/include/zmk/hid.h +++ b/app/include/zmk/hid.h @@ -208,7 +208,7 @@ static const uint8_t zmk_hid_report_desc[] = { HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP), HID_USAGE(HID_USAGE_GD_X), HID_USAGE(HID_USAGE_GD_Y), - HID_LOGICAL_MIN16(0xFF, -0x7F), + HID_LOGICAL_MIN16(0x00, 0x80), HID_LOGICAL_MAX16(0xFF, 0x7F), HID_REPORT_SIZE(0x10), HID_REPORT_COUNT(0x02), @@ -226,7 +226,7 @@ static const uint8_t zmk_hid_report_desc[] = { HID_FEATURE(ZMK_HID_MAIN_VAL_DATA | ZMK_HID_MAIN_VAL_VAR | ZMK_HID_MAIN_VAL_ABS), #endif // IS_ENABLED(CONFIG_ZMK_POINTING_SMOOTH_SCROLLING) HID_USAGE(HID_USAGE_GD_WHEEL), - HID_LOGICAL_MIN16(0xFF, -0x7F), + HID_LOGICAL_MIN16(0x00, 0x80), HID_LOGICAL_MAX16(0xFF, 0x7F), HID_PHYSICAL_MIN8(0x00), HID_PHYSICAL_MAX8(0x00), @@ -242,7 +242,7 @@ static const uint8_t zmk_hid_report_desc[] = { #endif // IS_ENABLED(CONFIG_ZMK_POINTING_SMOOTH_SCROLLING) HID_USAGE_PAGE(HID_USAGE_CONSUMER), HID_USAGE16_SINGLE(HID_USAGE_CONSUMER_AC_PAN), - HID_LOGICAL_MIN16(0xFF, -0x7F), + HID_LOGICAL_MIN16(0x00, 0x80), HID_LOGICAL_MAX16(0xFF, 0x7F), HID_PHYSICAL_MIN8(0x00), HID_PHYSICAL_MAX8(0x00), diff --git a/app/src/hog.c b/app/src/hog.c index d56eacf76..c7d9b861d 100644 --- a/app/src/hog.c +++ b/app/src/hog.c @@ -168,9 +168,28 @@ static ssize_t read_hids_mouse_input_report(struct bt_conn *conn, const struct b static ssize_t read_hids_mouse_feature_report(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { - struct zmk_hid_mouse_report_body *report_body = &zmk_hid_get_mouse_report()->body; - return bt_gatt_attr_read(conn, attr, buf, len, offset, report_body, - sizeof(struct zmk_hid_mouse_report_body)); + + int profile = zmk_ble_profile_index(bt_conn_get_dst(conn)); + if (profile < 0) { + LOG_DBG(" BT_ATT_ERR_UNLIKELY"); + return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); + } + + struct zmk_endpoint_instance endpoint = { + .transport = ZMK_TRANSPORT_BLE, + .ble = {.profile_index = profile}, + }; + + struct zmk_pointing_resolution_multipliers mult = + zmk_pointing_resolution_multipliers_get_profile(endpoint); + + struct zmk_hid_mouse_resolution_feature_report_body report = { + .wheel_res = mult.wheel, + .hwheel_res = mult.hor_wheel, + }; + + return bt_gatt_attr_read(conn, attr, buf, len, offset, &report, + sizeof(struct zmk_hid_mouse_resolution_feature_report_body)); } static ssize_t write_hids_mouse_feature_report(struct bt_conn *conn, diff --git a/app/src/pointing/resolution_multipliers.c b/app/src/pointing/resolution_multipliers.c index 951d104af..3ebda9d57 100644 --- a/app/src/pointing/resolution_multipliers.c +++ b/app/src/pointing/resolution_multipliers.c @@ -13,7 +13,13 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -static struct zmk_pointing_resolution_multipliers multipliers[ZMK_ENDPOINT_COUNT]; +static struct zmk_pointing_resolution_multipliers multipliers[ZMK_ENDPOINT_COUNT] = { + [0 ... ZMK_ENDPOINT_COUNT - 1] = + { + .wheel = 15, + .hor_wheel = 15, + }, +}; struct zmk_pointing_resolution_multipliers zmk_pointing_resolution_multipliers_get_current_profile(void) {