-
Notifications
You must be signed in to change notification settings - Fork 2
/
qmk_00_applefn.patch
220 lines (213 loc) · 9.35 KB
/
qmk_00_applefn.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk
index 0880934e95..e2ab76ecf3 100644
--- a/builddefs/common_features.mk
+++ b/builddefs/common_features.mk
@@ -859,6 +859,13 @@ ifeq ($(strip $(JOYSTICK_ENABLE)), yes)
endif
endif
+ifeq ($(strip $(APPLE_FN_ENABLE)), yes)
+ ifeq ($(strip $(EXTRAKEY_ENABLE)), no)
+ $(error APPLE_FN_ENABLE requires EXTRAKEY_ENABLE)
+ endif
+ OPT_DEFS += -DAPPLE_FN_ENABLE
+endif
+
USBPD_ENABLE ?= no
VALID_USBPD_DRIVER_TYPES = custom vendor
USBPD_DRIVER ?= vendor
diff --git a/drivers/bluetooth/bluetooth.c b/drivers/bluetooth/bluetooth.c
index d5382401e7..96e854ad5e 100644
--- a/drivers/bluetooth/bluetooth.c
+++ b/drivers/bluetooth/bluetooth.c
@@ -60,3 +60,7 @@ void bluetooth_send_consumer(uint16_t usage) {
rn42_send_consumer(usage);
#endif
}
+
+void bluetooth_send_apple(bool pressed, uint8_t usageIndex);
+// TODO not implemented yet
+}
diff --git a/drivers/bluetooth/bluetooth.h b/drivers/bluetooth/bluetooth.h
index 2e4d0df538..fa95a758f8 100644
--- a/drivers/bluetooth/bluetooth.h
+++ b/drivers/bluetooth/bluetooth.h
@@ -50,3 +50,5 @@ void bluetooth_send_mouse(report_mouse_t *report);
* \param usage The consumer usage to send.
*/
void bluetooth_send_consumer(uint16_t usage);
+
+void bluetooth_send_apple(bool pressed, uint8_t usageIndex);
diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c
index 2c6654e9a6..c0e0f35c1e 100644
--- a/tmk_core/protocol/host.c
+++ b/tmk_core/protocol/host.c
@@ -43,6 +43,7 @@ extern keymap_config_t keymap_config;
static host_driver_t *driver;
static uint16_t last_system_usage = 0;
static uint16_t last_consumer_usage = 0;
+static uint16_t last_apple_usages = 0;
void host_set_driver(host_driver_t *d) {
driver = d;
@@ -159,6 +160,28 @@ void host_consumer_send(uint16_t usage) {
(*driver->send_extra)(&report);
}
+void host_apple_send(bool pressed, uint8_t usageIndex) {
+ uint16_t usage_mask = 1 << usageIndex;
+ uint16_t usages = pressed ? (last_apple_usages | usage_mask) : (last_apple_usages & ~usage_mask);
+ if (usages == last_apple_usages) return;
+ last_apple_usages = usages;
+
+#ifdef BLUETOOTH_ENABLE
+ if (where_to_send() == OUTPUT_BLUETOOTH) {
+ bluetooth_send_apple_fn(pressed, usageIndex);
+ return;
+ }
+#endif
+
+ if (!driver) return;
+
+ report_extra_t report = {
+ .report_id = REPORT_ID_APPLE,
+ .usage = usages
+ };
+ (*driver->send_extra)(&report);
+}
+
#ifdef JOYSTICK_ENABLE
void host_joystick_send(joystick_t *joystick) {
if (!driver) return;
@@ -253,3 +276,7 @@ uint16_t host_last_system_usage(void) {
uint16_t host_last_consumer_usage(void) {
return last_consumer_usage;
}
+
+bool host_apple_is_pressed(uint16_t usage_mask) {
+ return (last_apple_usages & usage_mask) != 0;
+}
diff --git a/tmk_core/protocol/host.h b/tmk_core/protocol/host.h
index add408caf6..1cca92b2eb 100644
--- a/tmk_core/protocol/host.h
+++ b/tmk_core/protocol/host.h
@@ -44,10 +44,12 @@ void host_keyboard_send(report_keyboard_t *report);
void host_mouse_send(report_mouse_t *report);
void host_system_send(uint16_t usage);
void host_consumer_send(uint16_t usage);
+void host_apple_send(bool pressed, uint8_t usageIndex);
void host_programmable_button_send(uint32_t data);
uint16_t host_last_system_usage(void);
uint16_t host_last_consumer_usage(void);
+bool host_apple_is_pressed(uint16_t usage_mask);
#ifdef __cplusplus
}
diff --git a/tmk_core/protocol/report.h b/tmk_core/protocol/report.h
index 9d415a3bfd..3bf3bdff37 100644
--- a/tmk_core/protocol/report.h
+++ b/tmk_core/protocol/report.h
@@ -29,6 +29,7 @@ enum hid_report_ids {
REPORT_ID_MOUSE,
REPORT_ID_SYSTEM,
REPORT_ID_CONSUMER,
+ REPORT_ID_APPLE,
REPORT_ID_PROGRAMMABLE_BUTTON,
REPORT_ID_NKRO,
REPORT_ID_JOYSTICK,
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c
index 5ab9e3ff4f..7b0ce20535 100644
--- a/tmk_core/protocol/usb_descriptor.c
+++ b/tmk_core/protocol/usb_descriptor.c
@@ -319,6 +319,46 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
HID_RI_REPORT_SIZE(8, 16),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
HID_RI_END_COLLECTION(0),
+
+# ifdef APPLE_FN_ENABLE
+ // see
+ // https://github.com/apple-oss-distributions/IOHIDFamily/blob/1ca71a23b43de09cb3968515586840eacf817445/IOHIDFamily/IOHIDEventDriver.cpp#L2342
+ // https://mybyways.com/blog/script-to-re-map-macbook-pro-function-keys
+ // https://github.com/pqrs-org/Karabiner-VirtualHIDDevice/blob/master/src/VirtualHIDKeyboard/VirtualHIDKeyboard.cpp
+ HID_RI_USAGE_PAGE(16, 0xff00), // Usage Page kHIDPage_AppleVendor)
+ HID_RI_USAGE(8, 0x01), // Usage 1
+ HID_RI_COLLECTION(8, 0x01), // Application
+ HID_RI_REPORT_ID(8, REPORT_ID_APPLE),
+ // AppleVebdorTopCasePage
+ HID_RI_USAGE_PAGE(8, 0xFF), // AppleVendor Top Case
+ HID_RI_LOGICAL_MINIMUM(8, 0x0),
+ HID_RI_LOGICAL_MAXIMUM(8, 0x1),
+ HID_RI_USAGE(8, 0x03), // 0 kHIDUsage_AV_TopCase_KeyboardFn
+ HID_RI_USAGE(8, 0x06), // 1 kHIDUsage_AV_TopCase_VideoMirror
+ HID_RI_USAGE(8, 0x0A), // 2 kHIDUsage_AV_TopCase_ClamshellLatched
+ HID_RI_REPORT_COUNT(8, 0x03),
+ HID_RI_REPORT_SIZE(8, 0x01),
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+ // AppleVebdorKeyboardPage
+ HID_RI_USAGE_PAGE(16, 0xFF01), // kHIDPage_AppleVendorKeyboard
+ HID_RI_LOGICAL_MINIMUM(8, 0x0),
+ HID_RI_LOGICAL_MAXIMUM(8, 0x1),
+ HID_RI_USAGE(8, 0x01), // 3 kHIDUsage_AppleVendorKeyboard_Spotlight
+ HID_RI_USAGE(8, 0x02), // 4 kHIDUsage_AppleVendorKeyboard_Dashboard
+ HID_RI_USAGE(8, 0x03), // 5 kHIDUsage_AppleVendorKeyboard_Function
+ HID_RI_USAGE(8, 0x04), // 6 kHIDUsage_AppleVendorKeyboard_Launchpad
+ HID_RI_USAGE(8, 0x10), // 7 kHIDUsage_AppleVendorKeyboard_Expose_All
+ HID_RI_USAGE(8, 0x11), // 8 kHIDUsage_AppleVendorKeyboard_Expose_Desktop
+ HID_RI_USAGE(8, 0x30), // 9 kHIDUsage_AppleVendorKeyboard_Language
+ HID_RI_REPORT_COUNT(8, 0x07),
+ HID_RI_REPORT_SIZE(8, 0x01),
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+ // Reserved (6bits)
+ HID_RI_REPORT_COUNT(8, 0x06),
+ HID_RI_REPORT_SIZE(8, 0x01),
+ HID_RI_INPUT(8, HID_IOF_CONSTANT),
+ HID_RI_END_COLLECTION(0),
+# endif
#endif
#ifdef PROGRAMMABLE_BUTTON_ENABLE
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index b3eeff9e01..743912bef2 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -540,6 +540,46 @@ const PROGMEM uchar shared_hid_report[] = {
0x75, 0x10, // Report Size (16)
0x81, 0x00, // Input (Data, Array, Absolute)
0xC0, // End Collection
+
+# ifdef APPLE_FN_ENABLE
+ // see
+ // https://github.com/apple-oss-distributions/IOHIDFamily/blob/1ca71a23b43de09cb3968515586840eacf817445/IOHIDFamily/IOHIDEventDriver.cpp#L2342
+ // https://mybyways.com/blog/script-to-re-map-macbook-pro-function-keys
+ // https://github.com/pqrs-org/Karabiner-VirtualHIDDevice/blob/master/src/VirtualHIDKeyboard/VirtualHIDKeyboard.cpp
+ 0x06, 0x00, 0xFF, // Usage Page (kHIDPage_AppleVendor)
+ 0x09, 0x01, // Usage 1
+ 0xA1, 0x01, // Collection (Application)
+ 0x85, REPORT_ID_APPLE, // Report ID
+ // Apple Vendor Top Case Page
+ 0x05, 0xFF, // Usage Page (AppleVendor Top Case)
+ 0x15, 0x00, // Logical Minimum (0)
+ 0x25, 0x01, // Logical Maximum (1)
+ 0x09, 0x03, // Usage (KeyboardFn) index 0
+ 0x09, 0x06, // Usage (VideoMirror) index 1
+ 0x09, 0x0A, // Usage (ClamshellLatched) index 2
+ 0x95, 0x03, // Report Count (3)
+ 0x75, 0x01, // Report Size (1)
+ 0x81, 0x02, // Input (Data, Variable, Absolute)
+ // Apple Vendor Keyboard Page
+ 0x06, 0x01, 0xFF, // Usage Page (kHIDPage_AppleVendorKeyboard)
+ 0x15, 0x00, // Logical Minimum (0)
+ 0x25, 0x01, // Logical Maximum (1)
+ 0x09, 0x01, // Usage (kHIDUsage_AppleVendorKeyboard_Spotlight) index 3
+ 0x09, 0x02, // Usage (kHIDUsage_AppleVendorKeyboard_Dashboard) index 4
+ 0x09, 0x03, // Usage (kHIDUsage_AppleVendorKeyboard_Function) index 5
+ 0x09, 0x04, // Usage (kHIDUsage_AppleVendorKeyboard_Launchpad) index 6
+ 0x09, 0x10, // Usage (kHIDUsage_AppleVendorKeyboard_Expose_All) index 7
+ 0x09, 0x11, // Usage (kHIDUsage_AppleVendorKeyboard_Expose_Desktop) index 8
+ 0x09, 0x30, // Usage (kHIDUsage_AppleVendorKeyboard_Expose_Language) index 9
+ 0x95, 0x07, // Report Count (7)
+ 0x75, 0x01, // Report Size (1)
+ 0x81, 0x02, // Input (Data, Variable, Absolute)
+ // Reserved (6bits)
+ 0x95, 0x06, // Report Count (6)
+ 0x75, 0x01, // Report Size (1)
+ 0x81, 0x03, // Input (Constant)
+ 0xC0, // End Collection
+# endif
#endif
#ifdef JOYSTICK_ENABLE