You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
6.5 KiB

Merge ChibiOS and LUFA descriptor support (#2362) * Move lufa descriptor to protocol/usb_descriptor * Try to compile usb_descriptor on ChibiOS * Add lufa_utils for ChibiOS Lufa USB descriptors for ChibiOS * More lufa_util compatibility fixes * First compiling version of shared USB descriptor * Send the usb descriptors * Fix the CONSOLE output on ChibiOS * Add errors for unsupported interfaces * Enable support for vitual serial port USB descriptors * Implement virtual serial port for ChibiOS * Cleanup the lufa_utils Use the default lufa header files * Add raw hid support for ChibiOS This is completely untested * Enable midi compilation on ChibiOS * Move midi functionality out of lufa.c * Don't register sysex callback when not needed * ChibiOS compilation fixes * Update ChibiOS submodule * Fix the Midi USB descriptor It didn't work properly when both Midi and Virtual serial port was enabled. * Add MIDI support for ChibiOS * Fix USB descriptor strings on ChibiOS * Use serial usb driver for raw hid * Generalize the ChibiOS stream like drivers This makes the initialization much more simple and eliminates a lot of the code duplication. * Convert console output to chibios stream driver * Fixes for ChibiOS update * Update the ChibiOS contrib submodule To include the usb data toggle synchronization fixes * Fix duplicate reset enumeration on ChibiOS * Add missing include * Add number of endpoints check for ChibiOS * Enable serial USB driver on all keyboards * Add missing includes when API is enabled withot midi * Add another missing inlcude
6 years ago
  1. /*
  2. Copyright 2011,2012 Jun Wako <wakojun@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef REPORT_H
  15. #define REPORT_H
  16. #include <stdint.h>
  17. #include "keycode.h"
  18. /* report id */
  19. #define REPORT_ID_MOUSE 1
  20. #define REPORT_ID_SYSTEM 2
  21. #define REPORT_ID_CONSUMER 3
  22. /* mouse buttons */
  23. #define MOUSE_BTN1 (1<<0)
  24. #define MOUSE_BTN2 (1<<1)
  25. #define MOUSE_BTN3 (1<<2)
  26. #define MOUSE_BTN4 (1<<3)
  27. #define MOUSE_BTN5 (1<<4)
  28. /* Consumer Page(0x0C)
  29. * following are supported by Windows: http://msdn.microsoft.com/en-us/windows/hardware/gg463372.aspx
  30. */
  31. #define AUDIO_MUTE 0x00E2
  32. #define AUDIO_VOL_UP 0x00E9
  33. #define AUDIO_VOL_DOWN 0x00EA
  34. #define TRANSPORT_NEXT_TRACK 0x00B5
  35. #define TRANSPORT_PREV_TRACK 0x00B6
  36. #define TRANSPORT_STOP 0x00B7
  37. #define TRANSPORT_STOP_EJECT 0x00CC
  38. #define TRANSPORT_PLAY_PAUSE 0x00CD
  39. /* application launch */
  40. #define AL_CC_CONFIG 0x0183
  41. #define AL_EMAIL 0x018A
  42. #define AL_CALCULATOR 0x0192
  43. #define AL_LOCAL_BROWSER 0x0194
  44. /* application control */
  45. #define AC_SEARCH 0x0221
  46. #define AC_HOME 0x0223
  47. #define AC_BACK 0x0224
  48. #define AC_FORWARD 0x0225
  49. #define AC_STOP 0x0226
  50. #define AC_REFRESH 0x0227
  51. #define AC_BOOKMARKS 0x022A
  52. /* supplement for Bluegiga iWRAP HID(not supported by Windows?) */
  53. #define AL_LOCK 0x019E
  54. #define TRANSPORT_RECORD 0x00B2
  55. #define TRANSPORT_FAST_FORWARD 0x00B3
  56. #define TRANSPORT_REWIND 0x00B4
  57. #define TRANSPORT_EJECT 0x00B8
  58. #define AC_MINIMIZE 0x0206
  59. /* Generic Desktop Page(0x01) - system power control */
  60. #define SYSTEM_POWER_DOWN 0x0081
  61. #define SYSTEM_SLEEP 0x0082
  62. #define SYSTEM_WAKE_UP 0x0083
  63. /* key report size(NKRO or boot mode) */
  64. #if defined(NKRO_ENABLE)
  65. #if defined(PROTOCOL_PJRC)
  66. #include "usb.h"
  67. #define KEYBOARD_REPORT_SIZE KBD2_SIZE
  68. #define KEYBOARD_REPORT_KEYS (KBD2_SIZE - 2)
  69. #define KEYBOARD_REPORT_BITS (KBD2_SIZE - 1)
  70. #elif defined(PROTOCOL_LUFA) || defined(PROTOCOL_CHIBIOS)
  71. #include "protocol/usb_descriptor.h"
  72. #define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
  73. #define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
  74. #define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
  75. #else
  76. #error "NKRO not supported with this protocol"
  77. #endif
  78. #else
  79. # define KEYBOARD_REPORT_SIZE 8
  80. # define KEYBOARD_REPORT_KEYS 6
  81. #endif
  82. #ifdef __cplusplus
  83. extern "C" {
  84. #endif
  85. /*
  86. * keyboard report is 8-byte array retains state of 8 modifiers and 6 keys.
  87. *
  88. * byte |0 |1 |2 |3 |4 |5 |6 |7
  89. * -----+--------+--------+--------+--------+--------+--------+--------+--------
  90. * desc |mods |reserved|keys[0] |keys[1] |keys[2] |keys[3] |keys[4] |keys[5]
  91. *
  92. * It is exended to 16 bytes to retain 120keys+8mods when NKRO mode.
  93. *
  94. * byte |0 |1 |2 |3 |4 |5 |6 |7 ... |15
  95. * -----+--------+--------+--------+--------+--------+--------+--------+-------- +--------
  96. * desc |mods |bits[0] |bits[1] |bits[2] |bits[3] |bits[4] |bits[5] |bits[6] ... |bit[14]
  97. *
  98. * mods retains state of 8 modifiers.
  99. *
  100. * bit |0 |1 |2 |3 |4 |5 |6 |7
  101. * -----+--------+--------+--------+--------+--------+--------+--------+--------
  102. * desc |Lcontrol|Lshift |Lalt |Lgui |Rcontrol|Rshift |Ralt |Rgui
  103. *
  104. */
  105. typedef union {
  106. uint8_t raw[KEYBOARD_REPORT_SIZE];
  107. struct {
  108. uint8_t mods;
  109. uint8_t reserved;
  110. uint8_t keys[KEYBOARD_REPORT_KEYS];
  111. };
  112. #ifdef NKRO_ENABLE
  113. struct {
  114. uint8_t mods;
  115. uint8_t bits[KEYBOARD_REPORT_BITS];
  116. } nkro;
  117. #endif
  118. } __attribute__ ((packed)) report_keyboard_t;
  119. typedef struct {
  120. uint8_t buttons;
  121. int8_t x;
  122. int8_t y;
  123. int8_t v;
  124. int8_t h;
  125. } __attribute__ ((packed)) report_mouse_t;
  126. /* keycode to system usage */
  127. #define KEYCODE2SYSTEM(key) \
  128. (key == KC_SYSTEM_POWER ? SYSTEM_POWER_DOWN : \
  129. (key == KC_SYSTEM_SLEEP ? SYSTEM_SLEEP : \
  130. (key == KC_SYSTEM_WAKE ? SYSTEM_WAKE_UP : 0)))
  131. /* keycode to consumer usage */
  132. #define KEYCODE2CONSUMER(key) \
  133. (key == KC_AUDIO_MUTE ? AUDIO_MUTE : \
  134. (key == KC_AUDIO_VOL_UP ? AUDIO_VOL_UP : \
  135. (key == KC_AUDIO_VOL_DOWN ? AUDIO_VOL_DOWN : \
  136. (key == KC_MEDIA_NEXT_TRACK ? TRANSPORT_NEXT_TRACK : \
  137. (key == KC_MEDIA_PREV_TRACK ? TRANSPORT_PREV_TRACK : \
  138. (key == KC_MEDIA_FAST_FORWARD ? TRANSPORT_FAST_FORWARD : \
  139. (key == KC_MEDIA_REWIND ? TRANSPORT_REWIND : \
  140. (key == KC_MEDIA_STOP ? TRANSPORT_STOP : \
  141. (key == KC_MEDIA_EJECT ? TRANSPORT_STOP_EJECT : \
  142. (key == KC_MEDIA_PLAY_PAUSE ? TRANSPORT_PLAY_PAUSE : \
  143. (key == KC_MEDIA_SELECT ? AL_CC_CONFIG : \
  144. (key == KC_MAIL ? AL_EMAIL : \
  145. (key == KC_CALCULATOR ? AL_CALCULATOR : \
  146. (key == KC_MY_COMPUTER ? AL_LOCAL_BROWSER : \
  147. (key == KC_WWW_SEARCH ? AC_SEARCH : \
  148. (key == KC_WWW_HOME ? AC_HOME : \
  149. (key == KC_WWW_BACK ? AC_BACK : \
  150. (key == KC_WWW_FORWARD ? AC_FORWARD : \
  151. (key == KC_WWW_STOP ? AC_STOP : \
  152. (key == KC_WWW_REFRESH ? AC_REFRESH : \
  153. (key == KC_WWW_FAVORITES ? AC_BOOKMARKS : 0)))))))))))))))))))))
  154. uint8_t has_anykey(report_keyboard_t* keyboard_report);
  155. uint8_t get_first_key(report_keyboard_t* keyboard_report);
  156. void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code);
  157. void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code);
  158. #ifdef NKRO_ENABLE
  159. void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code);
  160. void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code);
  161. #endif
  162. void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key);
  163. void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key);
  164. void clear_keys_from_report(report_keyboard_t* keyboard_report);
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168. #endif