summaryrefslogtreecommitdiff
path: root/tmk_core/protocol
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/protocol
parentf209f91c7ce073aa0381e79c10219616cb7db523 (diff)
Convert `CONSUMER2BLUEFRUIT()` and `CONSUMER2RN42()` macros to static inline functions (#9055)
Diffstat (limited to 'tmk_core/protocol')
-rw-r--r--tmk_core/protocol/lufa/bluetooth.h98
-rw-r--r--tmk_core/protocol/lufa/lufa.c2
2 files changed, 74 insertions, 26 deletions
diff --git a/tmk_core/protocol/lufa/bluetooth.h b/tmk_core/protocol/lufa/bluetooth.h
index 081271a4e6..67f031439e 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
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef BLUETOOTH_H
-#define BLUETOOTH_H
+#pragma once
#include "../serial.h"
void bluefruit_serial_send(uint8_t data);
-/*
-+-----------------+-------------------+-------+
-| Consumer Key | Bit Map | Hex |
-+-----------------+-------------------+-------+
-| Home | 00000001 00000000 | 01 00 |
-| KeyboardLayout | 00000010 00000000 | 02 00 |
-| Search | 00000100 00000000 | 04 00 |
-| Snapshot | 00001000 00000000 | 08 00 |
-| VolumeUp | 00010000 00000000 | 10 00 |
-| VolumeDown | 00100000 00000000 | 20 00 |
-| Play/Pause | 01000000 00000000 | 40 00 |
-| Fast Forward | 10000000 00000000 | 80 00 |
-| Rewind | 00000000 00000001 | 00 01 |
-| Scan Next Track | 00000000 00000010 | 00 02 |
-| Scan Prev Track | 00000000 00000100 | 00 04 |
-| Random Play | 00000000 00001000 | 00 08 |
-| Stop | 00000000 00010000 | 00 10 |
-+-------------------------------------+-------+
-*/
-#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)))))))))))))))))))
-
-#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))))))))))))
+// https://learn.adafruit.com/introducing-bluefruit-ez-key-diy-bluetooth-hid-keyboard/sending-keys-via-serial#raw-hid-consumer-reports-8-14
+static inline uint16_t CONSUMER2BLUEFRUIT(uint16_t usage) {
+ switch (usage) {
+ case AC_HOME:
+ return 0x0001;
+ case AL_KEYBOARD_LAYOUT:
+ return 0x0002;
+ case AC_SEARCH:
+ return 0x0004;
+ case SNAPSHOT:
+ return 0x0008;
+ case AUDIO_VOL_UP:
+ return 0x0010;
+ case AUDIO_VOL_DOWN:
+ return 0x0020;
+ case TRANSPORT_PLAY_PAUSE:
+ return 0x0040;
+ case TRANSPORT_FAST_FORWARD:
+ return 0x0080;
+ case TRANSPORT_REWIND:
+ return 0x0100;
+ case TRANSPORT_NEXT_TRACK:
+ return 0x0200;
+ case TRANSPORT_PREV_TRACK:
+ return 0x0400;
+ case TRANSPORT_RANDOM_PLAY:
+ return 0x0800;
+ case TRANSPORT_STOP:
+ return 0x1000;
+ default:
+ return 0;
+ }
+}
-#endif
+// https://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/bluetooth_cr_UG-v1.0r.pdf#G7.663734
+static inline uint16_t CONSUMER2RN42(uint16_t usage) {
+ switch (usage) {
+ case AC_HOME:
+ return 0x0001;
+ case AL_EMAIL:
+ return 0x0002;
+ case AC_SEARCH:
+ return 0x0004;
+ case AL_KEYBOARD_LAYOUT:
+ return 0x0008;
+ case AUDIO_VOL_UP:
+ return 0x0010;
+ case AUDIO_VOL_DOWN:
+ return 0x0020;
+ case AUDIO_MUTE:
+ return 0x0040;
+ case TRANSPORT_PLAY_PAUSE:
+ return 0x0080;
+ case TRANSPORT_NEXT_TRACK:
+ return 0x0100;
+ case TRANSPORT_PREV_TRACK:
+ return 0x0200;
+ case TRANSPORT_STOP:
+ return 0x0400;
+ case TRANSPORT_EJECT:
+ return 0x0800;
+ case TRANSPORT_FAST_FORWARD:
+ return 0x1000;
+ case TRANSPORT_REWIND:
+ return 0x2000;
+ case TRANSPORT_STOP_EJECT:
+ return 0x4000;
+ case AL_LOCAL_BROWSER:
+ return 0x8000;
+ default:
+ return 0;
+ }
+}
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 19f417770f..3ca1a809d1 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) {
bluefruit_serial_send(0xFD);
bluefruit_serial_send(0x00);
bluefruit_serial_send(0x02);
- bluefruit_serial_send((bitmap >> 8) & 0xFF);
bluefruit_serial_send(bitmap & 0xFF);
+ bluefruit_serial_send((bitmap >> 8) & 0xFF);
bluefruit_serial_send(0x00);
bluefruit_serial_send(0x00);
bluefruit_serial_send(0x00);