bluetooth.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. Bluefruit Protocol for TMK firmware
  3. Author: Benjamin Gould, 2013
  4. Jack Humbert, 2015
  5. Based on code Copyright 2011 Jun Wako <wakojun@gmail.com>
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #pragma once
  18. #include "../serial.h"
  19. void bluefruit_serial_send(uint8_t data);
  20. // https://learn.adafruit.com/introducing-bluefruit-ez-key-diy-bluetooth-hid-keyboard/sending-keys-via-serial#raw-hid-consumer-reports-8-14
  21. static inline uint16_t CONSUMER2BLUEFRUIT(uint16_t usage) {
  22. switch (usage) {
  23. case AC_HOME:
  24. return 0x0001;
  25. case AL_KEYBOARD_LAYOUT:
  26. return 0x0002;
  27. case AC_SEARCH:
  28. return 0x0004;
  29. case SNAPSHOT:
  30. return 0x0008;
  31. case AUDIO_VOL_UP:
  32. return 0x0010;
  33. case AUDIO_VOL_DOWN:
  34. return 0x0020;
  35. case TRANSPORT_PLAY_PAUSE:
  36. return 0x0040;
  37. case TRANSPORT_FAST_FORWARD:
  38. return 0x0080;
  39. case TRANSPORT_REWIND:
  40. return 0x0100;
  41. case TRANSPORT_NEXT_TRACK:
  42. return 0x0200;
  43. case TRANSPORT_PREV_TRACK:
  44. return 0x0400;
  45. case TRANSPORT_RANDOM_PLAY:
  46. return 0x0800;
  47. case TRANSPORT_STOP:
  48. return 0x1000;
  49. default:
  50. return 0;
  51. }
  52. }
  53. // https://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/bluetooth_cr_UG-v1.0r.pdf#G7.663734
  54. static inline uint16_t CONSUMER2RN42(uint16_t usage) {
  55. switch (usage) {
  56. case AC_HOME:
  57. return 0x0001;
  58. case AL_EMAIL:
  59. return 0x0002;
  60. case AC_SEARCH:
  61. return 0x0004;
  62. case AL_KEYBOARD_LAYOUT:
  63. return 0x0008;
  64. case AUDIO_VOL_UP:
  65. return 0x0010;
  66. case AUDIO_VOL_DOWN:
  67. return 0x0020;
  68. case AUDIO_MUTE:
  69. return 0x0040;
  70. case TRANSPORT_PLAY_PAUSE:
  71. return 0x0080;
  72. case TRANSPORT_NEXT_TRACK:
  73. return 0x0100;
  74. case TRANSPORT_PREV_TRACK:
  75. return 0x0200;
  76. case TRANSPORT_STOP:
  77. return 0x0400;
  78. case TRANSPORT_EJECT:
  79. return 0x0800;
  80. case TRANSPORT_FAST_FORWARD:
  81. return 0x1000;
  82. case TRANSPORT_REWIND:
  83. return 0x2000;
  84. case TRANSPORT_STOP_EJECT:
  85. return 0x4000;
  86. case AL_LOCAL_BROWSER:
  87. return 0x8000;
  88. default:
  89. return 0;
  90. }
  91. }