Fine-tuning report, 16 buttons

This commit is contained in:
Alexander Krikun 2021-04-28 15:07:54 +03:00
parent d8d8b96992
commit 9b09974734
3 changed files with 24 additions and 23 deletions

View file

@ -188,26 +188,24 @@ static const uint8_t zmk_hid_report_desc[] = {
0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */ 0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
0x09, 0x02, /* Usage (Mouse) */ 0x09, 0x02, /* Usage (Mouse) */
0xA1, 0x01, /* Collection (Application) */ 0xA1, 0x01, /* Collection (Application) */
0x85, 0x04, /* Report ID (4) */
0x09, 0x01, /* Usage (Pointer) */ 0x09, 0x01, /* Usage (Pointer) */
0xA1, 0x00, /* Collection (Physical) */ 0xA1, 0x00, /* Collection (Physical) */
0x05, 0x09, /* Usage Page (Button) */ 0x05, 0x09, /* Usage Page (Button) */
0x19, 0x01, /* Usage Minimum (0x01) */ 0x19, 0x01, /* Usage Minimum (0x01) */
0x29, 0x03, /* Usage Maximum (0x03) */ 0x29, 0x10, /* Usage Maximum (0x10) */
0x15, 0x00, /* Logical Minimum (0) */ 0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */ 0x25, 0x01, /* Logical Maximum (1) */
0x95, 0x03, /* Report Count (3) */ 0x95, 0x10, /* Report Count (16) */
0x75, 0x01, /* Report Size (1) */ 0x75, 0x01, /* Report Size (1) */
0x81, 0x02, /* Input (Data,Var,Abs,No Wrap,Linear,...) */ 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) */ 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, 0x30, /* Usage (X) */
0x09, 0x31, /* Usage (Y) */ 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,...) */ 0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */
0xC0, /* End Collection */ 0xC0, /* End Collection */
0xC0, /* End Collection */ 0xC0, /* End Collection */
@ -250,8 +248,8 @@ struct zmk_hid_consumer_report {
struct zmk_hid_mouse_report_body { struct zmk_hid_mouse_report_body {
zmk_mouse_button_flags_t buttons; zmk_mouse_button_flags_t buttons;
int8_t x; int16_t x;
int8_t y; int16_t y;
} __packed; } __packed;
struct zmk_hid_mouse_report { struct zmk_hid_mouse_report {

View file

@ -9,5 +9,5 @@
#include <zephyr.h> #include <zephyr.h>
#include <dt-bindings/zmk/mouse.h> #include <dt-bindings/zmk/mouse.h>
typedef uint8_t zmk_mouse_button_flags_t; typedef uint16_t zmk_mouse_button_flags_t;
typedef uint8_t zmk_mouse_button_t; typedef uint16_t zmk_mouse_button_t;

View file

@ -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_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}}; .buttons = 0, .x = 0, .y = 0}};
// Keep track of how often a modifier was pressed. // Keep track of how often a modifier was pressed.
@ -175,7 +175,7 @@ void zmk_hid_consumer_clear() { memset(&consumer_report.body, 0, sizeof(consumer
// Keep track of how often a button was pressed. // Keep track of how often a button was pressed.
// Only release the button if the count is 0. // 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; static zmk_mod_flags_t explicit_buttons = 0;
#define SET_MOUSE_BUTTONS(butts) \ #define SET_MOUSE_BUTTONS(butts) \
@ -185,21 +185,21 @@ static zmk_mod_flags_t explicit_buttons = 0;
} }
int zmk_hid_mouse_button_press(zmk_mouse_button_t button) { int zmk_hid_mouse_button_press(zmk_mouse_button_t button) {
explicit_button_counts[button-5]++; explicit_button_counts[button]++;
LOG_DBG("Button %d count %d", button, explicit_button_counts[button-5]); LOG_DBG("Button %d count %d", button, explicit_button_counts[button]);
WRITE_BIT(explicit_buttons, button, true); WRITE_BIT(explicit_buttons, button, true);
SET_MOUSE_BUTTONS(explicit_buttons); SET_MOUSE_BUTTONS(explicit_buttons);
return 0; return 0;
} }
int zmk_hid_mouse_button_release(zmk_mouse_button_t button) { 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); LOG_ERR("Tried to release button %d too often", button);
return -EINVAL; return -EINVAL;
} }
explicit_button_counts[button]--; explicit_button_counts[button]--;
LOG_DBG("Button %d count: %d", button, explicit_button_counts[button-5]); LOG_DBG("Button %d count: %d", button, explicit_button_counts[button]);
if (explicit_button_counts[button-5] == 0) { if (explicit_button_counts[button] == 0) {
LOG_DBG("Button %d released", button); LOG_DBG("Button %d released", button);
WRITE_BIT(explicit_buttons, button, false); WRITE_BIT(explicit_buttons, button, false);
} }
@ -208,7 +208,7 @@ int zmk_hid_mouse_button_release(zmk_mouse_button_t button) {
} }
int zmk_hid_mouse_buttons_press(zmk_mouse_button_flags_t buttons) { 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)) { if (buttons & (1 << i)) {
zmk_hid_mouse_button_press(i); zmk_hid_mouse_button_press(i);
} }
@ -217,7 +217,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) { 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)) { if (buttons & (1 << i)) {
zmk_hid_mouse_button_release(i); zmk_hid_mouse_button_release(i);
} }
@ -225,7 +225,10 @@ int zmk_hid_mouse_buttons_release(zmk_mouse_button_flags_t buttons) {
return 0; 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() { struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report() {
return &keyboard_report; return &keyboard_report;