logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

report.h (10410B)


  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. #pragma once
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "keycode.h"
  18. #include "util.h"
  19. #ifdef JOYSTICK_ENABLE
  20. # include "joystick.h"
  21. #endif
  22. // clang-format off
  23. /* HID report IDs */
  24. enum hid_report_ids {
  25. REPORT_ID_ALL = 0,
  26. REPORT_ID_KEYBOARD = 1,
  27. REPORT_ID_MOUSE,
  28. REPORT_ID_SYSTEM,
  29. REPORT_ID_CONSUMER,
  30. REPORT_ID_PROGRAMMABLE_BUTTON,
  31. REPORT_ID_NKRO,
  32. REPORT_ID_JOYSTICK,
  33. REPORT_ID_DIGITIZER,
  34. REPORT_ID_COUNT = REPORT_ID_DIGITIZER
  35. };
  36. #define IS_VALID_REPORT_ID(id) ((id) >= REPORT_ID_ALL && (id) <= REPORT_ID_COUNT)
  37. /* Mouse buttons */
  38. #define MOUSE_BTN_MASK(n) (1 << (n))
  39. enum mouse_buttons {
  40. MOUSE_BTN1 = MOUSE_BTN_MASK(0),
  41. MOUSE_BTN2 = MOUSE_BTN_MASK(1),
  42. MOUSE_BTN3 = MOUSE_BTN_MASK(2),
  43. MOUSE_BTN4 = MOUSE_BTN_MASK(3),
  44. MOUSE_BTN5 = MOUSE_BTN_MASK(4),
  45. MOUSE_BTN6 = MOUSE_BTN_MASK(5),
  46. MOUSE_BTN7 = MOUSE_BTN_MASK(6),
  47. MOUSE_BTN8 = MOUSE_BTN_MASK(7)
  48. };
  49. /* Consumer Page (0x0C)
  50. *
  51. * See https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf#page=75
  52. */
  53. enum consumer_usages {
  54. // 15.5 Display Controls
  55. SNAPSHOT = 0x065,
  56. BRIGHTNESS_UP = 0x06F, // https://www.usb.org/sites/default/files/hutrr41_0.pdf
  57. BRIGHTNESS_DOWN = 0x070,
  58. // 15.7 Transport Controls
  59. TRANSPORT_RECORD = 0x0B2,
  60. TRANSPORT_FAST_FORWARD = 0x0B3,
  61. TRANSPORT_REWIND = 0x0B4,
  62. TRANSPORT_NEXT_TRACK = 0x0B5,
  63. TRANSPORT_PREV_TRACK = 0x0B6,
  64. TRANSPORT_STOP = 0x0B7,
  65. TRANSPORT_EJECT = 0x0B8,
  66. TRANSPORT_RANDOM_PLAY = 0x0B9,
  67. TRANSPORT_STOP_EJECT = 0x0CC,
  68. TRANSPORT_PLAY_PAUSE = 0x0CD,
  69. // 15.9.1 Audio Controls - Volume
  70. AUDIO_MUTE = 0x0E2,
  71. AUDIO_VOL_UP = 0x0E9,
  72. AUDIO_VOL_DOWN = 0x0EA,
  73. // 15.15 Application Launch Buttons
  74. AL_CC_CONFIG = 0x183,
  75. AL_EMAIL = 0x18A,
  76. AL_CALCULATOR = 0x192,
  77. AL_LOCAL_BROWSER = 0x194,
  78. AL_LOCK = 0x19E,
  79. AL_CONTROL_PANEL = 0x19F,
  80. AL_ASSISTANT = 0x1CB,
  81. AL_KEYBOARD_LAYOUT = 0x1AE,
  82. // 15.16 Generic GUI Application Controls
  83. AC_NEW = 0x201,
  84. AC_OPEN = 0x202,
  85. AC_CLOSE = 0x203,
  86. AC_EXIT = 0x204,
  87. AC_MAXIMIZE = 0x205,
  88. AC_MINIMIZE = 0x206,
  89. AC_SAVE = 0x207,
  90. AC_PRINT = 0x208,
  91. AC_PROPERTIES = 0x209,
  92. AC_UNDO = 0x21A,
  93. AC_COPY = 0x21B,
  94. AC_CUT = 0x21C,
  95. AC_PASTE = 0x21D,
  96. AC_SELECT_ALL = 0x21E,
  97. AC_FIND = 0x21F,
  98. AC_SEARCH = 0x221,
  99. AC_HOME = 0x223,
  100. AC_BACK = 0x224,
  101. AC_FORWARD = 0x225,
  102. AC_STOP = 0x226,
  103. AC_REFRESH = 0x227,
  104. AC_BOOKMARKS = 0x22A,
  105. AC_NEXT_KEYBOARD_LAYOUT_SELECT = 0x29D,
  106. AC_DESKTOP_SHOW_ALL_WINDOWS = 0x29F,
  107. AC_SOFT_KEY_LEFT = 0x2A0
  108. };
  109. /* Generic Desktop Page (0x01)
  110. *
  111. * See https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf#page=26
  112. */
  113. enum desktop_usages {
  114. // 4.5.1 System Controls - Power Controls
  115. SYSTEM_POWER_DOWN = 0x81,
  116. SYSTEM_SLEEP = 0x82,
  117. SYSTEM_WAKE_UP = 0x83,
  118. SYSTEM_RESTART = 0x8F,
  119. // 4.10 System Display Controls
  120. SYSTEM_DISPLAY_TOGGLE_INT_EXT = 0xB5
  121. };
  122. // clang-format on
  123. #define NKRO_REPORT_BITS 30
  124. #ifdef KEYBOARD_SHARED_EP
  125. # define KEYBOARD_REPORT_SIZE 9
  126. #else
  127. # define KEYBOARD_REPORT_SIZE 8
  128. #endif
  129. #define KEYBOARD_REPORT_KEYS 6
  130. #ifdef __cplusplus
  131. extern "C" {
  132. #endif
  133. /*
  134. * keyboard report is 8-byte array retains state of 8 modifiers and 6 keys.
  135. *
  136. * byte |0 |1 |2 |3 |4 |5 |6 |7
  137. * -----+--------+--------+--------+--------+--------+--------+--------+--------
  138. * desc |mods |reserved|keys[0] |keys[1] |keys[2] |keys[3] |keys[4] |keys[5]
  139. *
  140. * It is exended to 16 bytes to retain 120keys+8mods when NKRO mode.
  141. *
  142. * byte |0 |1 |2 |3 |4 |5 |6 |7 ... |15
  143. * -----+--------+--------+--------+--------+--------+--------+--------+-------- +--------
  144. * desc |mods |bits[0] |bits[1] |bits[2] |bits[3] |bits[4] |bits[5] |bits[6] ... |bit[14]
  145. *
  146. * mods retains state of 8 modifiers.
  147. *
  148. * bit |0 |1 |2 |3 |4 |5 |6 |7
  149. * -----+--------+--------+--------+--------+--------+--------+--------+--------
  150. * desc |Lcontrol|Lshift |Lalt |Lgui |Rcontrol|Rshift |Ralt |Rgui
  151. *
  152. */
  153. typedef struct {
  154. #ifdef KEYBOARD_SHARED_EP
  155. uint8_t report_id;
  156. #endif
  157. uint8_t mods;
  158. uint8_t reserved;
  159. uint8_t keys[KEYBOARD_REPORT_KEYS];
  160. } PACKED report_keyboard_t;
  161. typedef struct {
  162. uint8_t report_id;
  163. uint8_t mods;
  164. uint8_t bits[NKRO_REPORT_BITS];
  165. } PACKED report_nkro_t;
  166. typedef struct {
  167. uint8_t report_id;
  168. uint16_t usage;
  169. } PACKED report_extra_t;
  170. typedef struct {
  171. uint8_t report_id;
  172. uint32_t usage;
  173. } PACKED report_programmable_button_t;
  174. #ifdef MOUSE_EXTENDED_REPORT
  175. # define MOUSE_REPORT_XY_MIN INT16_MIN
  176. # define MOUSE_REPORT_XY_MAX INT16_MAX
  177. typedef int16_t mouse_xy_report_t;
  178. #else
  179. # define MOUSE_REPORT_XY_MIN INT8_MIN
  180. # define MOUSE_REPORT_XY_MAX INT8_MAX
  181. typedef int8_t mouse_xy_report_t;
  182. #endif
  183. #ifdef WHEEL_EXTENDED_REPORT
  184. # define MOUSE_REPORT_HV_MIN INT16_MIN
  185. # define MOUSE_REPORT_HV_MAX INT16_MAX
  186. typedef int16_t mouse_hv_report_t;
  187. #else
  188. # define MOUSE_REPORT_HV_MIN INT8_MIN
  189. # define MOUSE_REPORT_HV_MAX INT8_MAX
  190. typedef int8_t mouse_hv_report_t;
  191. #endif
  192. typedef struct {
  193. #ifdef MOUSE_SHARED_EP
  194. uint8_t report_id;
  195. #endif
  196. uint8_t buttons;
  197. #ifdef MOUSE_EXTENDED_REPORT
  198. int8_t boot_x;
  199. int8_t boot_y;
  200. #endif
  201. mouse_xy_report_t x;
  202. mouse_xy_report_t y;
  203. mouse_hv_report_t v;
  204. mouse_hv_report_t h;
  205. } PACKED report_mouse_t;
  206. typedef struct {
  207. #ifdef DIGITIZER_SHARED_EP
  208. uint8_t report_id;
  209. #endif
  210. bool in_range : 1;
  211. bool tip : 1;
  212. bool barrel : 1;
  213. uint8_t reserved : 5;
  214. uint16_t x;
  215. uint16_t y;
  216. } PACKED report_digitizer_t;
  217. #if JOYSTICK_AXIS_RESOLUTION > 8
  218. typedef int16_t joystick_axis_t;
  219. #else
  220. typedef int8_t joystick_axis_t;
  221. #endif
  222. typedef struct {
  223. #ifdef JOYSTICK_SHARED_EP
  224. uint8_t report_id;
  225. #endif
  226. #if JOYSTICK_AXIS_COUNT > 0
  227. joystick_axis_t axes[JOYSTICK_AXIS_COUNT];
  228. #endif
  229. #ifdef JOYSTICK_HAS_HAT
  230. int8_t hat : 4;
  231. uint8_t reserved : 4;
  232. #endif
  233. #if JOYSTICK_BUTTON_COUNT > 0
  234. uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1];
  235. #endif
  236. } PACKED report_joystick_t;
  237. /* keycode to system usage */
  238. static inline uint16_t KEYCODE2SYSTEM(uint8_t key) {
  239. switch (key) {
  240. case KC_SYSTEM_POWER:
  241. return SYSTEM_POWER_DOWN;
  242. case KC_SYSTEM_SLEEP:
  243. return SYSTEM_SLEEP;
  244. case KC_SYSTEM_WAKE:
  245. return SYSTEM_WAKE_UP;
  246. default:
  247. return 0;
  248. }
  249. }
  250. /* keycode to consumer usage */
  251. static inline uint16_t KEYCODE2CONSUMER(uint8_t key) {
  252. switch (key) {
  253. case KC_AUDIO_MUTE:
  254. return AUDIO_MUTE;
  255. case KC_AUDIO_VOL_UP:
  256. return AUDIO_VOL_UP;
  257. case KC_AUDIO_VOL_DOWN:
  258. return AUDIO_VOL_DOWN;
  259. case KC_MEDIA_NEXT_TRACK:
  260. return TRANSPORT_NEXT_TRACK;
  261. case KC_MEDIA_PREV_TRACK:
  262. return TRANSPORT_PREV_TRACK;
  263. case KC_MEDIA_FAST_FORWARD:
  264. return TRANSPORT_FAST_FORWARD;
  265. case KC_MEDIA_REWIND:
  266. return TRANSPORT_REWIND;
  267. case KC_MEDIA_STOP:
  268. return TRANSPORT_STOP;
  269. case KC_MEDIA_EJECT:
  270. return TRANSPORT_STOP_EJECT;
  271. case KC_MEDIA_PLAY_PAUSE:
  272. return TRANSPORT_PLAY_PAUSE;
  273. case KC_MEDIA_SELECT:
  274. return AL_CC_CONFIG;
  275. case KC_MAIL:
  276. return AL_EMAIL;
  277. case KC_CALCULATOR:
  278. return AL_CALCULATOR;
  279. case KC_MY_COMPUTER:
  280. return AL_LOCAL_BROWSER;
  281. case KC_CONTROL_PANEL:
  282. return AL_CONTROL_PANEL;
  283. case KC_ASSISTANT:
  284. return AL_ASSISTANT;
  285. case KC_WWW_SEARCH:
  286. return AC_SEARCH;
  287. case KC_WWW_HOME:
  288. return AC_HOME;
  289. case KC_WWW_BACK:
  290. return AC_BACK;
  291. case KC_WWW_FORWARD:
  292. return AC_FORWARD;
  293. case KC_WWW_STOP:
  294. return AC_STOP;
  295. case KC_WWW_REFRESH:
  296. return AC_REFRESH;
  297. case KC_BRIGHTNESS_UP:
  298. return BRIGHTNESS_UP;
  299. case KC_BRIGHTNESS_DOWN:
  300. return BRIGHTNESS_DOWN;
  301. case KC_WWW_FAVORITES:
  302. return AC_BOOKMARKS;
  303. case KC_MISSION_CONTROL:
  304. return AC_DESKTOP_SHOW_ALL_WINDOWS;
  305. case KC_LAUNCHPAD:
  306. return AC_SOFT_KEY_LEFT;
  307. default:
  308. return 0;
  309. }
  310. }
  311. uint8_t has_anykey(void);
  312. uint8_t get_first_key(void);
  313. bool is_key_pressed(uint8_t key);
  314. void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code);
  315. void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code);
  316. #ifdef NKRO_ENABLE
  317. void add_key_bit(report_nkro_t* nkro_report, uint8_t code);
  318. void del_key_bit(report_nkro_t* nkro_report, uint8_t code);
  319. #endif
  320. void add_key_to_report(uint8_t key);
  321. void del_key_from_report(uint8_t key);
  322. void clear_keys_from_report(void);
  323. #ifdef MOUSE_ENABLE
  324. bool has_mouse_report_changed(report_mouse_t* new_report, report_mouse_t* old_report);
  325. #endif
  326. #ifdef __cplusplus
  327. }
  328. #endif