Convert `CONSUMER2BLUEFRUIT()` and `CONSUMER2RN42()` macros to static inline functions (#9055)
This commit is contained in:
parent
f209f91c7c
commit
1193e45bf4
|
@ -46,8 +46,9 @@ enum mouse_buttons {
|
||||||
* See https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf#page=75
|
* See https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf#page=75
|
||||||
*/
|
*/
|
||||||
enum consumer_usages {
|
enum consumer_usages {
|
||||||
// 15.5 Display Controls (https://www.usb.org/sites/default/files/hutrr41_0.pdf)
|
// 15.5 Display Controls
|
||||||
BRIGHTNESS_UP = 0x06F,
|
SNAPSHOT = 0x065,
|
||||||
|
BRIGHTNESS_UP = 0x06F, // https://www.usb.org/sites/default/files/hutrr41_0.pdf
|
||||||
BRIGHTNESS_DOWN = 0x070,
|
BRIGHTNESS_DOWN = 0x070,
|
||||||
// 15.7 Transport Controls
|
// 15.7 Transport Controls
|
||||||
TRANSPORT_RECORD = 0x0B2,
|
TRANSPORT_RECORD = 0x0B2,
|
||||||
|
@ -57,6 +58,7 @@ enum consumer_usages {
|
||||||
TRANSPORT_PREV_TRACK = 0x0B6,
|
TRANSPORT_PREV_TRACK = 0x0B6,
|
||||||
TRANSPORT_STOP = 0x0B7,
|
TRANSPORT_STOP = 0x0B7,
|
||||||
TRANSPORT_EJECT = 0x0B8,
|
TRANSPORT_EJECT = 0x0B8,
|
||||||
|
TRANSPORT_RANDOM_PLAY = 0x0B9,
|
||||||
TRANSPORT_STOP_EJECT = 0x0CC,
|
TRANSPORT_STOP_EJECT = 0x0CC,
|
||||||
TRANSPORT_PLAY_PAUSE = 0x0CD,
|
TRANSPORT_PLAY_PAUSE = 0x0CD,
|
||||||
// 15.9.1 Audio Controls - Volume
|
// 15.9.1 Audio Controls - Volume
|
||||||
|
@ -71,6 +73,7 @@ enum consumer_usages {
|
||||||
AL_LOCK = 0x19E,
|
AL_LOCK = 0x19E,
|
||||||
AL_CONTROL_PANEL = 0x19F,
|
AL_CONTROL_PANEL = 0x19F,
|
||||||
AL_ASSISTANT = 0x1CB,
|
AL_ASSISTANT = 0x1CB,
|
||||||
|
AL_KEYBOARD_LAYOUT = 0x1AE,
|
||||||
// 15.16 Generic GUI Application Controls
|
// 15.16 Generic GUI Application Controls
|
||||||
AC_MINIMIZE = 0x206,
|
AC_MINIMIZE = 0x206,
|
||||||
AC_SEARCH = 0x221,
|
AC_SEARCH = 0x221,
|
||||||
|
|
|
@ -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/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef BLUETOOTH_H
|
#pragma once
|
||||||
#define BLUETOOTH_H
|
|
||||||
|
|
||||||
#include "../serial.h"
|
#include "../serial.h"
|
||||||
|
|
||||||
void bluefruit_serial_send(uint8_t data);
|
void bluefruit_serial_send(uint8_t data);
|
||||||
|
|
||||||
/*
|
// 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) {
|
||||||
| Consumer Key | Bit Map | Hex |
|
switch (usage) {
|
||||||
+-----------------+-------------------+-------+
|
case AC_HOME:
|
||||||
| Home | 00000001 00000000 | 01 00 |
|
return 0x0001;
|
||||||
| KeyboardLayout | 00000010 00000000 | 02 00 |
|
case AL_KEYBOARD_LAYOUT:
|
||||||
| Search | 00000100 00000000 | 04 00 |
|
return 0x0002;
|
||||||
| Snapshot | 00001000 00000000 | 08 00 |
|
case AC_SEARCH:
|
||||||
| VolumeUp | 00010000 00000000 | 10 00 |
|
return 0x0004;
|
||||||
| VolumeDown | 00100000 00000000 | 20 00 |
|
case SNAPSHOT:
|
||||||
| Play/Pause | 01000000 00000000 | 40 00 |
|
return 0x0008;
|
||||||
| Fast Forward | 10000000 00000000 | 80 00 |
|
case AUDIO_VOL_UP:
|
||||||
| Rewind | 00000000 00000001 | 00 01 |
|
return 0x0010;
|
||||||
| Scan Next Track | 00000000 00000010 | 00 02 |
|
case AUDIO_VOL_DOWN:
|
||||||
| Scan Prev Track | 00000000 00000100 | 00 04 |
|
return 0x0020;
|
||||||
| Random Play | 00000000 00001000 | 00 08 |
|
case TRANSPORT_PLAY_PAUSE:
|
||||||
| Stop | 00000000 00010000 | 00 10 |
|
return 0x0040;
|
||||||
+-------------------------------------+-------+
|
case TRANSPORT_FAST_FORWARD:
|
||||||
*/
|
return 0x0080;
|
||||||
#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)))))))))))))))))))
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#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://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/bluetooth_cr_UG-v1.0r.pdf#G7.663734
|
||||||
|
static inline uint16_t CONSUMER2RN42(uint16_t usage) {
|
||||||
#endif
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -720,8 +720,8 @@ static void send_consumer(uint16_t data) {
|
||||||
bluefruit_serial_send(0xFD);
|
bluefruit_serial_send(0xFD);
|
||||||
bluefruit_serial_send(0x00);
|
bluefruit_serial_send(0x00);
|
||||||
bluefruit_serial_send(0x02);
|
bluefruit_serial_send(0x02);
|
||||||
bluefruit_serial_send((bitmap >> 8) & 0xFF);
|
|
||||||
bluefruit_serial_send(bitmap & 0xFF);
|
bluefruit_serial_send(bitmap & 0xFF);
|
||||||
|
bluefruit_serial_send((bitmap >> 8) & 0xFF);
|
||||||
bluefruit_serial_send(0x00);
|
bluefruit_serial_send(0x00);
|
||||||
bluefruit_serial_send(0x00);
|
bluefruit_serial_send(0x00);
|
||||||
bluefruit_serial_send(0x00);
|
bluefruit_serial_send(0x00);
|
||||||
|
|
Loading…
Reference in New Issue