refactor(hid): Move hid logic into hid.c
Move the logic for picking the correct hid function into hid.c.
This commit is contained in:
parent
6150ad65c4
commit
57fca34dc0
3 changed files with 33 additions and 30 deletions
|
@ -133,6 +133,7 @@ int zmk_hid_register_mods(zmk_mod_flags_t explicit_modifiers);
|
||||||
int zmk_hid_unregister_mods(zmk_mod_flags_t explicit_modifiers);
|
int zmk_hid_unregister_mods(zmk_mod_flags_t explicit_modifiers);
|
||||||
int zmk_hid_implicit_modifiers_press(zmk_mod_flags_t implicit_modifiers);
|
int zmk_hid_implicit_modifiers_press(zmk_mod_flags_t implicit_modifiers);
|
||||||
int zmk_hid_implicit_modifiers_release();
|
int zmk_hid_implicit_modifiers_release();
|
||||||
|
|
||||||
int zmk_hid_keyboard_press(zmk_key_t key);
|
int zmk_hid_keyboard_press(zmk_key_t key);
|
||||||
int zmk_hid_keyboard_release(zmk_key_t key);
|
int zmk_hid_keyboard_release(zmk_key_t key);
|
||||||
void zmk_hid_keyboard_clear();
|
void zmk_hid_keyboard_clear();
|
||||||
|
@ -141,5 +142,8 @@ int zmk_hid_consumer_press(zmk_key_t key);
|
||||||
int zmk_hid_consumer_release(zmk_key_t key);
|
int zmk_hid_consumer_release(zmk_key_t key);
|
||||||
void zmk_hid_consumer_clear();
|
void zmk_hid_consumer_clear();
|
||||||
|
|
||||||
|
int zmk_hid_press(uint32_t usage);
|
||||||
|
int zmk_hid_release(uint32_t usage);
|
||||||
|
|
||||||
struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report();
|
struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report();
|
||||||
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report();
|
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report();
|
||||||
|
|
|
@ -176,6 +176,26 @@ int zmk_hid_consumer_release(zmk_key_t code) {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int zmk_hid_press(uint32_t usage) {
|
||||||
|
switch (ZMK_HID_USAGE_PAGE(usage)) {
|
||||||
|
case HID_USAGE_KEY:
|
||||||
|
return zmk_hid_keyboard_press(ZMK_HID_USAGE_ID(usage));
|
||||||
|
case HID_USAGE_CONSUMER:
|
||||||
|
return zmk_hid_consumer_press(ZMK_HID_USAGE_ID(usage));
|
||||||
|
}
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int zmk_hid_release(uint32_t usage) {
|
||||||
|
switch (ZMK_HID_USAGE_PAGE(usage)) {
|
||||||
|
case HID_USAGE_KEY:
|
||||||
|
return zmk_hid_keyboard_release(ZMK_HID_USAGE_ID(usage));
|
||||||
|
case HID_USAGE_CONSUMER:
|
||||||
|
return zmk_hid_consumer_release(ZMK_HID_USAGE_ID(usage));
|
||||||
|
}
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
void zmk_hid_consumer_clear() { memset(&consumer_report.body, 0, sizeof(consumer_report.body)); }
|
void zmk_hid_consumer_clear() { memset(&consumer_report.body, 0, sizeof(consumer_report.body)); }
|
||||||
|
|
||||||
struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report() {
|
struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report() {
|
||||||
|
|
|
@ -21,21 +21,10 @@ static int hid_listener_keycode_pressed(const struct zmk_keycode_state_changed *
|
||||||
|
|
||||||
LOG_DBG("usage_page 0x%02X keycode 0x%02X implicit_mods 0x%02X explicit_mods 0x%02X",
|
LOG_DBG("usage_page 0x%02X keycode 0x%02X implicit_mods 0x%02X explicit_mods 0x%02X",
|
||||||
ev->usage_page, ev->keycode, ev->implicit_modifiers, ev->explicit_modifiers);
|
ev->usage_page, ev->keycode, ev->implicit_modifiers, ev->explicit_modifiers);
|
||||||
switch (ev->usage_page) {
|
err = zmk_hid_press(ZMK_HID_USAGE(ev->usage_page, ev->keycode));
|
||||||
case HID_USAGE_KEY:
|
if (err < 0) {
|
||||||
err = zmk_hid_keyboard_press(ev->keycode);
|
LOG_DBG("Unable to press keycode");
|
||||||
if (err < 0) {
|
return err;
|
||||||
LOG_ERR("Unable to press keycode");
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case HID_USAGE_CONSUMER:
|
|
||||||
err = zmk_hid_consumer_press(ev->keycode);
|
|
||||||
if (err < 0) {
|
|
||||||
LOG_ERR("Unable to press keycode");
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
explicit_mods_changed = zmk_hid_register_mods(ev->explicit_modifiers);
|
explicit_mods_changed = zmk_hid_register_mods(ev->explicit_modifiers);
|
||||||
implicit_mods_changed = zmk_hid_implicit_modifiers_press(ev->implicit_modifiers);
|
implicit_mods_changed = zmk_hid_implicit_modifiers_press(ev->implicit_modifiers);
|
||||||
|
@ -56,20 +45,10 @@ static int hid_listener_keycode_released(const struct zmk_keycode_state_changed
|
||||||
|
|
||||||
LOG_DBG("usage_page 0x%02X keycode 0x%02X implicit_mods 0x%02X explicit_mods 0x%02X",
|
LOG_DBG("usage_page 0x%02X keycode 0x%02X implicit_mods 0x%02X explicit_mods 0x%02X",
|
||||||
ev->usage_page, ev->keycode, ev->implicit_modifiers, ev->explicit_modifiers);
|
ev->usage_page, ev->keycode, ev->implicit_modifiers, ev->explicit_modifiers);
|
||||||
switch (ev->usage_page) {
|
err = zmk_hid_release(ZMK_HID_USAGE(ev->usage_page, ev->keycode));
|
||||||
case HID_USAGE_KEY:
|
if (err < 0) {
|
||||||
err = zmk_hid_keyboard_release(ev->keycode);
|
LOG_DBG("Unable to release keycode");
|
||||||
if (err < 0) {
|
return err;
|
||||||
LOG_ERR("Unable to release keycode");
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case HID_USAGE_CONSUMER:
|
|
||||||
err = zmk_hid_consumer_release(ev->keycode);
|
|
||||||
if (err < 0) {
|
|
||||||
LOG_ERR("Unable to release keycode");
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit_mods_changed = zmk_hid_unregister_mods(ev->explicit_modifiers);
|
explicit_mods_changed = zmk_hid_unregister_mods(ev->explicit_modifiers);
|
||||||
|
@ -104,4 +83,4 @@ int hid_listener(const zmk_event_t *eh) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ZMK_LISTENER(hid_listener, hid_listener);
|
ZMK_LISTENER(hid_listener, hid_listener);
|
||||||
ZMK_SUBSCRIPTION(hid_listener, zmk_keycode_state_changed);
|
ZMK_SUBSCRIPTION(hid_listener, zmk_keycode_state_changed);
|
||||||
|
|
Loading…
Reference in a new issue