Browse Source

refactor(hid): Replace deprecated HID usage page references

Deprecate `USAGE_KEYPAD` and replace with `HID_USAGE_KEY`.

Deprecate `USAGE_CONSUMER` and replace with `HID_USAGE_CONSUMER`.

Closes #217.
xmkb
innovaker 4 years ago committed by Pete Johanson
parent
commit
e925319e4c
  1. 7
      app/dts/behaviors/key_press.dtsi
  2. 7
      app/dts/behaviors/sensor_rotate_key_press.dtsi
  3. 4
      app/include/dt-bindings/zmk/hid_usage_pages.h
  4. 4
      app/include/dt-bindings/zmk/keys.h
  5. 3
      app/src/behaviors/behavior_hold_tap.c
  6. 9
      app/src/endpoints.c
  7. 9
      app/src/hid_listener.c

7
app/dts/behaviors/key_press.dtsi

@ -1,18 +1,19 @@
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/hid_usage_pages.h>
/ { / {
behaviors { behaviors {
kp: behavior_key_press { kp: behavior_key_press {
compatible = "zmk,behavior-key-press"; compatible = "zmk,behavior-key-press";
label = "KEY_PRESS"; label = "KEY_PRESS";
usage_page = <USAGE_KEYPAD>; usage_page = <HID_USAGE_KEY>;
#binding-cells = <1>; #binding-cells = <1>;
}; };
cp: behavior_consumer_press { cp: behavior_consumer_press {
compatible = "zmk,behavior-key-press"; compatible = "zmk,behavior-key-press";
label = "CONSUMER_PRESS"; label = "CONSUMER_PRESS";
usage_page = <USAGE_CONSUMER>; usage_page = <HID_USAGE_CONSUMER>;
#binding-cells = <1>; #binding-cells = <1>;
}; };
}; };

7
app/dts/behaviors/sensor_rotate_key_press.dtsi

@ -1,18 +1,19 @@
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/hid_usage_pages.h>
/ { / {
behaviors { behaviors {
inc_dec_kp: behavior_sensor_rotate_key_press { inc_dec_kp: behavior_sensor_rotate_key_press {
compatible = "zmk,behavior-sensor-rotate-key-press"; compatible = "zmk,behavior-sensor-rotate-key-press";
label = "ENC_KEY_PRESS"; label = "ENC_KEY_PRESS";
usage_page = <USAGE_KEYPAD>; usage_page = <HID_USAGE_KEY>;
#sensor-binding-cells = <2>; #sensor-binding-cells = <2>;
}; };
inc_dec_cp: behavior_sensor_rotate_consumer_press { inc_dec_cp: behavior_sensor_rotate_consumer_press {
compatible = "zmk,behavior-sensor-rotate-key-press"; compatible = "zmk,behavior-sensor-rotate-key-press";
label = "ENC_CONSUMER_PRESS"; label = "ENC_CONSUMER_PRESS";
usage_page = <USAGE_CONSUMER>; usage_page = <HID_USAGE_CONSUMER>;
#sensor-binding-cells = <2>; #sensor-binding-cells = <2>;
}; };
}; };

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

@ -10,6 +10,10 @@
#pragma once #pragma once
/* WARNING: DEPRECATED from dt-bindings/zmk/keys.h */
#define USAGE_KEYPAD (0x07) // WARNING: DEPRECATED (DO NOT USE)
#define USAGE_CONSUMER (0x0C) // WARNING: DEPRECATED (DO NOT USE)
#define HID_USAGE_GD (0x01) // Generic Desktop #define HID_USAGE_GD (0x01) // Generic Desktop
#define HID_USAGE_SIM (0x02) // Simulation Controls #define HID_USAGE_SIM (0x02) // Simulation Controls
#define HID_USAGE_VR (0x03) // VR Controls #define HID_USAGE_VR (0x03) // VR Controls

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

@ -6,10 +6,6 @@
#pragma once #pragma once
#include <dt-bindings/zmk/modifiers.h> #include <dt-bindings/zmk/modifiers.h>
#define USAGE_KEYPAD 0x07
#define USAGE_CONSUMER 0x0C
#define A 0x04 #define A 0x04
#define B 0x05 #define B 0x05
#define C 0x06 #define C 0x06

3
app/src/behaviors/behavior_hold_tap.c

@ -9,6 +9,7 @@
#include <device.h> #include <device.h>
#include <drivers/behavior.h> #include <drivers/behavior.h>
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/hid_usage_pages.h>
#include <logging/log.h> #include <logging/log.h>
#include <zmk/behavior.h> #include <zmk/behavior.h>
#include <zmk/matrix.h> #include <zmk/matrix.h>
@ -428,7 +429,7 @@ static int position_state_changed_listener(const struct zmk_event_header *eh) {
} }
static inline bool only_mods(struct keycode_state_changed *ev) { static inline bool only_mods(struct keycode_state_changed *ev) {
return ev->usage_page == USAGE_KEYPAD && ev->keycode >= LCTL && ev->keycode <= RGUI; return ev->usage_page == HID_USAGE_KEY && ev->keycode >= LCTL && ev->keycode <= RGUI;
} }
static int keycode_state_changed_listener(const struct zmk_event_header *eh) { static int keycode_state_changed_listener(const struct zmk_event_header *eh) {

9
app/src/endpoints.c

@ -10,6 +10,7 @@
#include <zmk/ble.h> #include <zmk/ble.h>
#include <zmk/endpoints.h> #include <zmk/endpoints.h>
#include <zmk/hid.h> #include <zmk/hid.h>
#include <dt-bindings/zmk/hid_usage_pages.h>
#include <zmk/usb.h> #include <zmk/usb.h>
#include <zmk/hog.h> #include <zmk/hog.h>
#include <zmk/event-manager.h> #include <zmk/event-manager.h>
@ -116,9 +117,9 @@ int zmk_endpoints_send_report(u8_t usage_page) {
LOG_DBG("usage page 0x%02X", usage_page); LOG_DBG("usage page 0x%02X", usage_page);
switch (usage_page) { switch (usage_page) {
case USAGE_KEYPAD: case HID_USAGE_KEY:
return send_keypad_report(); return send_keypad_report();
case USAGE_CONSUMER: case HID_USAGE_CONSUMER:
return send_consumer_report(); return send_consumer_report();
default: default:
LOG_ERR("Unsupported usage page %d", usage_page); LOG_ERR("Unsupported usage page %d", usage_page);
@ -209,8 +210,8 @@ static void disconnect_current_endpoint() {
zmk_hid_keypad_clear(); zmk_hid_keypad_clear();
zmk_hid_consumer_clear(); zmk_hid_consumer_clear();
zmk_endpoints_send_report(USAGE_KEYPAD); zmk_endpoints_send_report(HID_USAGE_KEY);
zmk_endpoints_send_report(USAGE_CONSUMER); zmk_endpoints_send_report(HID_USAGE_CONSUMER);
} }
static void update_current_endpoint() { static void update_current_endpoint() {

9
app/src/hid_listener.c

@ -13,6 +13,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/events/keycode-state-changed.h> #include <zmk/events/keycode-state-changed.h>
#include <zmk/events/modifiers-state-changed.h> #include <zmk/events/modifiers-state-changed.h>
#include <zmk/hid.h> #include <zmk/hid.h>
#include <dt-bindings/zmk/hid_usage_pages.h>
#include <zmk/endpoints.h> #include <zmk/endpoints.h>
static int hid_listener_keycode_pressed(u8_t usage_page, u32_t keycode, static int hid_listener_keycode_pressed(u8_t usage_page, u32_t keycode,
@ -21,14 +22,14 @@ static int hid_listener_keycode_pressed(u8_t usage_page, u32_t keycode,
LOG_DBG("usage_page 0x%02X keycode 0x%02X mods 0x%02X", usage_page, keycode, LOG_DBG("usage_page 0x%02X keycode 0x%02X mods 0x%02X", usage_page, keycode,
implicit_modifiers); implicit_modifiers);
switch (usage_page) { switch (usage_page) {
case USAGE_KEYPAD: case HID_USAGE_KEY:
err = zmk_hid_keypad_press(keycode); err = zmk_hid_keypad_press(keycode);
if (err) { if (err) {
LOG_ERR("Unable to press keycode"); LOG_ERR("Unable to press keycode");
return err; return err;
} }
break; break;
case USAGE_CONSUMER: case HID_USAGE_CONSUMER:
err = zmk_hid_consumer_press(keycode); err = zmk_hid_consumer_press(keycode);
if (err) { if (err) {
LOG_ERR("Unable to press keycode"); LOG_ERR("Unable to press keycode");
@ -46,14 +47,14 @@ static int hid_listener_keycode_released(u8_t usage_page, u32_t keycode,
LOG_DBG("usage_page 0x%02X keycode 0x%02X mods 0x%02X", usage_page, keycode, LOG_DBG("usage_page 0x%02X keycode 0x%02X mods 0x%02X", usage_page, keycode,
implicit_modifiers); implicit_modifiers);
switch (usage_page) { switch (usage_page) {
case USAGE_KEYPAD: case HID_USAGE_KEY:
err = zmk_hid_keypad_release(keycode); err = zmk_hid_keypad_release(keycode);
if (err) { if (err) {
LOG_ERR("Unable to release keycode"); LOG_ERR("Unable to release keycode");
return err; return err;
} }
break; break;
case USAGE_CONSUMER: case HID_USAGE_CONSUMER:
err = zmk_hid_consumer_release(keycode); err = zmk_hid_consumer_release(keycode);
if (err) { if (err) {
LOG_ERR("Unable to release keycode"); LOG_ERR("Unable to release keycode");

Loading…
Cancel
Save