summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Johanson <peter@peterjohanson.com>2021-10-05 02:41:56 +0000
committerPete Johanson <peter@peterjohanson.com>2021-10-04 23:01:39 -0400
commitbc179b1030ccf9dd02818f77ecd9b5b9f14e85b7 (patch)
treec4386f2dde6a4bdaffcb9c2a9b64770d91669189
parent91ba034896c3b1668b88286e18d8f38314ec39c3 (diff)
feat(hid): Kconfig for basic/full consumer usages.
* Add ZMK_HID_CONSUMER_REPORT_USAGES choice to allow choosing between full consumer usage range, with poor OS compat, or basic consumer usage range, with broader compat.
-rw-r--r--app/Kconfig19
-rw-r--r--app/include/zmk/hid.h25
-rw-r--r--app/src/hid.c2
3 files changed, 45 insertions, 1 deletions
diff --git a/app/Kconfig b/app/Kconfig
index 629dfa7..35bf77d 100644
--- a/app/Kconfig
+++ b/app/Kconfig
@@ -51,13 +51,30 @@ config ZMK_HID_KEYBOARD_REPORT_SIZE
int "# Keyboard Keys Reportable"
default 6
-
endif
config ZMK_HID_CONSUMER_REPORT_SIZE
int "# Consumer Keys Reportable"
default 6
+
+choice ZMK_HID_CONSUMER_REPORT_USAGES
+ prompt "HID Report Type"
+
+config ZMK_HID_CONSUMER_REPORT_USAGES_FULL
+ bool "Full Consumer HID Usage Support"
+ help
+ Enable full Consumer usage ID values to be sent to hosts. Allows for less
+ frequently used usages, but has compatibability issues with some host OSes.
+
+config ZMK_HID_CONSUMER_REPORT_USAGES_BASIC
+ bool "Basic Consumer HID Usage Support"
+ help
+ Enable Consumer usage ID values up to "Playback Speed - Slow" to be sent to
+ hosts. Allows for broader compatibability with more host OSes.
+
+endchoice
+
menu "Output Types"
config ZMK_USB
diff --git a/app/include/zmk/hid.h b/app/include/zmk/hid.h
index be88c17..95b82d4 100644
--- a/app/include/zmk/hid.h
+++ b/app/include/zmk/hid.h
@@ -138,6 +138,24 @@ static const uint8_t zmk_hid_report_desc[] = {
/* USAGE_PAGE (Consumer) */
HID_GI_USAGE_PAGE,
HID_USAGE_CONSUMER,
+
+#if IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_BASIC)
+ /* LOGICAL_MINIMUM (0) */
+ HID_GI_LOGICAL_MIN(1),
+ 0x00,
+ /* LOGICAL_MAXIMUM (0xFFFF) */
+ HID_GI_LOGICAL_MAX(1),
+ 0xFF,
+ HID_LI_USAGE_MIN(1),
+ 0x00,
+ /* USAGE_MAXIMUM (0xFFFF) */
+ 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)
/* LOGICAL_MINIMUM (0) */
HID_GI_LOGICAL_MIN(1),
0x00,
@@ -155,6 +173,9 @@ static const uint8_t zmk_hid_report_desc[] = {
/* REPORT_SIZE (16) */
HID_GI_REPORT_SIZE,
0x10,
+#else
+#error "A proper consumer HID report usage range must be selected"
+#endif
/* REPORT_COUNT (CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE) */
HID_GI_REPORT_COUNT,
CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE,
@@ -187,7 +208,11 @@ struct zmk_hid_keyboard_report {
} __packed;
struct zmk_hid_consumer_report_body {
+#if IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_BASIC)
+ uint8_t keys[CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE];
+#elif IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_FULL)
uint16_t keys[CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE];
+#endif
} __packed;
struct zmk_hid_consumer_report {
diff --git a/app/src/hid.c b/app/src/hid.c
index 756ed90..b524b09 100644
--- a/app/src/hid.c
+++ b/app/src/hid.c
@@ -117,6 +117,8 @@ static inline int deselect_keyboard_usage(zmk_key_t usage) {
#endif
#define TOGGLE_CONSUMER(match, val) \
+ COND_CODE_1(IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_BASIC), \
+ (if (val > 0xFF) { return -ENOTSUP; }), ()) \
for (int idx = 0; idx < CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE; idx++) { \
if (consumer_report.body.keys[idx] != match) { \
continue; \