summaryrefslogtreecommitdiff
path: root/common/report.h
blob: e8582d81fafbcb83798083bbcd1c13f52faa357b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
Copyright 2011 Jun Wako <wakojun@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef REPORT_H
#define REPORT_H

#include <stdint.h>
#include <keycode.h>


/* report id */
#define REPORT_ID_MOUSE     1
#define REPORT_ID_SYSTEM    2
#define REPORT_ID_CONSUMER  3

/* mouse buttons */
#define MOUSE_BTN1 (1<<0)
#define MOUSE_BTN2 (1<<1)
#define MOUSE_BTN3 (1<<2)
#define MOUSE_BTN4 (1<<3)
#define MOUSE_BTN5 (1<<4)

// Consumer Page(0x0C)
// following are supported by Windows: http://msdn.microsoft.com/en-us/windows/hardware/gg463372.aspx
#define AUDIO_MUTE              0x00E2
#define AUDIO_VOL_UP            0x00E9
#define AUDIO_VOL_DOWN          0x00EA
#define TRANSPORT_NEXT_TRACK    0x00B5
#define TRANSPORT_PREV_TRACK    0x00B6
#define TRANSPORT_STOP          0x00B7
#define TRANSPORT_PLAY_PAUSE    0x00CD
#define AL_CC_CONFIG            0x0183
#define AL_EMAIL                0x018A
#define AL_CALCULATOR           0x0192
#define AL_LOCAL_BROWSER        0x0194
#define AC_SEARCH               0x0221
#define AC_HOME                 0x0223
#define AC_BACK                 0x0224
#define AC_FORWARD              0x0225
#define AC_STOP                 0x0226
#define AC_REFRESH              0x0227
#define AC_BOOKMARKS            0x022A
// supplement for Bluegiga iWRAP HID(not supported by Windows?)
#define AL_LOCK                 0x019E
#define TRANSPORT_RECORD        0x00B2
#define TRANSPORT_REWIND        0x00B4
#define TRANSPORT_EJECT         0x00B8
#define AC_MINIMIZE             0x0206

// Generic Desktop Page(0x01)
#define SYSTEM_POWER_DOWN       0x0081
#define SYSTEM_SLEEP            0x0082
#define SYSTEM_WAKE_UP          0x0083


// key report size(NKRO or boot mode)
#if defined(HOST_PJRC)
#   include "usb.h"
#   if defined(KBD2_REPORT_KEYS) && KBD2_REPORT_KEYS > KBD_REPORT_KEYS
#       define REPORT_KEYS KBD2_REPORT_KEYS
#   else
#       define REPORT_KEYS KBD_REPORT_KEYS
#   endif
#else
#   define REPORT_KEYS 6
#endif


#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
    uint8_t mods;
    uint8_t rserved;
    uint8_t keys[REPORT_KEYS];
} __attribute__ ((packed)) report_keyboard_t;

typedef struct {
    uint8_t buttons;
    int8_t x;
    int8_t y;
    int8_t v;
    int8_t h;
} __attribute__ ((packed)) report_mouse_t;


static uint16_t key2system(uint8_t key)
{
    uint16_t usage = 0;
    switch (key) {
        case KC_SYSTEM_POWER:
            usage = SYSTEM_POWER_DOWN;
            break;
        case KC_SYSTEM_SLEEP:
            usage = SYSTEM_SLEEP;
            break;
        case KC_SYSTEM_WAKE:
            usage = SYSTEM_WAKE_UP;
            break;
    }
    return usage;
}

static uint16_t key2consumer(uint8_t key)
{
    uint16_t usage = 0;
    switch (key) {
        case KC_AUDIO_MUTE:
            usage = AUDIO_MUTE;
            break;
        case KC_AUDIO_VOL_UP:
            usage = AUDIO_VOL_UP;
            break;
        case KC_AUDIO_VOL_DOWN:
            usage = AUDIO_VOL_DOWN;
            break;
        case KC_MEDIA_NEXT_TRACK:
            usage = TRANSPORT_NEXT_TRACK;
            break;
        case KC_MEDIA_PREV_TRACK:
            usage = TRANSPORT_PREV_TRACK;
            break;
        case KC_MEDIA_STOP:
            usage = TRANSPORT_STOP;
            break;
        case KC_MEDIA_PLAY_PAUSE:
            usage = TRANSPORT_PLAY_PAUSE;
            break;
        case KC_MEDIA_SELECT:
            usage = AL_CC_CONFIG;
            break;
        case KC_MAIL:
            usage = AL_EMAIL;
            break;
        case KC_CALCULATOR:
            usage = AL_CALCULATOR;
            break;
        case KC_MY_COMPUTER:
            usage = AL_LOCAL_BROWSER;
            break;
        case KC_WWW_SEARCH:
            usage = AC_SEARCH;
            break;
        case KC_WWW_HOME:
            usage = AC_HOME;
            break;
        case KC_WWW_BACK:
            usage = AC_BACK;
            break;
        case KC_WWW_FORWARD:
            usage = AC_FORWARD;
            break;
        case KC_WWW_STOP:
            usage = AC_STOP;
            break;
        case KC_WWW_REFRESH:
            usage = AC_REFRESH;
            break;
        case KC_WWW_FAVORITES:
            usage = AC_BOOKMARKS;
            break;
    }
    return usage;
}

#ifdef __cplusplus
}
#endif

#endif