From f4596fc784d11aa2d03ff0b7fa0a921600fc2db2 Mon Sep 17 00:00:00 2001 From: innovaker <66737976+innovaker@users.noreply.github.com> Date: Tue, 27 Oct 2020 22:35:44 +0000 Subject: refactor(hid): Refactor keypad report to use a configurable integer array Replace NKRO bit array with configurable integer (DV) array. --- app/src/hid.c | 45 +++++++++++---------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) (limited to 'app/src') diff --git a/app/src/hid.c b/app/src/hid.c index f80906c..5e46832 100644 --- a/app/src/hid.c +++ b/app/src/hid.c @@ -9,8 +9,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include -static struct zmk_hid_keypad_report kp_report = { - .report_id = 1, .body = {.modifiers = 0, .keys = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}}; +static struct zmk_hid_keypad_report kp_report = {.report_id = 1, + .body = {.modifiers = 0, .keys = {0}}}; static struct zmk_hid_consumer_report consumer_report = {.report_id = 2, .body = {.keys = {0, 0, 0, 0, 0, 0}}}; @@ -35,23 +35,16 @@ int zmk_hid_unregister_mods(zmk_mod_flags modifiers) { return 0; } -#define KEY_OFFSET 0x02 #define MAX_KEYS 6 -/* -#define TOGGLE_BOOT_KEY(match, val) \ - for (int idx = 0; idx < MAX_KEYS; idx++) \ - { \ - if (kp_report.boot.keys[idx + KEY_OFFSET] != match) \ - { \ - continue; \ - } \ - kp_report.boot.keys[idx + KEY_OFFSET] = val; \ - break; \ +#define TOGGLE_KEYPAD(match, val) \ + for (int idx = 0; idx < ZMK_HID_KEYPAD_NKRO_SIZE; idx++) { \ + if (kp_report.body.keys[idx] != match) { \ + continue; \ + } \ + kp_report.body.keys[idx] = val; \ + break; \ } -*/ - -#define TOGGLE_KEY(code, val) WRITE_BIT(kp_report.body.keys[code / 8], code % 8, val) #define TOGGLE_CONSUMER(match, val) \ for (int idx = 0; idx < MAX_KEYS; idx++) { \ @@ -66,15 +59,7 @@ int zmk_hid_keypad_press(zmk_key code) { if (code >= LCTL && code <= RGUI) { return zmk_hid_register_mod(code - LCTL); } - - if (code > ZMK_HID_MAX_KEYCODE) { - return -EINVAL; - } - - // TOGGLE_BOOT_KEY(0U, code); - - TOGGLE_KEY(code, true); - + TOGGLE_KEYPAD(0U, code); return 0; }; @@ -82,15 +67,7 @@ int zmk_hid_keypad_release(zmk_key code) { if (code >= LCTL && code <= RGUI) { return zmk_hid_unregister_mod(code - LCTL); } - - if (code > ZMK_HID_MAX_KEYCODE) { - return -EINVAL; - } - - // TOGGLE_BOOT_KEY(0U, code); - - TOGGLE_KEY(code, false); - + TOGGLE_KEYPAD(code, 0U); return 0; }; -- cgit v1.2.3 From 8ce7d8de0133242d5896333add10be9ba2ae9363 Mon Sep 17 00:00:00 2001 From: innovaker <66737976+innovaker@users.noreply.github.com> Date: Tue, 27 Oct 2020 18:42:41 +0000 Subject: refactor(hid): Refactor consumer report to a configurable size --- app/src/hid.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'app/src') diff --git a/app/src/hid.c b/app/src/hid.c index 5e46832..28efee1 100644 --- a/app/src/hid.c +++ b/app/src/hid.c @@ -12,8 +12,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); static struct zmk_hid_keypad_report kp_report = {.report_id = 1, .body = {.modifiers = 0, .keys = {0}}}; -static struct zmk_hid_consumer_report consumer_report = {.report_id = 2, - .body = {.keys = {0, 0, 0, 0, 0, 0}}}; +static struct zmk_hid_consumer_report consumer_report = {.report_id = 2, .body = {.keys = {0}}}; #define _TOGGLE_MOD(mod, state) \ if (modifier > MOD_RGUI) { \ @@ -35,8 +34,6 @@ int zmk_hid_unregister_mods(zmk_mod_flags modifiers) { return 0; } -#define MAX_KEYS 6 - #define TOGGLE_KEYPAD(match, val) \ for (int idx = 0; idx < ZMK_HID_KEYPAD_NKRO_SIZE; idx++) { \ if (kp_report.body.keys[idx] != match) { \ @@ -47,7 +44,7 @@ int zmk_hid_unregister_mods(zmk_mod_flags modifiers) { } #define TOGGLE_CONSUMER(match, val) \ - for (int idx = 0; idx < MAX_KEYS; idx++) { \ + for (int idx = 0; idx < ZMK_HID_CONSUMER_NKRO_SIZE; idx++) { \ if (consumer_report.body.keys[idx] != match) { \ continue; \ } \ -- cgit v1.2.3 From c402e953f6e9655898cd45af9b120d2a45dd45e0 Mon Sep 17 00:00:00 2001 From: innovaker <66737976+innovaker@users.noreply.github.com> Date: Tue, 27 Oct 2020 17:42:00 +0000 Subject: feat(hid): Make keypad report boot friendly Add missing byte to make keypad report boot friendly. --- app/src/hid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src') diff --git a/app/src/hid.c b/app/src/hid.c index 28efee1..207b1ad 100644 --- a/app/src/hid.c +++ b/app/src/hid.c @@ -9,8 +9,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include -static struct zmk_hid_keypad_report kp_report = {.report_id = 1, - .body = {.modifiers = 0, .keys = {0}}}; +static struct zmk_hid_keypad_report kp_report = { + .report_id = 1, .body = {.modifiers = 0, ._reserved = 0, .keys = {0}}}; static struct zmk_hid_consumer_report consumer_report = {.report_id = 2, .body = {.keys = {0}}}; -- cgit v1.2.3