|
|
@ -9,8 +9,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
|
|
|
|
|
|
|
|
|
|
|
#include <zmk/hid.h> |
|
|
|
#include <zmk/hid.h> |
|
|
|
|
|
|
|
|
|
|
|
static struct zmk_hid_keypad_report kp_report = { |
|
|
|
static struct zmk_hid_keypad_report kp_report = {.report_id = 1, |
|
|
|
.report_id = 1, .body = {.modifiers = 0, .keys = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}}; |
|
|
|
.body = {.modifiers = 0, .keys = {0}}}; |
|
|
|
|
|
|
|
|
|
|
|
static struct zmk_hid_consumer_report consumer_report = {.report_id = 2, |
|
|
|
static struct zmk_hid_consumer_report consumer_report = {.report_id = 2, |
|
|
|
.body = {.keys = {0, 0, 0, 0, 0, 0}}}; |
|
|
|
.body = {.keys = {0, 0, 0, 0, 0, 0}}}; |
|
|
@ -35,23 +35,16 @@ int zmk_hid_unregister_mods(zmk_mod_flags modifiers) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define KEY_OFFSET 0x02 |
|
|
|
|
|
|
|
#define MAX_KEYS 6 |
|
|
|
#define MAX_KEYS 6 |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
#define TOGGLE_KEYPAD(match, val) \ |
|
|
|
#define TOGGLE_BOOT_KEY(match, val) \ |
|
|
|
for (int idx = 0; idx < ZMK_HID_KEYPAD_NKRO_SIZE; idx++) { \
|
|
|
|
for (int idx = 0; idx < MAX_KEYS; idx++) \
|
|
|
|
if (kp_report.body.keys[idx] != match) { \
|
|
|
|
{ \
|
|
|
|
|
|
|
|
if (kp_report.boot.keys[idx + KEY_OFFSET] != match) \
|
|
|
|
|
|
|
|
{ \
|
|
|
|
|
|
|
|
continue; \
|
|
|
|
continue; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
kp_report.boot.keys[idx + KEY_OFFSET] = val; \
|
|
|
|
kp_report.body.keys[idx] = val; \
|
|
|
|
break; \
|
|
|
|
break; \
|
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define TOGGLE_KEY(code, val) WRITE_BIT(kp_report.body.keys[code / 8], code % 8, val) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define TOGGLE_CONSUMER(match, val) \ |
|
|
|
#define TOGGLE_CONSUMER(match, val) \ |
|
|
|
for (int idx = 0; idx < MAX_KEYS; idx++) { \
|
|
|
|
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) { |
|
|
|
if (code >= LCTL && code <= RGUI) { |
|
|
|
return zmk_hid_register_mod(code - LCTL); |
|
|
|
return zmk_hid_register_mod(code - LCTL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
TOGGLE_KEYPAD(0U, code); |
|
|
|
if (code > ZMK_HID_MAX_KEYCODE) { |
|
|
|
|
|
|
|
return -EINVAL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TOGGLE_BOOT_KEY(0U, code);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TOGGLE_KEY(code, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -82,15 +67,7 @@ int zmk_hid_keypad_release(zmk_key code) { |
|
|
|
if (code >= LCTL && code <= RGUI) { |
|
|
|
if (code >= LCTL && code <= RGUI) { |
|
|
|
return zmk_hid_unregister_mod(code - LCTL); |
|
|
|
return zmk_hid_unregister_mod(code - LCTL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
TOGGLE_KEYPAD(code, 0U); |
|
|
|
if (code > ZMK_HID_MAX_KEYCODE) { |
|
|
|
|
|
|
|
return -EINVAL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TOGGLE_BOOT_KEY(0U, code);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TOGGLE_KEY(code, false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|