Skip to content

Commit

Permalink
Added support for Apple FN key qmk#2179
Browse files Browse the repository at this point in the history
  • Loading branch information
dkjer committed Jan 21, 2021
1 parent 111eb89 commit ccf9eac
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 1 deletion.
4 changes: 4 additions & 0 deletions common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,7 @@ endif
ifeq ($(strip $(JOYSTICK_ENABLE)), digital)
OPT_DEFS += -DDIGITAL_JOYSTICK_ENABLE
endif

ifeq ($(strip $(APPLE_FN_ENABLE)), yes)
OPT_DEFS += -DAPPLE_FN_ENABLE
endif
5 changes: 5 additions & 0 deletions quantum/keymap_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ action_t action_for_key(uint8_t layer, keypos_t key) {
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
break;
#endif
#ifdef APPLE_FN_ENABLE
case KC_APPLE_FN:
action.code = ACTION_APPLE_FN();
break;
#endif
#ifdef MOUSEKEY_ENABLE
case KC_MS_UP ... KC_MS_ACCEL2:
action.code = ACTION_MOUSEKEY(keycode);
Expand Down
25 changes: 25 additions & 0 deletions tmk_core/common/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,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 @@ -863,6 +873,12 @@ void register_code(uint8_t code) {
else if
IS_CONSUMER(code) { host_consumer_send(KEYCODE2CONSUMER(code)); }
#endif
#ifdef APPLE_FN_ENABLE
else if IS_APPLE_FN(code) {
add_key(code);
send_keyboard_report();
}
#endif
#ifdef MOUSEKEY_ENABLE
else if
IS_MOUSEKEY(code) {
Expand Down Expand Up @@ -927,6 +943,12 @@ void unregister_code(uint8_t code) {
IS_SYSTEM(code) { host_system_send(0); }
else if
IS_CONSUMER(code) { host_consumer_send(0); }
#ifdef APPLE_FN_ENABLE
else if IS_APPLE_FN(code) {
del_key(code);
send_keyboard_report();
}
#endif
#ifdef MOUSEKEY_ENABLE
else if
IS_MOUSEKEY(code) {
Expand Down Expand Up @@ -1110,6 +1132,9 @@ void debug_action(action_t action) {
case ACT_USAGE:
dprint("ACT_USAGE");
break;
case ACT_APPLE_FN:
dprint("ACT_APPLE_FN");
break;
case ACT_MOUSEKEY:
dprint("ACT_MOUSEKEY");
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 @@ -106,6 +107,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_MODS = 0b1001,
Expand Down Expand Up @@ -216,6 +219,7 @@ enum mods_codes {
enum usage_pages { PAGE_SYSTEM, PAGE_CONSUMER };
#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)

/** \brief Layer Actions
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 @@ -191,6 +192,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 @@ -484,6 +488,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 @@ -231,6 +231,12 @@ void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code) {
* FIXME: Needs doc
*/
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 @@ -245,6 +251,12 @@ void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key) {
* FIXME: Needs doc
*/
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
12 changes: 12 additions & 0 deletions tmk_core/protocol/usb_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,22 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = {
HID_RI_REPORT_COUNT(8, 0x08),
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
// Reserved (1 byte)
HID_RI_REPORT_COUNT(8, 0x01),
HID_RI_REPORT_SIZE(8, 0x08),
HID_RI_INPUT(8, HID_IOF_CONSTANT),
#endif

// Keycodes (6 bytes)
HID_RI_USAGE_PAGE(8, 0x07), // Keyboard/Keypad
HID_RI_USAGE_MINIMUM(8, 0x00),
Expand Down
12 changes: 12 additions & 0 deletions tmk_core/protocol/vusb/vusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,22 @@ const PROGMEM uchar keyboard_hid_report[] = {
0x95, 0x08, // Report Count (8)
0x75, 0x01, // Report Size (1)
0x81, 0x02, // Input (Data, Variable, Absolute)

#ifdef APPLE_FN_ENABLE
0x05, 0xFF, // Usage Page (AppleVendor Top Case)
0x09, 0x03, // Usage (KeyboardFn)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x95, 0x01, // Report Count (1)
0x75, 0x08, // Report Size (8)
0x81, 0x02, // Input (Data, Variable, Absolute)
#else
// Reserved (1 byte)
0x95, 0x01, // Report Count (1)
0x75, 0x08, // Report Size (8)
0x81, 0x03, // Input (Constant)
#endif

// Keycodes (6 bytes)
0x05, 0x07, // Usage Page (Keyboard/Keypad)
0x19, 0x00, // Usage Minimum (0)
Expand Down

0 comments on commit ccf9eac

Please sign in to comment.