Skip to content

Commit bcfa8d1

Browse files
t-8chJiri Kosina
authored andcommitted
HID: input: Add support for Programmable Buttons
Map them to KEY_MACRO# event codes. These buttons are defined by HID as follows: "The user defines the function of these buttons to control software applications or GUI objects." This matches the semantics of the KEY_MACRO# input event codes that Linux supports. Also add support for HID "Named Array" collections. Also add hid-debug support for KEY_MACRO#. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent b15b253 commit bcfa8d1

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

drivers/hid/hid-debug.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static const struct hid_usage_entry hid_usage_table[] = {
122122
{ 9, 0, "Button" },
123123
{ 10, 0, "Ordinal" },
124124
{ 12, 0, "Consumer" },
125+
{0, 0x003, "ProgrammableButtons"},
125126
{0, 0x238, "HorizontalWheel"},
126127
{ 13, 0, "Digitizers" },
127128
{0, 0x01, "Digitizer"},
@@ -939,6 +940,16 @@ static const char *keys[KEY_MAX + 1] = {
939940
[KEY_KBDINPUTASSIST_NEXTGROUP] = "KbdInputAssistNextGroup",
940941
[KEY_KBDINPUTASSIST_ACCEPT] = "KbdInputAssistAccept",
941942
[KEY_KBDINPUTASSIST_CANCEL] = "KbdInputAssistCancel",
943+
[KEY_MACRO1] = "Macro1", [KEY_MACRO2] = "Macro2", [KEY_MACRO3] = "Macro3",
944+
[KEY_MACRO4] = "Macro4", [KEY_MACRO5] = "Macro5", [KEY_MACRO6] = "Macro6",
945+
[KEY_MACRO7] = "Macro7", [KEY_MACRO8] = "Macro8", [KEY_MACRO9] = "Macro9",
946+
[KEY_MACRO10] = "Macro10", [KEY_MACRO11] = "Macro11", [KEY_MACRO12] = "Macro12",
947+
[KEY_MACRO13] = "Macro13", [KEY_MACRO14] = "Macro14", [KEY_MACRO15] = "Macro15",
948+
[KEY_MACRO16] = "Macro16", [KEY_MACRO17] = "Macro17", [KEY_MACRO18] = "Macro18",
949+
[KEY_MACRO19] = "Macro19", [KEY_MACRO20] = "Macro20", [KEY_MACRO21] = "Macro21",
950+
[KEY_MACRO22] = "Macro22", [KEY_MACRO23] = "Macro23", [KEY_MACRO24] = "Macro24",
951+
[KEY_MACRO25] = "Macro25", [KEY_MACRO26] = "Macro26", [KEY_MACRO27] = "Macro27",
952+
[KEY_MACRO28] = "Macro28", [KEY_MACRO29] = "Macro29", [KEY_MACRO30] = "Macro30",
942953
};
943954

944955
static const char *relatives[REL_MAX + 1] = {

drivers/hid/hid-input.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,16 @@ static void hidinput_update_battery(struct hid_device *dev, int value)
567567
}
568568
#endif /* CONFIG_HID_BATTERY_STRENGTH */
569569

570+
static bool hidinput_field_in_collection(struct hid_device *device, struct hid_field *field,
571+
unsigned int type, unsigned int usage)
572+
{
573+
struct hid_collection *collection;
574+
575+
collection = &device->collection[field->usage->collection_index];
576+
577+
return collection->type == type && collection->usage == usage;
578+
}
579+
570580
static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field,
571581
struct hid_usage *usage)
572582
{
@@ -632,6 +642,18 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
632642
else
633643
code += BTN_TRIGGER_HAPPY - 0x10;
634644
break;
645+
case HID_CP_CONSUMER_CONTROL:
646+
if (hidinput_field_in_collection(device, field,
647+
HID_COLLECTION_NAMED_ARRAY,
648+
HID_CP_PROGRAMMABLEBUTTONS)) {
649+
if (code <= 0x1d)
650+
code += KEY_MACRO1;
651+
else
652+
code += BTN_TRIGGER_HAPPY - 0x1e;
653+
} else {
654+
goto ignore;
655+
}
656+
break;
635657
default:
636658
switch (field->physical) {
637659
case HID_GD_MOUSE:

include/linux/hid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct hid_item {
102102
#define HID_COLLECTION_PHYSICAL 0
103103
#define HID_COLLECTION_APPLICATION 1
104104
#define HID_COLLECTION_LOGICAL 2
105+
#define HID_COLLECTION_NAMED_ARRAY 4
105106

106107
/*
107108
* HID report descriptor global item tags

0 commit comments

Comments
 (0)