Skip to content

Commit

Permalink
usb_hid: Fix handling for Apple Magic Keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
tmk committed Mar 27, 2020
1 parent fdac009 commit 7915990
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions tmk_core/protocol/usb_hid/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,30 @@ void KBDReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *b
}
xprintf("\r\n");

// Apple USB Magic keyboard (Model A1644) (buf[1] == 0x01) has mods byte in buf[1] while buf[0] is always 0x01:
// input 1: 01 00 00 00 00 00 00 00 00 01
// It has 8 key input bytes instead of the usual 6
// buf[9] on magic keyboard:
// 0x01: eject key (top right next key to F12) pressed
// 0x02: fn key (bottom left key) pressed
// 0x03: fn and eject key pressed at the same time
// we store buf[9] in buf[1] (reserved byte)
// and map eject and fn to F23 and F24
// Apple USB Magic keyboard (Model A1644)
// USB Descriptor: // https://gist.github.com/tmk/0626b78f73575d5c1efa86470c4cdb18
//
// 01 00 00 00 00 00 00 00 00 00
//
// buf[0] Report ID:1
// buf[1] Modifiers
// buf[2] Reserve
// buf[3-8] Keys
// buf[9] eject and fn
// 0x01: eject key (top right next key to F12) pressed
// 0x02: fn key (bottom left key) pressed
// 0x03: fn and eject key pressed at the same time
if (buf[0] == 0x01 && len == 10) {
uint8_t t = buf[0];
buf[0] = buf[1];
buf[1] = buf[9];
buf[1] = buf[2];
buf[2] = buf[3];
buf[3] = buf[4];
buf[4] = buf[5];
buf[5] = buf[6];
buf[6] = buf[7];
buf[7] = buf[8];
// adhoc: Map eject and fn to F23 and F24
if (buf[9] & 0x01) buf[6] = KC_F23; // eject -> F23
if (buf[9] & 0x02) buf[7] = KC_F24; // Fn -> F24
}
Expand Down

0 comments on commit 7915990

Please sign in to comment.