Browse Source

refactor(hid): Refactor consumer report to a configurable size

xmkb
innovaker 4 years ago
parent
commit
8ce7d8de01
  1. 8
      app/include/zmk/hid.h
  2. 7
      app/src/hid.c

8
app/include/zmk/hid.h

@ -15,6 +15,8 @@
#define ZMK_HID_KEYPAD_NKRO_SIZE 6 #define ZMK_HID_KEYPAD_NKRO_SIZE 6
#define ZMK_HID_CONSUMER_NKRO_SIZE 6
static const u8_t zmk_hid_report_desc[] = { static const u8_t zmk_hid_report_desc[] = {
/* USAGE_PAGE (Generic Desktop) */ /* USAGE_PAGE (Generic Desktop) */
HID_GI_USAGE_PAGE, HID_GI_USAGE_PAGE,
@ -111,9 +113,9 @@ static const u8_t zmk_hid_report_desc[] = {
/* REPORT_SIZE (8) */ /* REPORT_SIZE (8) */
HID_GI_REPORT_SIZE, HID_GI_REPORT_SIZE,
0x08, 0x08,
/* REPORT_COUNT (8) */ /* REPORT_COUNT (ZMK_HID_CONSUMER_NKRO_SIZE) */
HID_GI_REPORT_COUNT, HID_GI_REPORT_COUNT,
0x06, ZMK_HID_CONSUMER_NKRO_SIZE,
HID_MI_INPUT, HID_MI_INPUT,
0x00, 0x00,
/* END COLLECTION */ /* END COLLECTION */
@ -138,7 +140,7 @@ struct zmk_hid_keypad_report {
} __packed; } __packed;
struct zmk_hid_consumer_report_body { struct zmk_hid_consumer_report_body {
u8_t keys[6]; u8_t keys[ZMK_HID_CONSUMER_NKRO_SIZE];
} __packed; } __packed;
struct zmk_hid_consumer_report { struct zmk_hid_consumer_report {

7
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, static struct zmk_hid_keypad_report kp_report = {.report_id = 1,
.body = {.modifiers = 0, .keys = {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}}};
.body = {.keys = {0, 0, 0, 0, 0, 0}}};
#define _TOGGLE_MOD(mod, state) \ #define _TOGGLE_MOD(mod, state) \
if (modifier > MOD_RGUI) { \ if (modifier > MOD_RGUI) { \
@ -35,8 +34,6 @@ int zmk_hid_unregister_mods(zmk_mod_flags modifiers) {
return 0; return 0;
} }
#define MAX_KEYS 6
#define TOGGLE_KEYPAD(match, val) \ #define TOGGLE_KEYPAD(match, val) \
for (int idx = 0; idx < ZMK_HID_KEYPAD_NKRO_SIZE; idx++) { \ for (int idx = 0; idx < ZMK_HID_KEYPAD_NKRO_SIZE; idx++) { \
if (kp_report.body.keys[idx] != match) { \ 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) \ #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) { \ if (consumer_report.body.keys[idx] != match) { \
continue; \ continue; \
} \ } \

Loading…
Cancel
Save