diff options
author | Pete Johanson <peter@peterjohanson.com> | 2021-03-15 00:40:09 -0400 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2021-10-04 23:01:39 -0400 |
commit | 91ba034896c3b1668b88286e18d8f38314ec39c3 (patch) | |
tree | 1a4999351ee331d9d8f205b539c7c5604d9ef39f /app/src | |
parent | 063b496c26316026e95cf7cdb0ba6c343b6c6efb (diff) |
feat(hid): Configurable NKRO HID report support.
* Add Kconfig settings for NKRO or HKRO (boot compatible), HID
report types for keyboard page.
* Updated report storage and set/unset for each config.
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/hid.c | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/app/src/hid.c b/app/src/hid.c index 7ab080e..756ed90 100644 --- a/app/src/hid.c +++ b/app/src/hid.c @@ -69,8 +69,30 @@ int zmk_hid_unregister_mods(zmk_mod_flags_t modifiers) { return 0; } +#if IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_NKRO) + +#define TOGGLE_KEYBOARD(code, val) WRITE_BIT(keyboard_report.body.keys[code / 8], code % 8, val) + +static inline int select_keyboard_usage(zmk_key_t usage) { + if (usage > ZMK_HID_KEYBOARD_NKRO_MAX_USAGE) { + return -EINVAL; + } + TOGGLE_KEYBOARD(usage, 1); + return 0; +} + +static inline int deselect_keyboard_usage(zmk_key_t usage) { + if (usage > ZMK_HID_KEYBOARD_NKRO_MAX_USAGE) { + return -EINVAL; + } + TOGGLE_KEYBOARD(usage, 0); + return 0; +} + +#elif IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_HKRO) + #define TOGGLE_KEYBOARD(match, val) \ - for (int idx = 0; idx < ZMK_HID_KEYBOARD_NKRO_SIZE; idx++) { \ + for (int idx = 0; idx < CONFIG_ZMK_HID_KEYBOARD_REPORT_SIZE; idx++) { \ if (keyboard_report.body.keys[idx] != match) { \ continue; \ } \ @@ -80,8 +102,22 @@ int zmk_hid_unregister_mods(zmk_mod_flags_t modifiers) { } \ } +static inline int select_keyboard_usage(zmk_key_t usage) { + TOGGLE_KEYBOARD(0U, usage); + return 0; +} + +static inline int deselect_keyboard_usage(zmk_key_t usage) { + TOGGLE_KEYBOARD(usage, 0U); + return 0; +} + +#else +#error "A proper HID report type must be selected" +#endif + #define TOGGLE_CONSUMER(match, val) \ - for (int idx = 0; idx < ZMK_HID_CONSUMER_NKRO_SIZE; idx++) { \ + for (int idx = 0; idx < CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE; idx++) { \ if (consumer_report.body.keys[idx] != match) { \ continue; \ } \ @@ -105,7 +141,7 @@ int zmk_hid_keyboard_press(zmk_key_t code) { if (code >= HID_USAGE_KEY_KEYBOARD_LEFTCONTROL && code <= HID_USAGE_KEY_KEYBOARD_RIGHT_GUI) { return zmk_hid_register_mod(code - HID_USAGE_KEY_KEYBOARD_LEFTCONTROL); } - TOGGLE_KEYBOARD(0U, code); + select_keyboard_usage(code); return 0; }; @@ -113,7 +149,7 @@ int zmk_hid_keyboard_release(zmk_key_t code) { if (code >= HID_USAGE_KEY_KEYBOARD_LEFTCONTROL && code <= HID_USAGE_KEY_KEYBOARD_RIGHT_GUI) { return zmk_hid_unregister_mod(code - HID_USAGE_KEY_KEYBOARD_LEFTCONTROL); } - TOGGLE_KEYBOARD(code, 0U); + deselect_keyboard_usage(code); return 0; }; |