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.
This commit is contained in:
parent
91ba034896
commit
bc179b1030
3 changed files with 45 additions and 1 deletions
19
app/Kconfig
19
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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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; \
|
||||
|
|
Loading…
Reference in a new issue