]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/common/report.h
core: Update comments in keycode.h
[max/tmk_keyboard.git] / tmk_core / common / report.h
1 /*
2 Copyright 2011,2012,2020 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
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
18 #ifndef REPORT_H
19 #define REPORT_H
20
21 #include <stdint.h>
22 #include "keycode.h"
23
24
25 /* report id */
26 #define REPORT_ID_MOUSE     1
27 #define REPORT_ID_SYSTEM    2
28 #define REPORT_ID_CONSUMER  3
29
30 /* mouse buttons */
31 #define MOUSE_BTN1 (1<<0)
32 #define MOUSE_BTN2 (1<<1)
33 #define MOUSE_BTN3 (1<<2)
34 #define MOUSE_BTN4 (1<<3)
35 #define MOUSE_BTN5 (1<<4)
36 #define MOUSE_BTN6 (1<<5)
37 #define MOUSE_BTN7 (1<<6)
38 #define MOUSE_BTN8 (1<<7)
39
40
41 /*
42  * USB HID Specifications
43  * https://www.usb.org/hid#approved-usage-table-review-requests
44  */
45
46 /*
47  * Consumer Page(0x0C)
48  * https://github.com/tmk/tmk_keyboard/issues/370
49  */
50 #define AUDIO_MUTE              0x00E2
51 #define AUDIO_VOL_UP            0x00E9
52 #define AUDIO_VOL_DOWN          0x00EA
53 #define TRANSPORT_NEXT_TRACK    0x00B5
54 #define TRANSPORT_PREV_TRACK    0x00B6
55 #define TRANSPORT_STOP          0x00B7
56 #define TRANSPORT_STOP_EJECT    0x00CC
57 #define TRANSPORT_PLAY_PAUSE    0x00CD
58 /* application launch */
59 #define APPLAUNCH_CC_CONFIG     0x0183
60 #define APPLAUNCH_EMAIL         0x018A
61 #define APPLAUNCH_CALCULATOR    0x0192
62 #define APPLAUNCH_LOCAL_BROWSER 0x0194
63 /* application control */
64 #define APPCONTROL_SEARCH       0x0221
65 #define APPCONTROL_HOME         0x0223
66 #define APPCONTROL_BACK         0x0224
67 #define APPCONTROL_FORWARD      0x0225
68 #define APPCONTROL_STOP         0x0226
69 #define APPCONTROL_REFRESH      0x0227
70 #define APPCONTROL_BOOKMARKS    0x022A
71 /* supplement for Bluegiga iWRAP HID(not supported by Windows?) */
72 #define APPLAUNCH_LOCK          0x019E
73 #define TRANSPORT_RECORD        0x00B2
74 #define TRANSPORT_FAST_FORWARD  0x00B3
75 #define TRANSPORT_REWIND        0x00B4
76 #define TRANSPORT_EJECT         0x00B8
77 #define APPCONTROL_MINIMIZE     0x0206
78 /* Display Brightness Controls  https://www.usb.org/sites/default/files/hutrr41_0.pdf */
79 #define BRIGHTNESS_INCREMENT    0x006F
80 #define BRIGHTNESS_DECREMENT    0x0070
81
82 /*
83  * Generic Desktop Page(0x01) - system power control
84  */
85 #define SYSTEM_POWER_DOWN       0x0081
86 #define SYSTEM_SLEEP            0x0082
87 #define SYSTEM_WAKE_UP          0x0083
88
89
90 /* key report size(NKRO or boot mode) */
91 #if defined(PROTOCOL_PJRC) && defined(NKRO_ENABLE)
92 #   include "usb.h"
93 #   define KEYBOARD_REPORT_SIZE KBD2_SIZE
94 #   define KEYBOARD_REPORT_KEYS (KBD2_SIZE - 2)
95 #   define KEYBOARD_REPORT_BITS (KBD2_SIZE - 1)
96
97 #elif defined(PROTOCOL_LUFA) && defined(NKRO_ENABLE)
98 #   include "protocol/lufa/descriptor.h"
99 #   define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
100 #   define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
101 #   define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
102 #elif defined(PROTOCOL_CHIBIOS) && defined(NKRO_ENABLE)
103 #   include "protocol/chibios/usb_main.h"
104 #   define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
105 #   define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
106 #   define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
107
108 #else
109 #   define KEYBOARD_REPORT_SIZE 8
110 #   define KEYBOARD_REPORT_KEYS 6
111 #endif
112
113
114 #ifdef __cplusplus
115 extern "C" {
116 #endif
117
118 /*
119  * keyboard report is 8-byte array retains state of 8 modifiers and 6 keys.
120  *
121  * byte |0       |1       |2       |3       |4       |5       |6       |7
122  * -----+--------+--------+--------+--------+--------+--------+--------+--------
123  * desc |mods    |reserved|keys[0] |keys[1] |keys[2] |keys[3] |keys[4] |keys[5]
124  *
125  * It is exended to 16 bytes to retain 120keys+8mods when NKRO mode.
126  *
127  * byte |0       |1       |2       |3       |4       |5       |6       |7        ... |15
128  * -----+--------+--------+--------+--------+--------+--------+--------+--------     +--------
129  * desc |mods    |bits[0] |bits[1] |bits[2] |bits[3] |bits[4] |bits[5] |bits[6]  ... |bit[14]
130  *
131  * mods retains state of 8 modifiers.
132  *
133  *  bit |0       |1       |2       |3       |4       |5       |6       |7
134  * -----+--------+--------+--------+--------+--------+--------+--------+--------
135  * desc |Lcontrol|Lshift  |Lalt    |Lgui    |Rcontrol|Rshift  |Ralt    |Rgui
136  *
137  */
138 typedef union {
139     uint8_t raw[KEYBOARD_REPORT_SIZE];
140     struct {
141         uint8_t mods;
142         uint8_t reserved;
143         uint8_t keys[KEYBOARD_REPORT_KEYS];
144     };
145 #ifdef NKRO_ENABLE
146     struct {
147         uint8_t mods;
148         uint8_t bits[KEYBOARD_REPORT_BITS];
149     } nkro;
150 #endif
151 } __attribute__ ((packed)) report_keyboard_t;
152 /*
153 typedef struct {
154     uint8_t mods;
155     uint8_t reserved;
156     uint8_t keys[REPORT_KEYS];
157 } __attribute__ ((packed)) report_keyboard_t;
158 */
159
160 typedef struct {
161     uint8_t buttons;
162     int8_t x;
163     int8_t y;
164     int8_t v;
165     int8_t h;
166 } __attribute__ ((packed)) report_mouse_t;
167
168
169 /* keycode to system usage */
170 #define KEYCODE2SYSTEM(key) \
171     (key == KC_SYSTEM_POWER ? SYSTEM_POWER_DOWN : \
172     (key == KC_SYSTEM_SLEEP ? SYSTEM_SLEEP : \
173     (key == KC_SYSTEM_WAKE  ? SYSTEM_WAKE_UP : 0)))
174
175 /* keycode to consumer usage */
176 #define KEYCODE2CONSUMER(key) \
177     (key == KC_AUDIO_MUTE           ?  AUDIO_MUTE : \
178     (key == KC_AUDIO_VOL_UP         ?  AUDIO_VOL_UP : \
179     (key == KC_AUDIO_VOL_DOWN       ?  AUDIO_VOL_DOWN : \
180     (key == KC_MEDIA_NEXT_TRACK     ?  TRANSPORT_NEXT_TRACK : \
181     (key == KC_MEDIA_PREV_TRACK     ?  TRANSPORT_PREV_TRACK : \
182     (key == KC_MEDIA_FAST_FORWARD   ?  TRANSPORT_FAST_FORWARD : \
183     (key == KC_MEDIA_REWIND         ?  TRANSPORT_REWIND : \
184     (key == KC_MEDIA_STOP           ?  TRANSPORT_STOP : \
185     (key == KC_MEDIA_EJECT          ?  TRANSPORT_STOP_EJECT : \
186     (key == KC_MEDIA_PLAY_PAUSE     ?  TRANSPORT_PLAY_PAUSE : \
187     (key == KC_MEDIA_SELECT         ?  APPLAUNCH_CC_CONFIG : \
188     (key == KC_MAIL                 ?  APPLAUNCH_EMAIL : \
189     (key == KC_CALCULATOR           ?  APPLAUNCH_CALCULATOR : \
190     (key == KC_MY_COMPUTER          ?  APPLAUNCH_LOCAL_BROWSER : \
191     (key == KC_WWW_SEARCH           ?  APPCONTROL_SEARCH : \
192     (key == KC_WWW_HOME             ?  APPCONTROL_HOME : \
193     (key == KC_WWW_BACK             ?  APPCONTROL_BACK : \
194     (key == KC_WWW_FORWARD          ?  APPCONTROL_FORWARD : \
195     (key == KC_WWW_STOP             ?  APPCONTROL_STOP : \
196     (key == KC_WWW_REFRESH          ?  APPCONTROL_REFRESH : \
197     (key == KC_WWW_FAVORITES        ?  APPCONTROL_BOOKMARKS : \
198     (key == KC_BRIGHTNESS_INC       ?  BRIGHTNESS_INCREMENT : \
199     (key == KC_BRIGHTNESS_DEC       ?  BRIGHTNESS_DECREMENT : 0)))))))))))))))))))))))
200
201 #ifdef __cplusplus
202 }
203 #endif
204
205 #endif