From 54ac7658e78dee4eb322774bcb88d64740986705 Mon Sep 17 00:00:00 2001 From: Alexander Krikun Date: Wed, 28 Apr 2021 15:07:54 +0300 Subject: [PATCH] Fine-tuning report, 16 buttons --- app/include/zmk/hid.h | 20 +++++++++----------- app/include/zmk/mouse.h | 4 ++-- app/src/hid.c | 23 +++++++++++++---------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/app/include/zmk/hid.h b/app/include/zmk/hid.h index 44c5edd7..8bde4c15 100644 --- a/app/include/zmk/hid.h +++ b/app/include/zmk/hid.h @@ -190,26 +190,24 @@ static const uint8_t zmk_hid_report_desc[] = { 0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */ 0x09, 0x02, /* Usage (Mouse) */ 0xA1, 0x01, /* Collection (Application) */ + 0x85, 0x04, /* Report ID (4) */ 0x09, 0x01, /* Usage (Pointer) */ 0xA1, 0x00, /* Collection (Physical) */ 0x05, 0x09, /* Usage Page (Button) */ 0x19, 0x01, /* Usage Minimum (0x01) */ - 0x29, 0x03, /* Usage Maximum (0x03) */ + 0x29, 0x10, /* Usage Maximum (0x10) */ 0x15, 0x00, /* Logical Minimum (0) */ 0x25, 0x01, /* Logical Maximum (1) */ - 0x95, 0x03, /* Report Count (3) */ + 0x95, 0x10, /* Report Count (16) */ 0x75, 0x01, /* Report Size (1) */ 0x81, 0x02, /* Input (Data,Var,Abs,No Wrap,Linear,...) */ - 0x95, 0x01, /* Report Count (1) */ - 0x75, 0x05, /* Report Size (5) */ - 0x81, 0x03, /* Input (Const,Var,Abs,No Wrap,Linear,...) */ 0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */ + 0x16, 0x01, 0x80, /* Logical Minimum (-32767) */ + 0x26, 0xFF, 0x7F, /* Logical Maximum (32767) */ + 0x75, 0x10, /* Report Size (8) */ + 0x95, 0x02, /* Report Count (2) */ 0x09, 0x30, /* Usage (X) */ 0x09, 0x31, /* Usage (Y) */ - 0x15, 0x81, /* Logical Minimum (129) */ - 0x25, 0x7F, /* Logical Maximum (127) */ - 0x75, 0x08, /* Report Size (8) */ - 0x95, 0x02, /* Report Count (2) */ 0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */ 0xC0, /* End Collection */ 0xC0, /* End Collection */ @@ -252,8 +250,8 @@ struct zmk_hid_consumer_report { struct zmk_hid_mouse_report_body { zmk_mouse_button_flags_t buttons; - int8_t x; - int8_t y; + int16_t x; + int16_t y; } __packed; struct zmk_hid_mouse_report { diff --git a/app/include/zmk/mouse.h b/app/include/zmk/mouse.h index 0d4bcb61..32d3d03e 100644 --- a/app/include/zmk/mouse.h +++ b/app/include/zmk/mouse.h @@ -9,5 +9,5 @@ #include #include -typedef uint8_t zmk_mouse_button_flags_t; -typedef uint8_t zmk_mouse_button_t; \ No newline at end of file +typedef uint16_t zmk_mouse_button_flags_t; +typedef uint16_t zmk_mouse_button_t; \ No newline at end of file diff --git a/app/src/hid.c b/app/src/hid.c index bd50e0d5..34399812 100644 --- a/app/src/hid.c +++ b/app/src/hid.c @@ -15,7 +15,7 @@ static struct zmk_hid_keyboard_report keyboard_report = { static struct zmk_hid_consumer_report consumer_report = {.report_id = 2, .body = {.keys = {0}}}; -static struct zmk_hid_mouse_report mouse_report = {.report_id = 3, .body = { +static struct zmk_hid_mouse_report mouse_report = {.report_id = 4, .body = { .buttons = 0, .x = 0, .y = 0}}; // Keep track of how often a modifier was pressed. @@ -184,7 +184,7 @@ void zmk_hid_consumer_clear() { memset(&consumer_report.body, 0, sizeof(consumer // Keep track of how often a button was pressed. // Only release the button if the count is 0. -static int explicit_button_counts[3] = {0, 0, 0}; +static int explicit_button_counts[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; static zmk_mod_flags_t explicit_buttons = 0; #define SET_MOUSE_BUTTONS(butts) \ @@ -194,21 +194,21 @@ static zmk_mod_flags_t explicit_buttons = 0; } int zmk_hid_mouse_button_press(zmk_mouse_button_t button) { - explicit_button_counts[button-5]++; - LOG_DBG("Button %d count %d", button, explicit_button_counts[button-5]); + explicit_button_counts[button]++; + LOG_DBG("Button %d count %d", button, explicit_button_counts[button]); WRITE_BIT(explicit_buttons, button, true); SET_MOUSE_BUTTONS(explicit_buttons); return 0; } int zmk_hid_mouse_button_release(zmk_mouse_button_t button) { - if (explicit_button_counts[button-5] <= 0) { + if (explicit_button_counts[button] <= 0) { LOG_ERR("Tried to release button %d too often", button); return -EINVAL; } explicit_button_counts[button]--; - LOG_DBG("Button %d count: %d", button, explicit_button_counts[button-5]); - if (explicit_button_counts[button-5] == 0) { + LOG_DBG("Button %d count: %d", button, explicit_button_counts[button]); + if (explicit_button_counts[button] == 0) { LOG_DBG("Button %d released", button); WRITE_BIT(explicit_buttons, button, false); } @@ -217,7 +217,7 @@ int zmk_hid_mouse_button_release(zmk_mouse_button_t button) { } int zmk_hid_mouse_buttons_press(zmk_mouse_button_flags_t buttons) { - for (zmk_mod_t i = 5; i < 8; i++) { + for (zmk_mod_t i = 0; i < 16; i++) { if (buttons & (1 << i)) { zmk_hid_mouse_button_press(i); } @@ -226,7 +226,7 @@ int zmk_hid_mouse_buttons_press(zmk_mouse_button_flags_t buttons) { } int zmk_hid_mouse_buttons_release(zmk_mouse_button_flags_t buttons) { - for (zmk_mod_t i = 5; i < 8; i++) { + for (zmk_mod_t i = 0; i < 16; i++) { if (buttons & (1 << i)) { zmk_hid_mouse_button_release(i); } @@ -234,7 +234,10 @@ int zmk_hid_mouse_buttons_release(zmk_mouse_button_flags_t buttons) { return 0; } -void zmk_hid_mouse_clear() { memset(&mouse_report.body, 0, sizeof(mouse_report.body)); } +void zmk_hid_mouse_clear() { + memset(&mouse_report.body, 0, sizeof(mouse_report.body)); + mouse_report.body.buffer = 1; +} struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report() { return &keyboard_report;