1 /******************************************************************************
2  *
3  *  Copyright (C) 2009-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #ifndef __UINPUT_H
20 #define __UINPUT_H
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include <stdint.h>
27 #include <sys/time.h>
28 #include <sys/ioctl.h>
29 
30 /*******************************************************************************
31 **  Constants & Macros
32 ********************************************************************************/
33 
34 /* Events */
35 
36 #define EV_SYN          0x00
37 #define EV_KEY          0x01
38 #define EV_REL          0x02
39 #define EV_ABS          0x03
40 #define EV_MSC          0x04
41 #define EV_LED          0x11
42 #define EV_SND          0x12
43 #define EV_REP          0x14
44 #define EV_FF           0x15
45 #define EV_PWR          0x16
46 #define EV_FF_STATUS        0x17
47 #define EV_MAX          0x1f
48 
49 /* Synchronization events */
50 
51 #define SYN_REPORT      0
52 #define SYN_CONFIG      1
53 
54 /* Keys and buttons */
55 
56 #define KEY_RESERVED        0
57 #define KEY_ESC         1
58 #define KEY_1           2
59 #define KEY_2           3
60 #define KEY_3           4
61 #define KEY_4           5
62 #define KEY_5           6
63 #define KEY_6           7
64 #define KEY_7           8
65 #define KEY_8           9
66 #define KEY_9           10
67 #define KEY_0           11
68 #define KEY_MINUS       12
69 #define KEY_EQUAL       13
70 #define KEY_BACKSPACE       14
71 #define KEY_TAB         15
72 #define KEY_Q           16
73 #define KEY_W           17
74 #define KEY_E           18
75 #define KEY_R           19
76 #define KEY_T           20
77 #define KEY_Y           21
78 #define KEY_U           22
79 #define KEY_I           23
80 #define KEY_O           24
81 #define KEY_P           25
82 #define KEY_LEFTBRACE       26
83 #define KEY_RIGHTBRACE      27
84 #define KEY_ENTER       28
85 #define KEY_LEFTCTRL        29
86 #define KEY_A           30
87 #define KEY_S           31
88 #define KEY_D           32
89 #define KEY_F           33
90 #define KEY_G           34
91 #define KEY_H           35
92 #define KEY_J           36
93 #define KEY_K           37
94 #define KEY_L           38
95 #define KEY_SEMICOLON       39
96 #define KEY_APOSTROPHE      40
97 #define KEY_GRAVE       41
98 #define KEY_LEFTSHIFT       42
99 #define KEY_BACKSLASH       43
100 #define KEY_Z           44
101 #define KEY_X           45
102 #define KEY_C           46
103 #define KEY_V           47
104 #define KEY_B           48
105 #define KEY_N           49
106 #define KEY_M           50
107 #define KEY_COMMA       51
108 #define KEY_DOT         52
109 #define KEY_SLASH       53
110 #define KEY_RIGHTSHIFT      54
111 #define KEY_KPASTERISK      55
112 #define KEY_LEFTALT     56
113 #define KEY_SPACE       57
114 #define KEY_CAPSLOCK        58
115 #define KEY_F1          59
116 #define KEY_F2          60
117 #define KEY_F3          61
118 #define KEY_F4          62
119 #define KEY_F5          63
120 #define KEY_F6          64
121 #define KEY_F7          65
122 #define KEY_F8          66
123 #define KEY_F9          67
124 #define KEY_F10         68
125 #define KEY_NUMLOCK     69
126 #define KEY_SCROLLLOCK      70
127 #define KEY_KP7         71
128 #define KEY_KP8         72
129 #define KEY_KP9         73
130 #define KEY_KPMINUS     74
131 #define KEY_KP4         75
132 #define KEY_KP5         76
133 #define KEY_KP6         77
134 #define KEY_KPPLUS      78
135 #define KEY_KP1         79
136 #define KEY_KP2         80
137 #define KEY_KP3         81
138 #define KEY_KP0         82
139 #define KEY_KPDOT       83
140 #define KEY_103RD       84
141 #define KEY_F13         85
142 #define KEY_102ND       86
143 #define KEY_F11         87
144 #define KEY_F12         88
145 #define KEY_F14         89
146 #define KEY_F15         90
147 #define KEY_F16         91
148 #define KEY_F17         92
149 #define KEY_F18         93
150 #define KEY_F19         94
151 #define KEY_F20         95
152 #define KEY_KPENTER     96
153 #define KEY_RIGHTCTRL       97
154 #define KEY_KPSLASH     98
155 #define KEY_SYSRQ       99
156 #define KEY_RIGHTALT        100
157 #define KEY_LINEFEED        101
158 #define KEY_HOME        102
159 #define KEY_UP          103
160 #define KEY_PAGEUP      104
161 #define KEY_LEFT        105
162 #define KEY_RIGHT       106
163 #define KEY_END         107
164 #define KEY_DOWN        108
165 #define KEY_PAGEDOWN        109
166 #define KEY_INSERT      110
167 #define KEY_DELETE      111
168 #define KEY_MACRO       112
169 #define KEY_MUTE        113
170 #define KEY_VOLUMEDOWN      114
171 #define KEY_VOLUMEUP        115
172 #define KEY_POWER       116
173 #define KEY_KPEQUAL     117
174 #define KEY_KPPLUSMINUS     118
175 #define KEY_PAUSE       119
176 #define KEY_F21         120
177 #define KEY_F22         121
178 #define KEY_F23         122
179 #define KEY_F24         123
180 #define KEY_KPCOMMA     124
181 #define KEY_LEFTMETA        125
182 #define KEY_RIGHTMETA       126
183 #define KEY_COMPOSE     127
184 
185 #define KEY_STOP        128
186 #define KEY_AGAIN       129
187 #define KEY_PROPS       130
188 #define KEY_UNDO        131
189 #define KEY_FRONT       132
190 #define KEY_COPY        133
191 #define KEY_OPEN        134
192 #define KEY_PASTE       135
193 #define KEY_FIND        136
194 #define KEY_CUT         137
195 #define KEY_HELP        138
196 #define KEY_MENU        139
197 #define KEY_CALC        140
198 #define KEY_SETUP       141
199 #define KEY_SLEEP       142
200 #define KEY_WAKEUP      143
201 #define KEY_FILE        144
202 #define KEY_SENDFILE        145
203 #define KEY_DELETEFILE      146
204 #define KEY_XFER        147
205 #define KEY_PROG1       148
206 #define KEY_PROG2       149
207 #define KEY_WWW         150
208 #define KEY_MSDOS       151
209 #define KEY_COFFEE      152
210 #define KEY_DIRECTION       153
211 #define KEY_CYCLEWINDOWS    154
212 #define KEY_MAIL        155
213 #define KEY_BOOKMARKS       156
214 #define KEY_COMPUTER        157
215 #define KEY_BACK        158
216 #define KEY_FORWARD     159
217 #define KEY_CLOSECD     160
218 #define KEY_EJECTCD     161
219 #define KEY_EJECTCLOSECD    162
220 #define KEY_NEXTSONG        163
221 #define KEY_PLAYPAUSE       164
222 #define KEY_PREVIOUSSONG    165
223 #define KEY_STOPCD      166
224 #define KEY_RECORD      167
225 #define KEY_REWIND      168
226 #define KEY_PHONE       169
227 #define KEY_ISO         170
228 #define KEY_CONFIG      171
229 #define KEY_HOMEPAGE        172
230 #define KEY_REFRESH     173
231 #define KEY_EXIT        174
232 #define KEY_MOVE        175
233 #define KEY_EDIT        176
234 #define KEY_SCROLLUP        177
235 #define KEY_SCROLLDOWN      178
236 #define KEY_KPLEFTPAREN     179
237 #define KEY_KPRIGHTPAREN    180
238 
239 #define KEY_INTL1       181
240 #define KEY_INTL2       182
241 #define KEY_INTL3       183
242 #define KEY_INTL4       184
243 #define KEY_INTL5       185
244 #define KEY_INTL6       186
245 #define KEY_INTL7       187
246 #define KEY_INTL8       188
247 #define KEY_INTL9       189
248 #define KEY_LANG1       190
249 #define KEY_LANG2       191
250 #define KEY_LANG3       192
251 #define KEY_LANG4       193
252 #define KEY_LANG5       194
253 #define KEY_LANG6       195
254 #define KEY_LANG7       196
255 #define KEY_LANG8       197
256 #define KEY_LANG9       198
257 
258 #define KEY_PLAYCD      200
259 #define KEY_PAUSECD     201
260 #define KEY_PROG3       202
261 #define KEY_PROG4       203
262 #define KEY_SUSPEND     205
263 #define KEY_CLOSE       206
264 #define KEY_PLAY        207
265 #define KEY_FAST_FORWARD  208
266 
267 #define KEY_UNKNOWN     220
268 
269 #define KEY_BRIGHTNESSDOWN  224
270 #define KEY_BRIGHTNESSUP    225
271 
272 #define BTN_MISC        0x100
273 #define BTN_0           0x100
274 #define BTN_1           0x101
275 #define BTN_2           0x102
276 #define BTN_3           0x103
277 #define BTN_4           0x104
278 #define BTN_5           0x105
279 #define BTN_6           0x106
280 #define BTN_7           0x107
281 #define BTN_8           0x108
282 #define BTN_9           0x109
283 
284 #define BTN_MOUSE       0x110
285 #define BTN_LEFT        0x110
286 #define BTN_RIGHT       0x111
287 #define BTN_MIDDLE      0x112
288 #define BTN_SIDE        0x113
289 #define BTN_EXTRA       0x114
290 #define BTN_FORWARD     0x115
291 #define BTN_BACK        0x116
292 #define BTN_TASK        0x117
293 
294 #define BTN_JOYSTICK        0x120
295 #define BTN_TRIGGER     0x120
296 #define BTN_THUMB       0x121
297 #define BTN_THUMB2      0x122
298 #define BTN_TOP         0x123
299 #define BTN_TOP2        0x124
300 #define BTN_PINKIE      0x125
301 #define BTN_BASE        0x126
302 #define BTN_BASE2       0x127
303 #define BTN_BASE3       0x128
304 #define BTN_BASE4       0x129
305 #define BTN_BASE5       0x12a
306 #define BTN_BASE6       0x12b
307 #define BTN_DEAD        0x12f
308 
309 #define BTN_GAMEPAD     0x130
310 #define BTN_A           0x130
311 #define BTN_B           0x131
312 #define BTN_C           0x132
313 #define BTN_X           0x133
314 #define BTN_Y           0x134
315 #define BTN_Z           0x135
316 #define BTN_TL          0x136
317 #define BTN_TR          0x137
318 #define BTN_TL2         0x138
319 #define BTN_TR2         0x139
320 #define BTN_SELECT      0x13a
321 #define BTN_START       0x13b
322 #define BTN_MODE        0x13c
323 #define BTN_THUMBL      0x13d
324 #define BTN_THUMBR      0x13e
325 
326 #define BTN_DIGI        0x140
327 #define BTN_TOOL_PEN        0x140
328 #define BTN_TOOL_RUBBER     0x141
329 #define BTN_TOOL_BRUSH      0x142
330 #define BTN_TOOL_PENCIL     0x143
331 #define BTN_TOOL_AIRBRUSH   0x144
332 #define BTN_TOOL_FINGER     0x145
333 #define BTN_TOOL_MOUSE      0x146
334 #define BTN_TOOL_LENS       0x147
335 #define BTN_TOUCH       0x14a
336 #define BTN_STYLUS      0x14b
337 #define BTN_STYLUS2     0x14c
338 #define BTN_TOOL_DOUBLETAP  0x14d
339 #define BTN_TOOL_TRIPLETAP  0x14e
340 
341 #define BTN_WHEEL       0x150
342 #define BTN_GEAR_DOWN       0x150
343 #define BTN_GEAR_UP     0x151
344 
345 #define KEY_OK          0x160
346 #define KEY_SELECT      0x161
347 #define KEY_GOTO        0x162
348 #define KEY_CLEAR       0x163
349 #define KEY_POWER2      0x164
350 #define KEY_OPTION      0x165
351 #define KEY_INFO        0x166
352 #define KEY_TIME        0x167
353 #define KEY_VENDOR      0x168
354 #define KEY_ARCHIVE     0x169
355 #define KEY_PROGRAM     0x16a
356 #define KEY_CHANNEL     0x16b
357 #define KEY_FAVORITES       0x16c
358 #define KEY_EPG         0x16d
359 #define KEY_PVR         0x16e
360 #define KEY_MHP         0x16f
361 #define KEY_LANGUAGE        0x170
362 #define KEY_TITLE       0x171
363 #define KEY_SUBTITLE        0x172
364 #define KEY_ANGLE       0x173
365 #define KEY_ZOOM        0x174
366 #define KEY_MODE        0x175
367 #define KEY_KEYBOARD        0x176
368 #define KEY_SCREEN      0x177
369 #define KEY_PC          0x178
370 #define KEY_TV          0x179
371 #define KEY_TV2         0x17a
372 #define KEY_VCR         0x17b
373 #define KEY_VCR2        0x17c
374 #define KEY_SAT         0x17d
375 #define KEY_SAT2        0x17e
376 #define KEY_CD          0x17f
377 #define KEY_TAPE        0x180
378 #define KEY_RADIO       0x181
379 #define KEY_TUNER       0x182
380 #define KEY_PLAYER      0x183
381 #define KEY_TEXT        0x184
382 #define KEY_DVD         0x185
383 #define KEY_AUX         0x186
384 #define KEY_MP3         0x187
385 #define KEY_AUDIO       0x188
386 #define KEY_VIDEO       0x189
387 #define KEY_DIRECTORY       0x18a
388 #define KEY_LIST        0x18b
389 #define KEY_MEMO        0x18c
390 #define KEY_CALENDAR        0x18d
391 #define KEY_RED         0x18e
392 #define KEY_GREEN       0x18f
393 #define KEY_YELLOW      0x190
394 #define KEY_BLUE        0x191
395 #define KEY_CHANNELUP       0x192
396 #define KEY_CHANNELDOWN     0x193
397 #define KEY_FIRST       0x194
398 #define KEY_LAST        0x195
399 #define KEY_AB          0x196
400 #define KEY_NEXT        0x197
401 #define KEY_RESTART     0x198
402 #define KEY_SLOW        0x199
403 #define KEY_SHUFFLE     0x19a
404 #define KEY_BREAK       0x19b
405 #define KEY_PREVIOUS        0x19c
406 #define KEY_DIGITS      0x19d
407 #define KEY_TEEN        0x19e
408 #define KEY_TWEN        0x19f
409 
410 #define KEY_FRAMEBACK       0x1b2
411 #define KEY_FRAMEFORWARD    0x1b3
412 #define KEY_CONTEXT_MENU    0x1fb
413 
414 #define KEY_MAX         0x1ff
415 
416 /* Relative axes */
417 
418 #define REL_X           0x00
419 #define REL_Y           0x01
420 #define REL_Z           0x02
421 #define REL_RX          0x03
422 #define REL_RY          0x04
423 #define REL_RZ          0x05
424 #define REL_HWHEEL      0x06
425 #define REL_DIAL        0x07
426 #define REL_WHEEL       0x08
427 #define REL_MISC        0x09
428 #define REL_MAX         0x0f
429 
430 /* Absolute axes */
431 
432 #define ABS_X           0x00
433 #define ABS_Y           0x01
434 #define ABS_Z           0x02
435 #define ABS_RX          0x03
436 #define ABS_RY          0x04
437 #define ABS_RZ          0x05
438 #define ABS_THROTTLE        0x06
439 #define ABS_RUDDER      0x07
440 #define ABS_WHEEL       0x08
441 #define ABS_GAS         0x09
442 #define ABS_BRAKE       0x0a
443 #define ABS_HAT0X       0x10
444 #define ABS_HAT0Y       0x11
445 #define ABS_HAT1X       0x12
446 #define ABS_HAT1Y       0x13
447 #define ABS_HAT2X       0x14
448 #define ABS_HAT2Y       0x15
449 #define ABS_HAT3X       0x16
450 #define ABS_HAT3Y       0x17
451 #define ABS_PRESSURE        0x18
452 #define ABS_DISTANCE        0x19
453 #define ABS_TILT_X      0x1a
454 #define ABS_TILT_Y      0x1b
455 #define ABS_TOOL_WIDTH      0x1c
456 #define ABS_VOLUME      0x20
457 #define ABS_MISC        0x28
458 #define ABS_MAX         0x3f
459 
460 /* Switch events */
461 
462 #define SW_0            0x00
463 #define SW_1            0x01
464 #define SW_2            0x02
465 #define SW_3            0x03
466 #define SW_4            0x04
467 #define SW_5            0x05
468 #define SW_6            0x06
469 #define SW_7            0x07
470 #define SW_MAX          0x0f
471 
472 /* Misc events */
473 
474 #define MSC_SERIAL      0x00
475 #define MSC_PULSELED        0x01
476 #define MSC_GESTURE     0x02
477 #define MSC_RAW         0x03
478 #define MSC_SCAN        0x04
479 #define MSC_MAX         0x07
480 
481 /* LEDs */
482 
483 #define LED_NUML        0x00
484 #define LED_CAPSL       0x01
485 #define LED_SCROLLL     0x02
486 #define LED_COMPOSE     0x03
487 #define LED_KANA        0x04
488 #define LED_SLEEP       0x05
489 #define LED_SUSPEND     0x06
490 #define LED_MUTE        0x07
491 #define LED_MISC        0x08
492 #define LED_MAIL        0x09
493 #define LED_CHARGING        0x0a
494 #define LED_MAX         0x0f
495 
496 /* Autorepeat values */
497 
498 #define REP_DELAY       0x00
499 #define REP_PERIOD      0x01
500 #define REP_MAX         0x01
501 
502 /* Sounds */
503 
504 #define SND_CLICK       0x00
505 #define SND_BELL        0x01
506 #define SND_TONE        0x02
507 #define SND_MAX         0x07
508 
509 /* Identifiers */
510 
511 #define ID_BUS          0
512 #define ID_VENDOR       1
513 #define ID_PRODUCT      2
514 #define ID_VERSION      3
515 
516 #define BUS_PCI         0x01
517 #define BUS_ISAPNP      0x02
518 #define BUS_USB         0x03
519 #define BUS_HIL         0x04
520 #define BUS_BLUETOOTH       0x05
521 
522 #define BUS_ISA         0x10
523 #define BUS_I8042       0x11
524 #define BUS_XTKBD       0x12
525 #define BUS_RS232       0x13
526 #define BUS_GAMEPORT        0x14
527 #define BUS_PARPORT     0x15
528 #define BUS_AMIGA       0x16
529 #define BUS_ADB         0x17
530 #define BUS_I2C         0x18
531 #define BUS_HOST        0x19
532 #define BUS_GSC         0x1A
533 
534 /* User input interface */
535 
536 #define UINPUT_IOCTL_BASE   'U'
537 
538 #define UI_DEV_CREATE       _IO(UINPUT_IOCTL_BASE, 1)
539 #define UI_DEV_DESTROY      _IO(UINPUT_IOCTL_BASE, 2)
540 
541 #define UI_SET_EVBIT        _IOW(UINPUT_IOCTL_BASE, 100, int)
542 #define UI_SET_KEYBIT       _IOW(UINPUT_IOCTL_BASE, 101, int)
543 #define UI_SET_RELBIT       _IOW(UINPUT_IOCTL_BASE, 102, int)
544 #define UI_SET_ABSBIT       _IOW(UINPUT_IOCTL_BASE, 103, int)
545 #define UI_SET_MSCBIT       _IOW(UINPUT_IOCTL_BASE, 104, int)
546 #define UI_SET_LEDBIT       _IOW(UINPUT_IOCTL_BASE, 105, int)
547 #define UI_SET_SNDBIT       _IOW(UINPUT_IOCTL_BASE, 106, int)
548 #define UI_SET_FFBIT        _IOW(UINPUT_IOCTL_BASE, 107, int)
549 #define UI_SET_PHYS     _IOW(UINPUT_IOCTL_BASE, 108, char*)
550 #define UI_SET_SWBIT        _IOW(UINPUT_IOCTL_BASE, 109, int)
551 
552 #ifndef NBITS
553 #define NBITS(x) ((((x) - 1) / (sizeof(long) * 8)) + 1)
554 #endif
555 
556 #define UINPUT_MAX_NAME_SIZE    80
557 
558 
559 /*******************************************************************************
560 **  Type definitions and return values
561 ********************************************************************************/
562 
563 struct uinput_id {
564     uint16_t bustype;
565     uint16_t vendor;
566     uint16_t product;
567     uint16_t version;
568 };
569 
570 struct uinput_dev {
571     char name[UINPUT_MAX_NAME_SIZE];
572     struct uinput_id id;
573     int ff_effects_max;
574     int absmax[ABS_MAX + 1];
575     int absmin[ABS_MAX + 1];
576     int absfuzz[ABS_MAX + 1];
577     int absflat[ABS_MAX + 1];
578 };
579 
580 struct uinput_event {
581     struct timeval time;
582     uint16_t type;
583     uint16_t code;
584     int32_t value;
585 };
586 
587 #ifdef __cplusplus
588 }
589 #endif
590 
591 #endif /* __UINPUT_H */
592