|
|
@ -4,6 +4,7 @@ |
|
|
|
* SPDX-License-Identifier: MIT |
|
|
|
* SPDX-License-Identifier: MIT |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "zmk/keys.h" |
|
|
|
#include <logging/log.h> |
|
|
|
#include <logging/log.h> |
|
|
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
|
|
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
|
|
|
|
|
|
|
|
|
|
@ -55,6 +56,11 @@ int zmk_hid_unregister_mod(zmk_mod_t modifier) { |
|
|
|
return current == GET_MODIFIERS ? 0 : 1; |
|
|
|
return current == GET_MODIFIERS ? 0 : 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool zmk_hid_mod_is_pressed(zmk_mod_t modifier) { |
|
|
|
|
|
|
|
zmk_mod_flags_t mod_flag = 1 << modifier; |
|
|
|
|
|
|
|
return (zmk_hid_get_explicit_mods() & mod_flag) == mod_flag; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int zmk_hid_register_mods(zmk_mod_flags_t modifiers) { |
|
|
|
int zmk_hid_register_mods(zmk_mod_flags_t modifiers) { |
|
|
|
int ret = 0; |
|
|
|
int ret = 0; |
|
|
|
for (zmk_mod_t i = 0; i < 8; i++) { |
|
|
|
for (zmk_mod_t i = 0; i < 8; i++) { |
|
|
@ -96,6 +102,13 @@ static inline int deselect_keyboard_usage(zmk_key_t usage) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline bool check_keyboard_usage(zmk_key_t usage) { |
|
|
|
|
|
|
|
if (usage > ZMK_HID_KEYBOARD_NKRO_MAX_USAGE) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return keyboard_report.body.keys[usage / 8] & (1 << (usage % 8)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#elif IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_HKRO) |
|
|
|
#elif IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_HKRO) |
|
|
|
|
|
|
|
|
|
|
|
#define TOGGLE_KEYBOARD(match, val) \ |
|
|
|
#define TOGGLE_KEYBOARD(match, val) \ |
|
|
@ -119,6 +132,15 @@ static inline int deselect_keyboard_usage(zmk_key_t usage) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline int check_keyboard_usage(zmk_key_t usage) { |
|
|
|
|
|
|
|
for (int idx = 0; idx < CONFIG_ZMK_HID_KEYBOARD_REPORT_SIZE; idx++) { |
|
|
|
|
|
|
|
if (keyboard_report.body.keys[idx] == usage) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#else |
|
|
|
#else |
|
|
|
#error "A proper HID report type must be selected" |
|
|
|
#error "A proper HID report type must be selected" |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -164,6 +186,13 @@ int zmk_hid_keyboard_release(zmk_key_t code) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool zmk_hid_keyboard_is_pressed(zmk_key_t code) { |
|
|
|
|
|
|
|
if (code >= HID_USAGE_KEY_KEYBOARD_LEFTCONTROL && code <= HID_USAGE_KEY_KEYBOARD_RIGHT_GUI) { |
|
|
|
|
|
|
|
return zmk_hid_mod_is_pressed(code - HID_USAGE_KEY_KEYBOARD_LEFTCONTROL); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return check_keyboard_usage(code); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void zmk_hid_keyboard_clear() { memset(&keyboard_report.body, 0, sizeof(keyboard_report.body)); } |
|
|
|
void zmk_hid_keyboard_clear() { memset(&keyboard_report.body, 0, sizeof(keyboard_report.body)); } |
|
|
|
|
|
|
|
|
|
|
|
int zmk_hid_consumer_press(zmk_key_t code) { |
|
|
|
int zmk_hid_consumer_press(zmk_key_t code) { |
|
|
@ -176,6 +205,17 @@ int zmk_hid_consumer_release(zmk_key_t code) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void zmk_hid_consumer_clear() { memset(&consumer_report.body, 0, sizeof(consumer_report.body)); } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool zmk_hid_consumer_is_pressed(zmk_key_t key) { |
|
|
|
|
|
|
|
for (int idx = 0; idx < CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE; idx++) { |
|
|
|
|
|
|
|
if (consumer_report.body.keys[idx] == key) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int zmk_hid_press(uint32_t usage) { |
|
|
|
int zmk_hid_press(uint32_t usage) { |
|
|
|
switch (ZMK_HID_USAGE_PAGE(usage)) { |
|
|
|
switch (ZMK_HID_USAGE_PAGE(usage)) { |
|
|
|
case HID_USAGE_KEY: |
|
|
|
case HID_USAGE_KEY: |
|
|
@ -196,7 +236,15 @@ int zmk_hid_release(uint32_t usage) { |
|
|
|
return -EINVAL; |
|
|
|
return -EINVAL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void zmk_hid_consumer_clear() { memset(&consumer_report.body, 0, sizeof(consumer_report.body)); } |
|
|
|
bool zmk_hid_is_pressed(uint32_t usage) { |
|
|
|
|
|
|
|
switch (ZMK_HID_USAGE_PAGE(usage)) { |
|
|
|
|
|
|
|
case HID_USAGE_KEY: |
|
|
|
|
|
|
|
return zmk_hid_keyboard_is_pressed(ZMK_HID_USAGE_ID(usage)); |
|
|
|
|
|
|
|
case HID_USAGE_CONSUMER: |
|
|
|
|
|
|
|
return zmk_hid_consumer_is_pressed(ZMK_HID_USAGE_ID(usage)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|