Skip to content

Commit

Permalink
Keyboard: Don't skip NONUS_POUND and CLEAR
Browse files Browse the repository at this point in the history
To be able to send NONUS_POUND and CLEAR keycodes, we need our report bitmap to
support them, and not mask them over with constants. These were originally
masked due to bugs in the Linux kernel: it treats NONUS_POUND the same as
BACKSLASH, and CLEAR the same as DELETE. There is no way for userland to
distinguish the two under Linux. But this is a linux-specific issue, one that is
not relevant when neither NONUS_POUND or CLEAR appear on the keymap. Linux will
happily accept a descriptor that does not mask this out (even ancient versions,
going back 13 years). It will not double-press if these appear in the report. At
worst, repeat will kick in faster if both BACKSLASH and NONUS_POUND are held at
the same time. However, other OSes may - and do - work differently, and some of
them handle NONUS_POUND separately from BACKSLASH.

Because not masking out these keys in the report causes no issues under
Linux (the only reason for the mask) unless the keys are in the report, and even
then, the issue is not critical, we should not punish other operating systems.
Linux has had this issue for at least 13 years (7 for CLEAR/DELETE). Changing it
would require changes to the kernel and a whole lot of userland too. I do not
see that happening in my lifetime, and that's even more reason for not waiting
for Linux to get rid of the bug before changing the descriptors.

Therefore, this patch removes the mask, and only the first four bits remain
masked. Therefore, operating systems that can treat NONUS_POUND and CLEAR
separately from BACKSLASH and DELETE will be able to do that, and Linux will not
be severely impacted either. And we also save a few bytes.

Fixes #273.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
  • Loading branch information
algernon committed Dec 21, 2017
1 parent 993cef1 commit e1388f5
Showing 1 changed file with 5 additions and 43 deletions.
48 changes: 5 additions & 43 deletions plugins/KeyboardioHID/src/MultiReport/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,62 +51,24 @@ static const uint8_t _hidMultiReportDescriptorKeyboard[] PROGMEM = {
D_REPORT_SIZE, 0x01,
D_OUTPUT, (D_DATA | D_VARIABLE | D_ABSOLUTE),

// USB Code not within 4-49 (0x4-0x31), 51-155 (0x33-0x9B), 157-164 (0x9D-0xA4),
// 176-221 (0xB0-0xDD) or 224-231 (0xE0-0xE7) NKRO Mode
/* NKRO Keyboard */
D_USAGE_PAGE, D_PAGE_KEYBOARD,

// Padding 3 bits
// To skip HID_KEYBOARD_NON_US_POUND_AND_TILDE, which causes
// Linux to choke on our driver.
// Padding 4 bits, to skip NO_EVENT & 3 error states.
D_REPORT_SIZE, 0x04,
D_REPORT_COUNT, 0x01,
D_INPUT, (D_CONSTANT),


D_USAGE_MINIMUM, HID_KEYBOARD_A_AND_A,
D_USAGE_MAXIMUM, HID_KEYBOARD_BACKSLASH_AND_PIPE,
D_LOGICAL_MINIMUM, 0x00,
D_LOGICAL_MAXIMUM, 0x01,
D_REPORT_SIZE, 0x01,
D_REPORT_COUNT, (HID_KEYBOARD_BACKSLASH_AND_PIPE - HID_KEYBOARD_A_AND_A)+1,
D_INPUT, (D_DATA|D_VARIABLE|D_ABSOLUTE),

// Padding 1 bit.
// To skip HID_KEYBOARD_NON_US_POUND_AND_TILDE, which causes
// Linux to choke on our driver.
D_REPORT_SIZE, 0x01,
D_REPORT_COUNT, 0x01,
D_INPUT, (D_CONSTANT),


D_USAGE_MINIMUM, HID_KEYBOARD_SEMICOLON_AND_COLON,
D_USAGE_MAXIMUM, HID_KEYBOARD_CANCEL,
D_USAGE_MAXIMUM, HID_LAST_KEY,
D_LOGICAL_MINIMUM, 0x00,
D_LOGICAL_MAXIMUM, 0x01,
D_REPORT_SIZE, 0x01,
D_REPORT_COUNT, (HID_KEYBOARD_CANCEL-HID_KEYBOARD_SEMICOLON_AND_COLON) +1,
D_REPORT_COUNT, (HID_LAST_KEY - HID_KEYBOARD_A_AND_A),
D_INPUT, (D_DATA|D_VARIABLE|D_ABSOLUTE),


// Padding 1 bit.
// To skip HID_KEYBOARD_CLEAR, which causes
// Linux to choke on our driver.
D_REPORT_SIZE, 0x01,
D_REPORT_COUNT, 0x01,
D_INPUT, (D_CONSTANT),

D_USAGE_MINIMUM, HID_KEYBOARD_PRIOR,
D_USAGE_MAXIMUM, HID_KEYPAD_HEXADECIMAL,
D_LOGICAL_MINIMUM, 0x00,
D_LOGICAL_MAXIMUM, 0x01,
D_REPORT_SIZE, 0x01,
D_REPORT_COUNT, (HID_KEYPAD_HEXADECIMAL - HID_KEYBOARD_PRIOR) +1,
D_INPUT, (D_DATA|D_VARIABLE|D_ABSOLUTE),


// Padding (w bits)
D_REPORT_SIZE, 0x02,
// Padding (3 bits) to round up the report to byte boundary.
D_REPORT_SIZE, 0x03,
D_REPORT_COUNT, 0x01,
D_INPUT, (D_CONSTANT),

Expand Down

0 comments on commit e1388f5

Please sign in to comment.