Browse Source

refactor: Handle HID macro/API changes in Zephyr.

xmkb
Peter Johanson 3 years ago committed by Pete Johanson
parent
commit
40d8470664
  1. 6
      app/include/dt-bindings/zmk/hid_usage_pages.h
  2. 755
      app/include/dt-bindings/zmk/keys.h
  3. 4
      app/include/zmk/events/keycode_state_changed.h
  4. 202
      app/include/zmk/hid.h
  5. 4
      app/src/behaviors/behavior_caps_word.c
  6. 4
      app/src/behaviors/behavior_sticky_key.c

6
app/include/dt-bindings/zmk/hid_usage_pages.h

@ -10,9 +10,9 @@
#pragma once #pragma once
#define HID_USAGE(page, id) ((page << 16) | id) #define ZMK_HID_USAGE(page, id) ((page << 16) | id)
#define HID_USAGE_ID(usage) (usage & 0xFFFF) #define ZMK_HID_USAGE_ID(usage) (usage & 0xFFFF)
#define HID_USAGE_PAGE(usage) (usage >> 16) #define ZMK_HID_USAGE_PAGE(usage) (usage >> 16)
/* WARNING: DEPRECATED from dt-bindings/zmk/keys.h */ /* WARNING: DEPRECATED from dt-bindings/zmk/keys.h */
#define USAGE_KEYPAD (0x07) // WARNING: DEPRECATED (DO NOT USE) #define USAGE_KEYPAD (0x07) // WARNING: DEPRECATED (DO NOT USE)

755
app/include/dt-bindings/zmk/keys.h

File diff suppressed because it is too large Load Diff

4
app/include/zmk/events/keycode_state_changed.h

@ -23,8 +23,8 @@ ZMK_EVENT_DECLARE(zmk_keycode_state_changed);
static inline struct zmk_keycode_state_changed_event * static inline struct zmk_keycode_state_changed_event *
zmk_keycode_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) { zmk_keycode_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) {
uint16_t page = HID_USAGE_PAGE(encoded) & 0xFF; uint16_t page = ZMK_HID_USAGE_PAGE(encoded) & 0xFF;
uint16_t id = HID_USAGE_ID(encoded); uint16_t id = ZMK_HID_USAGE_ID(encoded);
uint8_t implicit_modifiers = 0x00; uint8_t implicit_modifiers = 0x00;
uint8_t explicit_modifiers = 0x00; uint8_t explicit_modifiers = 0x00;

202
app/include/zmk/hid.h

@ -18,173 +18,77 @@
#define COLLECTION_REPORT 0x03 #define COLLECTION_REPORT 0x03
static const uint8_t zmk_hid_report_desc[] = { static const uint8_t zmk_hid_report_desc[] = {
/* USAGE_PAGE (Generic Desktop) */ HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP),
HID_GI_USAGE_PAGE, HID_USAGE(HID_USAGE_GD_KEYBOARD),
HID_USAGE_GD, HID_COLLECTION(HID_COLLECTION_APPLICATION),
/* USAGE (Keyboard) */ HID_REPORT_ID(0x01),
HID_LI_USAGE, HID_USAGE_PAGE(HID_USAGE_KEY),
HID_USAGE_GD_KEYBOARD, HID_USAGE_MIN8(HID_USAGE_KEY_KEYBOARD_LEFTCONTROL),
/* COLLECTION (Application) */ HID_USAGE_MAX8(HID_USAGE_KEY_KEYBOARD_RIGHT_GUI),
HID_MI_COLLECTION, HID_LOGICAL_MIN8(0x00),
COLLECTION_APPLICATION, HID_LOGICAL_MAX8(0x01),
/* REPORT ID (1) */
HID_GI_REPORT_ID, HID_REPORT_SIZE(0x01),
0x01, HID_REPORT_COUNT(0x08),
/* USAGE_PAGE (Keyboard/Keypad) */
HID_GI_USAGE_PAGE,
HID_USAGE_KEY,
/* USAGE_MINIMUM (Keyboard LeftControl) */
HID_LI_USAGE_MIN(1),
HID_USAGE_KEY_KEYBOARD_LEFTCONTROL,
/* USAGE_MAXIMUM (Keyboard Right GUI) */
HID_LI_USAGE_MAX(1),
HID_USAGE_KEY_KEYBOARD_RIGHT_GUI,
/* LOGICAL_MINIMUM (0) */
HID_GI_LOGICAL_MIN(1),
0x00,
/* LOGICAL_MAXIMUM (1) */
HID_GI_LOGICAL_MAX(1),
0x01,
/* REPORT_SIZE (1) */
HID_GI_REPORT_SIZE,
0x01,
/* REPORT_COUNT (8) */
HID_GI_REPORT_COUNT,
0x08,
/* INPUT (Data,Var,Abs) */ /* INPUT (Data,Var,Abs) */
HID_MI_INPUT, HID_INPUT(0x02),
0x02,
HID_USAGE_PAGE(HID_USAGE_KEY),
/* USAGE_PAGE (Keyboard/Keypad) */ HID_REPORT_SIZE(0x08),
HID_GI_USAGE_PAGE, HID_REPORT_COUNT(0x01),
HID_USAGE_KEY,
/* REPORT_SIZE (8) */
HID_GI_REPORT_SIZE,
0x08,
/* REPORT_COUNT (1) */
HID_GI_REPORT_COUNT,
0x01,
/* INPUT (Cnst,Var,Abs) */ /* INPUT (Cnst,Var,Abs) */
HID_MI_INPUT, HID_INPUT(0x03),
0x03,
/* USAGE_PAGE (Keyboard/Keypad) */ HID_USAGE_PAGE(HID_USAGE_KEY),
HID_GI_USAGE_PAGE,
HID_USAGE_KEY,
#if IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_NKRO) #if IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_NKRO)
/* LOGICAL_MINIMUM (0) */ HID_LOGICAL_MIN8(0x00),
HID_GI_LOGICAL_MIN(1), HID_LOGICAL_MAX8(0x01),
0x00, HID_USAGE_MIN8(0x00),
/* LOGICAL_MAXIMUM (1) */ HID_USAGE_MAX8(ZMK_HID_KEYBOARD_NKRO_MAX_USAGE),
HID_GI_LOGICAL_MAX(1), HID_REPORT_SIZE(0x01),
0x01, HID_REPORT_COUNT(ZMK_HID_KEYBOARD_NKRO_MAX_USAGE + 1),
/* USAGE_MINIMUM (Reserved) */
HID_LI_USAGE_MIN(1),
0x00,
/* USAGE_MAXIMUM (Keyboard Application) */
HID_LI_USAGE_MAX(1),
ZMK_HID_KEYBOARD_NKRO_MAX_USAGE,
/* REPORT_SIZE (8) */
HID_GI_REPORT_SIZE,
0x01,
/* REPORT_COUNT (6) */
HID_GI_REPORT_COUNT,
ZMK_HID_KEYBOARD_NKRO_MAX_USAGE + 1,
/* INPUT (Data,Ary,Abs) */ /* INPUT (Data,Ary,Abs) */
HID_MI_INPUT, HID_INPUT(0x02),
0x02,
#elif IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_HKRO) #elif IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_HKRO)
/* LOGICAL_MINIMUM (0) */ HID_LOGICAL_MIN8(0x00),
HID_GI_LOGICAL_MIN(1), HID_LOGICAL_MAX8(0xFF),
0x00, HID_USAGE_MIN8(0x00),
/* LOGICAL_MAXIMUM (0xFF) */ HID_USAGE_MAX8(0xFF),
HID_GI_LOGICAL_MAX(1), HID_REPORT_SIZE(0x08),
0xFF, HID_REPORT_COUNT(CONFIG_ZMK_HID_KEYBOARD_REPORT_SIZE),
/* USAGE_MINIMUM (Reserved) */
HID_LI_USAGE_MIN(1),
0x00,
/* USAGE_MAXIMUM (Keyboard Application) */
HID_LI_USAGE_MAX(1),
0xFF,
/* REPORT_SIZE (1) */
HID_GI_REPORT_SIZE,
0x08,
/* REPORT_COUNT (CONFIG_ZMK_HID_KEYBOARD_REPORT_SIZE) */
HID_GI_REPORT_COUNT,
CONFIG_ZMK_HID_KEYBOARD_REPORT_SIZE,
/* INPUT (Data,Ary,Abs) */ /* INPUT (Data,Ary,Abs) */
HID_MI_INPUT, HID_INPUT(0x00),
0x00,
#else #else
#error "A proper HID report type must be selected" #error "A proper HID report type must be selected"
#endif #endif
/* END_COLLECTION */ HID_END_COLLECTION,
HID_MI_COLLECTION_END, HID_USAGE_PAGE(HID_USAGE_CONSUMER),
/* USAGE_PAGE (Consumer) */ HID_USAGE(HID_USAGE_CONSUMER_CONSUMER_CONTROL),
HID_GI_USAGE_PAGE, HID_COLLECTION(HID_COLLECTION_APPLICATION),
HID_USAGE_CONSUMER, HID_REPORT_ID(0x02),
/* USAGE (Consumer Control) */ HID_USAGE_PAGE(HID_USAGE_CONSUMER),
HID_LI_USAGE,
HID_USAGE_CONSUMER_CONSUMER_CONTROL,
/* Consumer Page */
HID_MI_COLLECTION,
COLLECTION_APPLICATION,
/* REPORT ID (1) */
HID_GI_REPORT_ID,
0x02,
/* USAGE_PAGE (Consumer) */
HID_GI_USAGE_PAGE,
HID_USAGE_CONSUMER,
#if IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_BASIC) #if IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_BASIC)
/* LOGICAL_MINIMUM (0) */ HID_LOGICAL_MIN8(0x00),
HID_GI_LOGICAL_MIN(1), HID_LOGICAL_MAX16(0xFF, 0x00),
0x00, HID_USAGE_MIN8(0x00),
/* LOGICAL_MAXIMUM (0x00FF) - little endian, and requires two bytes because logical max is HID_USAGE_MAX8(0xFF),
signed */ HID_REPORT_SIZE(0x08),
HID_GI_LOGICAL_MAX(2),
0xFF,
0x00,
HID_LI_USAGE_MIN(1),
0x00,
/* USAGE_MAXIMUM (0xFF) */
HID_LI_USAGE_MAX(1),
0xFF,
/* INPUT (Data,Ary,Abs) */
/* REPORT_SIZE (8) */
HID_GI_REPORT_SIZE,
0x08,
#elif IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_FULL) #elif IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_FULL)
/* LOGICAL_MINIMUM (0) */ HID_LOGICAL_MIN8(0x00),
HID_GI_LOGICAL_MIN(1), HID_LOGICAL_MAX16(0xFF, 0xFF),
0x00, HID_USAGE_MIN8(0x00),
/* LOGICAL_MAXIMUM (0xFFFF) */ HID_USAGE_MAX16(0xFF, 0xFF),
HID_GI_LOGICAL_MAX(2), HID_REPORT_SIZE(0x10),
0xFF,
0xFF,
HID_LI_USAGE_MIN(1),
0x00,
/* USAGE_MAXIMUM (0xFFFF) */
HID_LI_USAGE_MAX(2),
0xFF,
0xFF,
/* INPUT (Data,Ary,Abs) */
/* REPORT_SIZE (16) */
HID_GI_REPORT_SIZE,
0x10,
#else #else
#error "A proper consumer HID report usage range must be selected" #error "A proper consumer HID report usage range must be selected"
#endif #endif
/* REPORT_COUNT (CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE) */ HID_REPORT_COUNT(CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE),
HID_GI_REPORT_COUNT, /* INPUT (Data,Ary,Abs) */
CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE, HID_INPUT(0x00),
HID_MI_INPUT, HID_END_COLLECTION,
0x00,
/* END COLLECTION */
HID_MI_COLLECTION_END,
}; };
// struct zmk_hid_boot_report // struct zmk_hid_boot_report

4
app/src/behaviors/behavior_caps_word.c

@ -162,8 +162,8 @@ static int behavior_caps_word_init(const struct device *dev) {
#define CAPS_WORD_LABEL(i, _n) DT_INST_LABEL(i) #define CAPS_WORD_LABEL(i, _n) DT_INST_LABEL(i)
#define PARSE_BREAK(i) \ #define PARSE_BREAK(i) \
{.page = (HID_USAGE_PAGE(i) & 0xFF), \ {.page = (ZMK_HID_USAGE_PAGE(i) & 0xFF), \
.id = HID_USAGE_ID(i), \ .id = ZMK_HID_USAGE_ID(i), \
.implicit_modifiers = SELECT_MODS(i)}, .implicit_modifiers = SELECT_MODS(i)},
#define BREAK_ITEM(i, n) PARSE_BREAK(DT_INST_PROP_BY_IDX(n, continue_list, i)) #define BREAK_ITEM(i, n) PARSE_BREAK(DT_INST_PROP_BY_IDX(n, continue_list, i))

4
app/src/behaviors/behavior_sticky_key.c

@ -198,8 +198,8 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) {
} }
if (strcmp(sticky_key->config->behavior.behavior_dev, "KEY_PRESS") == 0 && if (strcmp(sticky_key->config->behavior.behavior_dev, "KEY_PRESS") == 0 &&
HID_USAGE_ID(sticky_key->param1) == ev->keycode && ZMK_HID_USAGE_ID(sticky_key->param1) == ev->keycode &&
(HID_USAGE_PAGE(sticky_key->param1) & 0xFF) == ev->usage_page && (ZMK_HID_USAGE_PAGE(sticky_key->param1) & 0xFF) == ev->usage_page &&
SELECT_MODS(sticky_key->param1) == ev->implicit_modifiers) { SELECT_MODS(sticky_key->param1) == ev->implicit_modifiers) {
// don't catch key down events generated by the sticky key behavior itself // don't catch key down events generated by the sticky key behavior itself
continue; continue;

Loading…
Cancel
Save