]> git.gir.st - tmk_keyboard.git/blob - common/report.h
Squashed 'tmk_core/' changes from d5c5ac6..8da1898
[tmk_keyboard.git] / common / report.h
1 /*
2 Copyright 2011,2012 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
37 /* Consumer Page(0x0C)
38 * following are supported by Windows: http://msdn.microsoft.com/en-us/windows/hardware/gg463372.aspx
39 */
40 #define AUDIO_MUTE 0x00E2
41 #define AUDIO_VOL_UP 0x00E9
42 #define AUDIO_VOL_DOWN 0x00EA
43 #define TRANSPORT_NEXT_TRACK 0x00B5
44 #define TRANSPORT_PREV_TRACK 0x00B6
45 #define TRANSPORT_STOP 0x00B7
46 #define TRANSPORT_STOP_EJECT 0x00CC
47 #define TRANSPORT_PLAY_PAUSE 0x00CD
48 /* application launch */
49 #define AL_CC_CONFIG 0x0183
50 #define AL_EMAIL 0x018A
51 #define AL_CALCULATOR 0x0192
52 #define AL_LOCAL_BROWSER 0x0194
53 /* application control */
54 #define AC_SEARCH 0x0221
55 #define AC_HOME 0x0223
56 #define AC_BACK 0x0224
57 #define AC_FORWARD 0x0225
58 #define AC_STOP 0x0226
59 #define AC_REFRESH 0x0227
60 #define AC_BOOKMARKS 0x022A
61 /* supplement for Bluegiga iWRAP HID(not supported by Windows?) */
62 #define AL_LOCK 0x019E
63 #define TRANSPORT_RECORD 0x00B2
64 #define TRANSPORT_FAST_FORWARD 0x00B3
65 #define TRANSPORT_REWIND 0x00B4
66 #define TRANSPORT_EJECT 0x00B8
67 #define AC_MINIMIZE 0x0206
68
69 /* Generic Desktop Page(0x01) - system power control */
70 #define SYSTEM_POWER_DOWN 0x0081
71 #define SYSTEM_SLEEP 0x0082
72 #define SYSTEM_WAKE_UP 0x0083
73
74
75 /* key report size(NKRO or boot mode) */
76 #if defined(PROTOCOL_PJRC) && defined(NKRO_ENABLE)
77 # include "usb.h"
78 # define KEYBOARD_REPORT_SIZE KBD2_SIZE
79 # define KEYBOARD_REPORT_KEYS (KBD2_SIZE - 2)
80 # define KEYBOARD_REPORT_BITS (KBD2_SIZE - 1)
81
82 #elif defined(PROTOCOL_LUFA) && defined(NKRO_ENABLE)
83 # include "protocol/lufa/descriptor.h"
84 # define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
85 # define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
86 # define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
87 #elif defined(PROTOCOL_CHIBIOS) && defined(NKRO_ENABLE)
88 # include "protocol/chibios/usb_main.h"
89 # define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
90 # define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
91 # define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
92
93 #else
94 # define KEYBOARD_REPORT_SIZE 8
95 # define KEYBOARD_REPORT_KEYS 6
96 #endif
97
98
99 #ifdef __cplusplus
100 extern "C" {
101 #endif
102
103 /*
104 * keyboard report is 8-byte array retains state of 8 modifiers and 6 keys.
105 *
106 * byte |0 |1 |2 |3 |4 |5 |6 |7
107 * -----+--------+--------+--------+--------+--------+--------+--------+--------
108 * desc |mods |reserved|keys[0] |keys[1] |keys[2] |keys[3] |keys[4] |keys[5]
109 *
110 * It is exended to 16 bytes to retain 120keys+8mods when NKRO mode.
111 *
112 * byte |0 |1 |2 |3 |4 |5 |6 |7 ... |15
113 * -----+--------+--------+--------+--------+--------+--------+--------+-------- +--------
114 * desc |mods |bits[0] |bits[1] |bits[2] |bits[3] |bits[4] |bits[5] |bits[6] ... |bit[14]
115 *
116 * mods retains state of 8 modifiers.
117 *
118 * bit |0 |1 |2 |3 |4 |5 |6 |7
119 * -----+--------+--------+--------+--------+--------+--------+--------+--------
120 * desc |Lcontrol|Lshift |Lalt |Lgui |Rcontrol|Rshift |Ralt |Rgui
121 *
122 */
123 typedef union {
124 uint8_t raw[KEYBOARD_REPORT_SIZE];
125 struct {
126 uint8_t mods;
127 uint8_t reserved;
128 uint8_t keys[KEYBOARD_REPORT_KEYS];
129 };
130 #ifdef NKRO_ENABLE
131 struct {
132 uint8_t mods;
133 uint8_t bits[KEYBOARD_REPORT_BITS];
134 } nkro;
135 #endif
136 } __attribute__ ((packed)) report_keyboard_t;
137 /*
138 typedef struct {
139 uint8_t mods;
140 uint8_t reserved;
141 uint8_t keys[REPORT_KEYS];
142 } __attribute__ ((packed)) report_keyboard_t;
143 */
144
145 typedef struct {
146 uint8_t buttons;
147 int8_t x;
148 int8_t y;
149 int8_t v;
150 int8_t h;
151 } __attribute__ ((packed)) report_mouse_t;
152
153
154 /* keycode to system usage */
155 #define KEYCODE2SYSTEM(key) \
156 (key == KC_SYSTEM_POWER ? SYSTEM_POWER_DOWN : \
157 (key == KC_SYSTEM_SLEEP ? SYSTEM_SLEEP : \
158 (key == KC_SYSTEM_WAKE ? SYSTEM_WAKE_UP : 0)))
159
160 /* keycode to consumer usage */
161 #define KEYCODE2CONSUMER(key) \
162 (key == KC_AUDIO_MUTE ? AUDIO_MUTE : \
163 (key == KC_AUDIO_VOL_UP ? AUDIO_VOL_UP : \
164 (key == KC_AUDIO_VOL_DOWN ? AUDIO_VOL_DOWN : \
165 (key == KC_MEDIA_NEXT_TRACK ? TRANSPORT_NEXT_TRACK : \
166 (key == KC_MEDIA_PREV_TRACK ? TRANSPORT_PREV_TRACK : \
167 (key == KC_MEDIA_FAST_FORWARD ? TRANSPORT_FAST_FORWARD : \
168 (key == KC_MEDIA_REWIND ? TRANSPORT_REWIND : \
169 (key == KC_MEDIA_STOP ? TRANSPORT_STOP : \
170 (key == KC_MEDIA_EJECT ? TRANSPORT_STOP_EJECT : \
171 (key == KC_MEDIA_PLAY_PAUSE ? TRANSPORT_PLAY_PAUSE : \
172 (key == KC_MEDIA_SELECT ? AL_CC_CONFIG : \
173 (key == KC_MAIL ? AL_EMAIL : \
174 (key == KC_CALCULATOR ? AL_CALCULATOR : \
175 (key == KC_MY_COMPUTER ? AL_LOCAL_BROWSER : \
176 (key == KC_WWW_SEARCH ? AC_SEARCH : \
177 (key == KC_WWW_HOME ? AC_HOME : \
178 (key == KC_WWW_BACK ? AC_BACK : \
179 (key == KC_WWW_FORWARD ? AC_FORWARD : \
180 (key == KC_WWW_STOP ? AC_STOP : \
181 (key == KC_WWW_REFRESH ? AC_REFRESH : \
182 (key == KC_WWW_FAVORITES ? AC_BOOKMARKS : 0)))))))))))))))))))))
183
184 #ifdef __cplusplus
185 }
186 #endif
187
188 #endif
Imprint / Impressum