Skip to content

Commit

Permalink
Add Apple Vendor patch
Browse files Browse the repository at this point in the history
  • Loading branch information
caius committed Jul 19, 2019
1 parent b1fc3f3 commit f5eded8
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 1 deletion.
3 changes: 3 additions & 0 deletions quantum/keymap_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ action_t action_for_key(uint8_t layer, keypos_t key)
case KC_AUDIO_MUTE ... KC_BRIGHTNESS_DOWN:
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
break;
case KC_APPLE_FN:
action.code = ACTION_APPLE_FN();
break;
case KC_MS_UP ... KC_MS_ACCEL2:
action.code = ACTION_MOUSEKEY(keycode);
break;
Expand Down
4 changes: 4 additions & 0 deletions tmk_core/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ ifeq ($(strip $(EXTRAKEY_ENABLE)), yes)
SHARED_EP_ENABLE = yes
endif

ifeq ($(strip $(APPLE_FN_ENABLE)), yes)
TMK_COMMON_DEFS += -DAPPLE_FN_ENABLE
endif

ifeq ($(strip $(RAW_ENABLE)), yes)
TMK_COMMON_DEFS += -DRAW_ENABLE
endif
Expand Down
20 changes: 20 additions & 0 deletions tmk_core/common/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,16 @@ void process_action(keyrecord_t *record, action_t action)
}
break;
#endif
#ifdef APPLE_FN_ENABLE
/* Apple Fn */
case ACT_APPLE_FN:
if (event.pressed) {
register_code(KC_APPLE_FN);
} else {
unregister_code(KC_APPLE_FN);
}
break;
#endif
#ifdef MOUSEKEY_ENABLE
/* Mouse key */
case ACT_MOUSEKEY:
Expand Down Expand Up @@ -776,6 +786,10 @@ void register_code(uint8_t code)
else if IS_CONSUMER(code) {
host_consumer_send(KEYCODE2CONSUMER(code));
}
else if IS_APPLE_FN(code) {
add_key(code);
send_keyboard_report();
}

#ifdef MOUSEKEY_ENABLE
else if IS_MOUSEKEY(code) {
Expand Down Expand Up @@ -842,6 +856,11 @@ void unregister_code(uint8_t code)
else if IS_CONSUMER(code) {
host_consumer_send(0);
}
else if IS_APPLE_FN(code) {
del_key(code);
send_keyboard_report();
}

#ifdef MOUSEKEY_ENABLE
else if IS_MOUSEKEY(code) {
mousekey_off(code);
Expand Down Expand Up @@ -1007,6 +1026,7 @@ void debug_action(action_t action)
case ACT_LMODS_TAP: dprint("ACT_LMODS_TAP"); break;
case ACT_RMODS_TAP: dprint("ACT_RMODS_TAP"); break;
case ACT_USAGE: dprint("ACT_USAGE"); break;
case ACT_APPLE_FN: dprint("ACT_APPLE_FN"); break;
case ACT_MOUSEKEY: dprint("ACT_MOUSEKEY"); break;
case ACT_LAYER: dprint("ACT_LAYER"); break;
case ACT_LAYER_TAP: dprint("ACT_LAYER_TAP"); break;
Expand Down
6 changes: 5 additions & 1 deletion tmk_core/common/action_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* ACT_SWAP_HANDS(0110):
* 0110|xxxx| keycode Swap hands (keycode on tap, or options)
*
* 0111|xxxx xxxx xxxx (reserved)
* ACT_APPLE_FN(0111):
* 0111|0000|0000|0000 Apple Fn
*
* Layer Actions(10xx)
* -------------------
Expand Down Expand Up @@ -108,6 +109,8 @@ enum action_kind_id {
ACT_MOUSEKEY = 0b0101,
/* One-hand Support */
ACT_SWAP_HANDS = 0b0110,
/* Apple Fn */
ACT_APPLE_FN = 0b0111,
/* Layer Actions */
ACT_LAYER = 0b1000,
ACT_LAYER_TAP = 0b1010, /* Layer 0-15 */
Expand Down Expand Up @@ -231,6 +234,7 @@ enum usage_pages {
};
#define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM<<10 | (id))
#define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER<<10 | (id))
#define ACTION_APPLE_FN() ACTION(ACT_APPLE_FN, 0)
#define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key)


Expand Down
7 changes: 7 additions & 0 deletions tmk_core/common/keycode.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF))
#define IS_SYSTEM(code) (KC_PWR <= (code) && (code) <= KC_WAKE)
#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_BRID)
#define IS_APPLE_FN(code) (KC_APFN == (code))

#define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31)

Expand Down Expand Up @@ -190,6 +191,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define KC_BRIU KC_BRIGHTNESS_UP
#define KC_BRID KC_BRIGHTNESS_DOWN

/* Apple Fn */
#define KC_APFN KC_APPLE_FN

/* System Specific */
#define KC_BRMU KC_PAUSE
#define KC_BRMD KC_SCROLLLOCK
Expand Down Expand Up @@ -483,6 +487,9 @@ enum internal_special_keycodes {
KC_BRIGHTNESS_UP,
KC_BRIGHTNESS_DOWN,

/* Apple Fn */
KC_APPLE_FN,

/* Fn keys */
KC_FN0 = 0xC0,
KC_FN1,
Expand Down
12 changes: 12 additions & 0 deletions tmk_core/common/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code)
*/
void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key)
{
#ifdef APPLE_FN_ENABLE
if IS_APPLE_FN(key) {
keyboard_report->reserved = 1;
return;
}
#endif
#ifdef NKRO_ENABLE
if (keyboard_protocol && keymap_config.nkro) {
add_key_bit(keyboard_report, key);
Expand All @@ -230,6 +236,12 @@ void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key)
*/
void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key)
{
#ifdef APPLE_FN_ENABLE
if IS_APPLE_FN(key) {
keyboard_report->reserved = 0;
return;
}
#endif
#ifdef NKRO_ENABLE
if (keyboard_protocol && keymap_config.nkro) {
del_key_bit(keyboard_report, key);
Expand Down
10 changes: 10 additions & 0 deletions tmk_core/protocol/usb_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,19 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = {
HID_RI_REPORT_SIZE(8, 0x01),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),

#ifdef APPLE_FN_ENABLE
HID_RI_USAGE_PAGE(8, 0xFF), /* AppleVendor Top Case */
HID_RI_USAGE(8, 0x03), /* KeyboardFn */
HID_RI_LOGICAL_MINIMUM(8, 0x00),
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
HID_RI_REPORT_COUNT(8, 0x01),
HID_RI_REPORT_SIZE(8, 0x08),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
#else
HID_RI_REPORT_COUNT(8, 0x01),
HID_RI_REPORT_SIZE(8, 0x08),
HID_RI_INPUT(8, HID_IOF_CONSTANT), /* reserved */
#endif

HID_RI_USAGE_PAGE(8, 0x08), /* LEDs */
HID_RI_USAGE_MINIMUM(8, 0x01), /* Num Lock */
Expand Down

0 comments on commit f5eded8

Please sign in to comment.