aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2020-06-07 15:00:59 +1000
committerJames Young <18669334+noroadsleft@users.noreply.github.com>2020-08-29 14:30:02 -0700
commit1193e45bf4c8c69e33c054c6eb3d545d5d52fcb5 (patch)
tree59559e7ee2f6e5e88b3d6621e0b95b25f9664953 /tmk_core
parentf209f91c7ce073aa0381e79c10219616cb7db523 (diff)
downloadqmk_firmware-1193e45bf4c8c69e33c054c6eb3d545d5d52fcb5.tar.gz
qmk_firmware-1193e45bf4c8c69e33c054c6eb3d545d5d52fcb5.zip
Convert `CONSUMER2BLUEFRUIT()` and `CONSUMER2RN42()` macros to static inline functions (#9055)
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/common/report.h7
-rw-r--r--tmk_core/protocol/lufa/bluetooth.h98
-rw-r--r--tmk_core/protocol/lufa/lufa.c2
3 files changed, 79 insertions, 28 deletions
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index c2b1b7c71..1b2f13bdd 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -46,8 +46,9 @@ enum mouse_buttons {
46 * See https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf#page=75 46 * See https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf#page=75
47 */ 47 */
48enum consumer_usages { 48enum consumer_usages {
49 // 15.5 Display Controls (https://www.usb.org/sites/default/files/hutrr41_0.pdf) 49 // 15.5 Display Controls
50 BRIGHTNESS_UP = 0x06F, 50 SNAPSHOT = 0x065,
51 BRIGHTNESS_UP = 0x06F, // https://www.usb.org/sites/default/files/hutrr41_0.pdf
51 BRIGHTNESS_DOWN = 0x070, 52 BRIGHTNESS_DOWN = 0x070,
52 // 15.7 Transport Controls 53 // 15.7 Transport Controls
53 TRANSPORT_RECORD = 0x0B2, 54 TRANSPORT_RECORD = 0x0B2,
@@ -57,6 +58,7 @@ enum consumer_usages {
57 TRANSPORT_PREV_TRACK = 0x0B6, 58 TRANSPORT_PREV_TRACK = 0x0B6,
58 TRANSPORT_STOP = 0x0B7, 59 TRANSPORT_STOP = 0x0B7,
59 TRANSPORT_EJECT = 0x0B8, 60 TRANSPORT_EJECT = 0x0B8,
61 TRANSPORT_RANDOM_PLAY = 0x0B9,
60 TRANSPORT_STOP_EJECT = 0x0CC, 62 TRANSPORT_STOP_EJECT = 0x0CC,
61 TRANSPORT_PLAY_PAUSE = 0x0CD, 63 TRANSPORT_PLAY_PAUSE = 0x0CD,
62 // 15.9.1 Audio Controls - Volume 64 // 15.9.1 Audio Controls - Volume
@@ -71,6 +73,7 @@ enum consumer_usages {
71 AL_LOCK = 0x19E, 73 AL_LOCK = 0x19E,
72 AL_CONTROL_PANEL = 0x19F, 74 AL_CONTROL_PANEL = 0x19F,
73 AL_ASSISTANT = 0x1CB, 75 AL_ASSISTANT = 0x1CB,
76 AL_KEYBOARD_LAYOUT = 0x1AE,
74 // 15.16 Generic GUI Application Controls 77 // 15.16 Generic GUI Application Controls
75 AC_MINIMIZE = 0x206, 78 AC_MINIMIZE = 0x206,
76 AC_SEARCH = 0x221, 79 AC_SEARCH = 0x221,
diff --git a/tmk_core/protocol/lufa/bluetooth.h b/tmk_core/protocol/lufa/bluetooth.h
index 081271a4e..67f031439 100644
--- a/tmk_core/protocol/lufa/bluetooth.h
+++ b/tmk_core/protocol/lufa/bluetooth.h
@@ -15,34 +15,82 @@ You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#ifndef BLUETOOTH_H 18#pragma once
19#define BLUETOOTH_H
20 19
21#include "../serial.h" 20#include "../serial.h"
22 21
23void bluefruit_serial_send(uint8_t data); 22void bluefruit_serial_send(uint8_t data);
24 23
25/* 24// https://learn.adafruit.com/introducing-bluefruit-ez-key-diy-bluetooth-hid-keyboard/sending-keys-via-serial#raw-hid-consumer-reports-8-14
26+-----------------+-------------------+-------+ 25static inline uint16_t CONSUMER2BLUEFRUIT(uint16_t usage) {
27| Consumer Key | Bit Map | Hex | 26 switch (usage) {
28+-----------------+-------------------+-------+ 27 case AC_HOME:
29| Home | 00000001 00000000 | 01 00 | 28 return 0x0001;
30| KeyboardLayout | 00000010 00000000 | 02 00 | 29 case AL_KEYBOARD_LAYOUT:
31| Search | 00000100 00000000 | 04 00 | 30 return 0x0002;
32| Snapshot | 00001000 00000000 | 08 00 | 31 case AC_SEARCH:
33| VolumeUp | 00010000 00000000 | 10 00 | 32 return 0x0004;
34| VolumeDown | 00100000 00000000 | 20 00 | 33 case SNAPSHOT:
35| Play/Pause | 01000000 00000000 | 40 00 | 34 return 0x0008;
36| Fast Forward | 10000000 00000000 | 80 00 | 35 case AUDIO_VOL_UP:
37| Rewind | 00000000 00000001 | 00 01 | 36 return 0x0010;
38| Scan Next Track | 00000000 00000010 | 00 02 | 37 case AUDIO_VOL_DOWN:
39| Scan Prev Track | 00000000 00000100 | 00 04 | 38 return 0x0020;
40| Random Play | 00000000 00001000 | 00 08 | 39 case TRANSPORT_PLAY_PAUSE:
41| Stop | 00000000 00010000 | 00 10 | 40 return 0x0040;
42+-------------------------------------+-------+ 41 case TRANSPORT_FAST_FORWARD:
43*/ 42 return 0x0080;
44#define CONSUMER2BLUEFRUIT(usage) (usage == AUDIO_MUTE ? 0x0000 : (usage == AUDIO_VOL_UP ? 0x1000 : (usage == AUDIO_VOL_DOWN ? 0x2000 : (usage == TRANSPORT_NEXT_TRACK ? 0x0002 : (usage == TRANSPORT_PREV_TRACK ? 0x0004 : (usage == TRANSPORT_STOP ? 0x0010 : (usage == TRANSPORT_STOP_EJECT ? 0x0000 : (usage == TRANSPORT_PLAY_PAUSE ? 0x4000 : (usage == AL_CC_CONFIG ? 0x0000 : (usage == AL_EMAIL ? 0x0000 : (usage == AL_CALCULATOR ? 0x0000 : (usage == AL_LOCAL_BROWSER ? 0x0000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : (usage == AC_BACK ? 0x0000 : (usage == AC_FORWARD ? 0x0000 : (usage == AC_STOP ? 0x0000 : (usage == AC_REFRESH ? 0x0000 : (usage == AC_BOOKMARKS ? 0x0000 : 0))))))))))))))))))) 43 case TRANSPORT_REWIND:
45 44 return 0x0100;
46#define CONSUMER2RN42(usage) (usage == AUDIO_MUTE ? 0x0040 : (usage == AUDIO_VOL_UP ? 0x0010 : (usage == AUDIO_VOL_DOWN ? 0x0020 : (usage == TRANSPORT_NEXT_TRACK ? 0x0100 : (usage == TRANSPORT_PREV_TRACK ? 0x0200 : (usage == TRANSPORT_STOP ? 0x0400 : (usage == TRANSPORT_STOP_EJECT ? 0x0800 : (usage == TRANSPORT_PLAY_PAUSE ? 0x0080 : (usage == AL_EMAIL ? 0x0200 : (usage == AL_LOCAL_BROWSER ? 0x8000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : 0)))))))))))) 45 case TRANSPORT_NEXT_TRACK:
46 return 0x0200;
47 case TRANSPORT_PREV_TRACK:
48 return 0x0400;
49 case TRANSPORT_RANDOM_PLAY:
50 return 0x0800;
51 case TRANSPORT_STOP:
52 return 0x1000;
53 default:
54 return 0;
55 }
56}
47 57
48#endif 58// https://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/bluetooth_cr_UG-v1.0r.pdf#G7.663734
59static inline uint16_t CONSUMER2RN42(uint16_t usage) {
60 switch (usage) {
61 case AC_HOME:
62 return 0x0001;
63 case AL_EMAIL:
64 return 0x0002;
65 case AC_SEARCH:
66 return 0x0004;
67 case AL_KEYBOARD_LAYOUT:
68 return 0x0008;
69 case AUDIO_VOL_UP:
70 return 0x0010;
71 case AUDIO_VOL_DOWN:
72 return 0x0020;
73 case AUDIO_MUTE:
74 return 0x0040;
75 case TRANSPORT_PLAY_PAUSE:
76 return 0x0080;
77 case TRANSPORT_NEXT_TRACK:
78 return 0x0100;
79 case TRANSPORT_PREV_TRACK:
80 return 0x0200;
81 case TRANSPORT_STOP:
82 return 0x0400;
83 case TRANSPORT_EJECT:
84 return 0x0800;
85 case TRANSPORT_FAST_FORWARD:
86 return 0x1000;
87 case TRANSPORT_REWIND:
88 return 0x2000;
89 case TRANSPORT_STOP_EJECT:
90 return 0x4000;
91 case AL_LOCAL_BROWSER:
92 return 0x8000;
93 default:
94 return 0;
95 }
96}
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 19f417770..3ca1a809d 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -720,8 +720,8 @@ static void send_consumer(uint16_t data) {
720 bluefruit_serial_send(0xFD); 720 bluefruit_serial_send(0xFD);
721 bluefruit_serial_send(0x00); 721 bluefruit_serial_send(0x00);
722 bluefruit_serial_send(0x02); 722 bluefruit_serial_send(0x02);
723 bluefruit_serial_send((bitmap >> 8) & 0xFF);
724 bluefruit_serial_send(bitmap & 0xFF); 723 bluefruit_serial_send(bitmap & 0xFF);
724 bluefruit_serial_send((bitmap >> 8) & 0xFF);
725 bluefruit_serial_send(0x00); 725 bluefruit_serial_send(0x00);
726 bluefruit_serial_send(0x00); 726 bluefruit_serial_send(0x00);
727 bluefruit_serial_send(0x00); 727 bluefruit_serial_send(0x00);