HID: input: Increase maximum number of joystick buttons
PATCH 1/1 HID: input: Increase maximum number of joystick buttons
This patch increases the limit from 80 to 112 key codes.
If a joystick has 80 or fewer buttons, mapping stays the same.
If a joystick has more than 80 buttons:
Map buttons [ 0 .. 15 ] to key codes starting with BTN_JOYSTICK; Map buttons [ 16 .. 47 ] to key codes starting with KEY_MACRO1; Map buttons [ 48 .. 111 ] to key codes starting with BTN_TRIGGER_HAPPY.
--- drivers/hid/hid-input.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/hid/hid-input.c +7 -1
@@ -763,7 +763,13 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fielif (code <=0xf ) code +=BTN_JOYSTICK ;else - code +=BTN_TRIGGER_HAPPY -0x10 ; +if (field->maxusage <=80 ) + code +=BTN_TRIGGER_HAPPY -0x10 ; +else +if (code <=0x2f ) + code +=KEY_MACRO1 -0x10 ; +else + code +=BTN_TRIGGER_HAPPY -0x30 ;break ;case HID_GD_GAMEPAD :if (code <=0xf )
Signature · 1 line
2.43.0
Quoted 24 lines · Ivan Gorinov
This patch increases the limit from 80 to 112 key codes.
If a joystick has 80 or fewer buttons, mapping stays the same.
If a joystick has more than 80 buttons:
Map buttons [ 0 .. 15 ] to key codes starting with BTN_JOYSTICK; Map buttons [ 16 .. 47 ] to key codes starting with KEY_MACRO1; Map buttons [ 48 .. 111 ] to key codes starting with BTN_TRIGGER_HAPPY.Signed-off-by Ivan Gorinov <[email protected]>--- drivers/hid/hid-input.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/hid/hid-input.c +0
-1@@ -763,7 +763,13 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fielif (code <=0xf ) code +=BTN_JOYSTICK ;else - code +=BTN_TRIGGER_HAPPY -0x10 ;
drivers/hid/hid-input.c static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel · line 775
Quoted 10 lines
drivers/hid/hid-input.c +7
-0+if (field->maxusage <=80 ) + code +=BTN_TRIGGER_HAPPY -0x10 ; +else +if (code <=0x2f ) + code +=KEY_MACRO1 -0x10 ; +else + code +=BTN_TRIGGER_HAPPY -0x30 ;break ;case HID_GD_GAMEPAD :if (code <=0xf )
As stated previously by Dmitry when I tried to increase the KEY_MAX for the same reason, the defined usages have their place and shouldn't be misused. I finally understood that and I have to say that this is just more confusing and a dirty hack, certainly used by some drivers because it still works with SDL and Wine (they only care about the usage index).
I'm working on a proper solution with a new event type that will only send button number (starting from 1 as does plain HID) and it's value.
This will support up to 65535 (u16) buttons and should be enough for years to come :D I'll make sure to CC you when I'll send RFC.
Quoted 18 lines · On Sat, Jan 03, 2026 at 08:26:55PM +0100, [email protected]…
Quoted 10 lines · Ivan Gorinov
This patch increases the limit from 80 to 112 key codes.
If a joystick has 80 or fewer buttons, mapping stays the same.
If a joystick has more than 80 buttons:
Map buttons [ 0 .. 15 ] to key codes starting with BTN_JOYSTICK; Map buttons [ 16 .. 47 ] to key codes starting with KEY_MACRO1; Map buttons [ 48 .. 111 ] to key codes starting with BTN_TRIGGER_HAPPY.As stated previously by Dmitry when I tried to increase the
KEY_MAXfor the same reason, the defined usages have their place and shouldn't be misused. I finally understood that and I have to say that this is just more confusing and a dirty hack, certainly used by some drivers because it still works with SDL and Wine (they only care about the usage index).
Quoted 5 lines
I'm working on a proper solution with a new event type that will only send button number (starting from 1 as does plain HID) and it's value.
This will support up to 65535 (u16) buttons and should be enough for years to come :D I'll make sure to CC you when I'll send RFC.
Thank you! I learned how to map more than 80 buttons by overriding function hid_driver.input_mapping from your contribution to JacKeTUs/universal-pdiff and used the same idea in my recent changes in the hid-winwing module.
Good luck in your work on new event type!
I will test your changes with my Orion2/TGRIP-18 combo.
Meanwhile, this patch could allow existing software (for example, X-Plane 12) to work with more input devices without any changes in userspace.