![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
The preloaded firmware shipped on the mBot.
Please use the version of this project/repo found at: http://developer.mbed.org/teams/Outrageous-Circuits/code/Official_mBot/
USBDevice/USBHID/USBMouseKeyboard.cpp@0:865d42c46692, 2014-11-25 (annotated)
- Committer:
- jeffknaggs
- Date:
- Tue Nov 25 14:34:47 2014 +0000
- Revision:
- 0:865d42c46692
Initial commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jeffknaggs | 0:865d42c46692 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
jeffknaggs | 0:865d42c46692 | 2 | * |
jeffknaggs | 0:865d42c46692 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
jeffknaggs | 0:865d42c46692 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
jeffknaggs | 0:865d42c46692 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
jeffknaggs | 0:865d42c46692 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
jeffknaggs | 0:865d42c46692 | 7 | * Software is furnished to do so, subject to the following conditions: |
jeffknaggs | 0:865d42c46692 | 8 | * |
jeffknaggs | 0:865d42c46692 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
jeffknaggs | 0:865d42c46692 | 10 | * substantial portions of the Software. |
jeffknaggs | 0:865d42c46692 | 11 | * |
jeffknaggs | 0:865d42c46692 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
jeffknaggs | 0:865d42c46692 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
jeffknaggs | 0:865d42c46692 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
jeffknaggs | 0:865d42c46692 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
jeffknaggs | 0:865d42c46692 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
jeffknaggs | 0:865d42c46692 | 17 | */ |
jeffknaggs | 0:865d42c46692 | 18 | |
jeffknaggs | 0:865d42c46692 | 19 | #include "stdint.h" |
jeffknaggs | 0:865d42c46692 | 20 | #include "USBMouseKeyboard.h" |
jeffknaggs | 0:865d42c46692 | 21 | |
jeffknaggs | 0:865d42c46692 | 22 | typedef struct { |
jeffknaggs | 0:865d42c46692 | 23 | unsigned char usage; |
jeffknaggs | 0:865d42c46692 | 24 | unsigned char modifier; |
jeffknaggs | 0:865d42c46692 | 25 | } KEYMAP; |
jeffknaggs | 0:865d42c46692 | 26 | |
jeffknaggs | 0:865d42c46692 | 27 | #ifdef US_KEYBOARD |
jeffknaggs | 0:865d42c46692 | 28 | /* US keyboard (as HID standard) */ |
jeffknaggs | 0:865d42c46692 | 29 | #define KEYMAP_SIZE (152) |
jeffknaggs | 0:865d42c46692 | 30 | const KEYMAP keymap[KEYMAP_SIZE] = { |
jeffknaggs | 0:865d42c46692 | 31 | {0, 0}, /* NUL */ |
jeffknaggs | 0:865d42c46692 | 32 | {0, 0}, /* SOH */ |
jeffknaggs | 0:865d42c46692 | 33 | {0, 0}, /* STX */ |
jeffknaggs | 0:865d42c46692 | 34 | {0, 0}, /* ETX */ |
jeffknaggs | 0:865d42c46692 | 35 | {0, 0}, /* EOT */ |
jeffknaggs | 0:865d42c46692 | 36 | {0, 0}, /* ENQ */ |
jeffknaggs | 0:865d42c46692 | 37 | {0, 0}, /* ACK */ |
jeffknaggs | 0:865d42c46692 | 38 | {0, 0}, /* BEL */ |
jeffknaggs | 0:865d42c46692 | 39 | {0x2a, 0}, /* BS */ /* Keyboard Delete (Backspace) */ |
jeffknaggs | 0:865d42c46692 | 40 | {0x2b, 0}, /* TAB */ /* Keyboard Tab */ |
jeffknaggs | 0:865d42c46692 | 41 | {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */ |
jeffknaggs | 0:865d42c46692 | 42 | {0, 0}, /* VT */ |
jeffknaggs | 0:865d42c46692 | 43 | {0, 0}, /* FF */ |
jeffknaggs | 0:865d42c46692 | 44 | {0, 0}, /* CR */ |
jeffknaggs | 0:865d42c46692 | 45 | {0, 0}, /* SO */ |
jeffknaggs | 0:865d42c46692 | 46 | {0, 0}, /* SI */ |
jeffknaggs | 0:865d42c46692 | 47 | {0, 0}, /* DEL */ |
jeffknaggs | 0:865d42c46692 | 48 | {0, 0}, /* DC1 */ |
jeffknaggs | 0:865d42c46692 | 49 | {0, 0}, /* DC2 */ |
jeffknaggs | 0:865d42c46692 | 50 | {0, 0}, /* DC3 */ |
jeffknaggs | 0:865d42c46692 | 51 | {0, 0}, /* DC4 */ |
jeffknaggs | 0:865d42c46692 | 52 | {0, 0}, /* NAK */ |
jeffknaggs | 0:865d42c46692 | 53 | {0, 0}, /* SYN */ |
jeffknaggs | 0:865d42c46692 | 54 | {0, 0}, /* ETB */ |
jeffknaggs | 0:865d42c46692 | 55 | {0, 0}, /* CAN */ |
jeffknaggs | 0:865d42c46692 | 56 | {0, 0}, /* EM */ |
jeffknaggs | 0:865d42c46692 | 57 | {0, 0}, /* SUB */ |
jeffknaggs | 0:865d42c46692 | 58 | {0, 0}, /* ESC */ |
jeffknaggs | 0:865d42c46692 | 59 | {0, 0}, /* FS */ |
jeffknaggs | 0:865d42c46692 | 60 | {0, 0}, /* GS */ |
jeffknaggs | 0:865d42c46692 | 61 | {0, 0}, /* RS */ |
jeffknaggs | 0:865d42c46692 | 62 | {0, 0}, /* US */ |
jeffknaggs | 0:865d42c46692 | 63 | {0x2c, 0}, /* */ |
jeffknaggs | 0:865d42c46692 | 64 | {0x1e, KEY_SHIFT}, /* ! */ |
jeffknaggs | 0:865d42c46692 | 65 | {0x34, KEY_SHIFT}, /* " */ |
jeffknaggs | 0:865d42c46692 | 66 | {0x20, KEY_SHIFT}, /* # */ |
jeffknaggs | 0:865d42c46692 | 67 | {0x21, KEY_SHIFT}, /* $ */ |
jeffknaggs | 0:865d42c46692 | 68 | {0x22, KEY_SHIFT}, /* % */ |
jeffknaggs | 0:865d42c46692 | 69 | {0x24, KEY_SHIFT}, /* & */ |
jeffknaggs | 0:865d42c46692 | 70 | {0x34, 0}, /* ' */ |
jeffknaggs | 0:865d42c46692 | 71 | {0x26, KEY_SHIFT}, /* ( */ |
jeffknaggs | 0:865d42c46692 | 72 | {0x27, KEY_SHIFT}, /* ) */ |
jeffknaggs | 0:865d42c46692 | 73 | {0x25, KEY_SHIFT}, /* * */ |
jeffknaggs | 0:865d42c46692 | 74 | {0x2e, KEY_SHIFT}, /* + */ |
jeffknaggs | 0:865d42c46692 | 75 | {0x36, 0}, /* , */ |
jeffknaggs | 0:865d42c46692 | 76 | {0x2d, 0}, /* - */ |
jeffknaggs | 0:865d42c46692 | 77 | {0x37, 0}, /* . */ |
jeffknaggs | 0:865d42c46692 | 78 | {0x38, 0}, /* / */ |
jeffknaggs | 0:865d42c46692 | 79 | {0x27, 0}, /* 0 */ |
jeffknaggs | 0:865d42c46692 | 80 | {0x1e, 0}, /* 1 */ |
jeffknaggs | 0:865d42c46692 | 81 | {0x1f, 0}, /* 2 */ |
jeffknaggs | 0:865d42c46692 | 82 | {0x20, 0}, /* 3 */ |
jeffknaggs | 0:865d42c46692 | 83 | {0x21, 0}, /* 4 */ |
jeffknaggs | 0:865d42c46692 | 84 | {0x22, 0}, /* 5 */ |
jeffknaggs | 0:865d42c46692 | 85 | {0x23, 0}, /* 6 */ |
jeffknaggs | 0:865d42c46692 | 86 | {0x24, 0}, /* 7 */ |
jeffknaggs | 0:865d42c46692 | 87 | {0x25, 0}, /* 8 */ |
jeffknaggs | 0:865d42c46692 | 88 | {0x26, 0}, /* 9 */ |
jeffknaggs | 0:865d42c46692 | 89 | {0x33, KEY_SHIFT}, /* : */ |
jeffknaggs | 0:865d42c46692 | 90 | {0x33, 0}, /* ; */ |
jeffknaggs | 0:865d42c46692 | 91 | {0x36, KEY_SHIFT}, /* < */ |
jeffknaggs | 0:865d42c46692 | 92 | {0x2e, 0}, /* = */ |
jeffknaggs | 0:865d42c46692 | 93 | {0x37, KEY_SHIFT}, /* > */ |
jeffknaggs | 0:865d42c46692 | 94 | {0x38, KEY_SHIFT}, /* ? */ |
jeffknaggs | 0:865d42c46692 | 95 | {0x1f, KEY_SHIFT}, /* @ */ |
jeffknaggs | 0:865d42c46692 | 96 | {0x04, KEY_SHIFT}, /* A */ |
jeffknaggs | 0:865d42c46692 | 97 | {0x05, KEY_SHIFT}, /* B */ |
jeffknaggs | 0:865d42c46692 | 98 | {0x06, KEY_SHIFT}, /* C */ |
jeffknaggs | 0:865d42c46692 | 99 | {0x07, KEY_SHIFT}, /* D */ |
jeffknaggs | 0:865d42c46692 | 100 | {0x08, KEY_SHIFT}, /* E */ |
jeffknaggs | 0:865d42c46692 | 101 | {0x09, KEY_SHIFT}, /* F */ |
jeffknaggs | 0:865d42c46692 | 102 | {0x0a, KEY_SHIFT}, /* G */ |
jeffknaggs | 0:865d42c46692 | 103 | {0x0b, KEY_SHIFT}, /* H */ |
jeffknaggs | 0:865d42c46692 | 104 | {0x0c, KEY_SHIFT}, /* I */ |
jeffknaggs | 0:865d42c46692 | 105 | {0x0d, KEY_SHIFT}, /* J */ |
jeffknaggs | 0:865d42c46692 | 106 | {0x0e, KEY_SHIFT}, /* K */ |
jeffknaggs | 0:865d42c46692 | 107 | {0x0f, KEY_SHIFT}, /* L */ |
jeffknaggs | 0:865d42c46692 | 108 | {0x10, KEY_SHIFT}, /* M */ |
jeffknaggs | 0:865d42c46692 | 109 | {0x11, KEY_SHIFT}, /* N */ |
jeffknaggs | 0:865d42c46692 | 110 | {0x12, KEY_SHIFT}, /* O */ |
jeffknaggs | 0:865d42c46692 | 111 | {0x13, KEY_SHIFT}, /* P */ |
jeffknaggs | 0:865d42c46692 | 112 | {0x14, KEY_SHIFT}, /* Q */ |
jeffknaggs | 0:865d42c46692 | 113 | {0x15, KEY_SHIFT}, /* R */ |
jeffknaggs | 0:865d42c46692 | 114 | {0x16, KEY_SHIFT}, /* S */ |
jeffknaggs | 0:865d42c46692 | 115 | {0x17, KEY_SHIFT}, /* T */ |
jeffknaggs | 0:865d42c46692 | 116 | {0x18, KEY_SHIFT}, /* U */ |
jeffknaggs | 0:865d42c46692 | 117 | {0x19, KEY_SHIFT}, /* V */ |
jeffknaggs | 0:865d42c46692 | 118 | {0x1a, KEY_SHIFT}, /* W */ |
jeffknaggs | 0:865d42c46692 | 119 | {0x1b, KEY_SHIFT}, /* X */ |
jeffknaggs | 0:865d42c46692 | 120 | {0x1c, KEY_SHIFT}, /* Y */ |
jeffknaggs | 0:865d42c46692 | 121 | {0x1d, KEY_SHIFT}, /* Z */ |
jeffknaggs | 0:865d42c46692 | 122 | {0x2f, 0}, /* [ */ |
jeffknaggs | 0:865d42c46692 | 123 | {0x31, 0}, /* \ */ |
jeffknaggs | 0:865d42c46692 | 124 | {0x30, 0}, /* ] */ |
jeffknaggs | 0:865d42c46692 | 125 | {0x23, KEY_SHIFT}, /* ^ */ |
jeffknaggs | 0:865d42c46692 | 126 | {0x2d, KEY_SHIFT}, /* _ */ |
jeffknaggs | 0:865d42c46692 | 127 | {0x35, 0}, /* ` */ |
jeffknaggs | 0:865d42c46692 | 128 | {0x04, 0}, /* a */ |
jeffknaggs | 0:865d42c46692 | 129 | {0x05, 0}, /* b */ |
jeffknaggs | 0:865d42c46692 | 130 | {0x06, 0}, /* c */ |
jeffknaggs | 0:865d42c46692 | 131 | {0x07, 0}, /* d */ |
jeffknaggs | 0:865d42c46692 | 132 | {0x08, 0}, /* e */ |
jeffknaggs | 0:865d42c46692 | 133 | {0x09, 0}, /* f */ |
jeffknaggs | 0:865d42c46692 | 134 | {0x0a, 0}, /* g */ |
jeffknaggs | 0:865d42c46692 | 135 | {0x0b, 0}, /* h */ |
jeffknaggs | 0:865d42c46692 | 136 | {0x0c, 0}, /* i */ |
jeffknaggs | 0:865d42c46692 | 137 | {0x0d, 0}, /* j */ |
jeffknaggs | 0:865d42c46692 | 138 | {0x0e, 0}, /* k */ |
jeffknaggs | 0:865d42c46692 | 139 | {0x0f, 0}, /* l */ |
jeffknaggs | 0:865d42c46692 | 140 | {0x10, 0}, /* m */ |
jeffknaggs | 0:865d42c46692 | 141 | {0x11, 0}, /* n */ |
jeffknaggs | 0:865d42c46692 | 142 | {0x12, 0}, /* o */ |
jeffknaggs | 0:865d42c46692 | 143 | {0x13, 0}, /* p */ |
jeffknaggs | 0:865d42c46692 | 144 | {0x14, 0}, /* q */ |
jeffknaggs | 0:865d42c46692 | 145 | {0x15, 0}, /* r */ |
jeffknaggs | 0:865d42c46692 | 146 | {0x16, 0}, /* s */ |
jeffknaggs | 0:865d42c46692 | 147 | {0x17, 0}, /* t */ |
jeffknaggs | 0:865d42c46692 | 148 | {0x18, 0}, /* u */ |
jeffknaggs | 0:865d42c46692 | 149 | {0x19, 0}, /* v */ |
jeffknaggs | 0:865d42c46692 | 150 | {0x1a, 0}, /* w */ |
jeffknaggs | 0:865d42c46692 | 151 | {0x1b, 0}, /* x */ |
jeffknaggs | 0:865d42c46692 | 152 | {0x1c, 0}, /* y */ |
jeffknaggs | 0:865d42c46692 | 153 | {0x1d, 0}, /* z */ |
jeffknaggs | 0:865d42c46692 | 154 | {0x2f, KEY_SHIFT}, /* { */ |
jeffknaggs | 0:865d42c46692 | 155 | {0x31, KEY_SHIFT}, /* | */ |
jeffknaggs | 0:865d42c46692 | 156 | {0x30, KEY_SHIFT}, /* } */ |
jeffknaggs | 0:865d42c46692 | 157 | {0x35, KEY_SHIFT}, /* ~ */ |
jeffknaggs | 0:865d42c46692 | 158 | {0,0}, /* DEL */ |
jeffknaggs | 0:865d42c46692 | 159 | |
jeffknaggs | 0:865d42c46692 | 160 | {0x3a, 0}, /* F1 */ |
jeffknaggs | 0:865d42c46692 | 161 | {0x3b, 0}, /* F2 */ |
jeffknaggs | 0:865d42c46692 | 162 | {0x3c, 0}, /* F3 */ |
jeffknaggs | 0:865d42c46692 | 163 | {0x3d, 0}, /* F4 */ |
jeffknaggs | 0:865d42c46692 | 164 | {0x3e, 0}, /* F5 */ |
jeffknaggs | 0:865d42c46692 | 165 | {0x3f, 0}, /* F6 */ |
jeffknaggs | 0:865d42c46692 | 166 | {0x40, 0}, /* F7 */ |
jeffknaggs | 0:865d42c46692 | 167 | {0x41, 0}, /* F8 */ |
jeffknaggs | 0:865d42c46692 | 168 | {0x42, 0}, /* F9 */ |
jeffknaggs | 0:865d42c46692 | 169 | {0x43, 0}, /* F10 */ |
jeffknaggs | 0:865d42c46692 | 170 | {0x44, 0}, /* F11 */ |
jeffknaggs | 0:865d42c46692 | 171 | {0x45, 0}, /* F12 */ |
jeffknaggs | 0:865d42c46692 | 172 | |
jeffknaggs | 0:865d42c46692 | 173 | {0x46, 0}, /* PRINT_SCREEN */ |
jeffknaggs | 0:865d42c46692 | 174 | {0x47, 0}, /* SCROLL_LOCK */ |
jeffknaggs | 0:865d42c46692 | 175 | {0x39, 0}, /* CAPS_LOCK */ |
jeffknaggs | 0:865d42c46692 | 176 | {0x53, 0}, /* NUM_LOCK */ |
jeffknaggs | 0:865d42c46692 | 177 | {0x49, 0}, /* INSERT */ |
jeffknaggs | 0:865d42c46692 | 178 | {0x4a, 0}, /* HOME */ |
jeffknaggs | 0:865d42c46692 | 179 | {0x4b, 0}, /* PAGE_UP */ |
jeffknaggs | 0:865d42c46692 | 180 | {0x4e, 0}, /* PAGE_DOWN */ |
jeffknaggs | 0:865d42c46692 | 181 | |
jeffknaggs | 0:865d42c46692 | 182 | {0x4f, 0}, /* RIGHT_ARROW */ |
jeffknaggs | 0:865d42c46692 | 183 | {0x50, 0}, /* LEFT_ARROW */ |
jeffknaggs | 0:865d42c46692 | 184 | {0x51, 0}, /* DOWN_ARROW */ |
jeffknaggs | 0:865d42c46692 | 185 | {0x52, 0}, /* UP_ARROW */ |
jeffknaggs | 0:865d42c46692 | 186 | }; |
jeffknaggs | 0:865d42c46692 | 187 | |
jeffknaggs | 0:865d42c46692 | 188 | #else |
jeffknaggs | 0:865d42c46692 | 189 | /* UK keyboard */ |
jeffknaggs | 0:865d42c46692 | 190 | #define KEYMAP_SIZE (152) |
jeffknaggs | 0:865d42c46692 | 191 | const KEYMAP keymap[KEYMAP_SIZE] = { |
jeffknaggs | 0:865d42c46692 | 192 | {0, 0}, /* NUL */ |
jeffknaggs | 0:865d42c46692 | 193 | {0, 0}, /* SOH */ |
jeffknaggs | 0:865d42c46692 | 194 | {0, 0}, /* STX */ |
jeffknaggs | 0:865d42c46692 | 195 | {0, 0}, /* ETX */ |
jeffknaggs | 0:865d42c46692 | 196 | {0, 0}, /* EOT */ |
jeffknaggs | 0:865d42c46692 | 197 | {0, 0}, /* ENQ */ |
jeffknaggs | 0:865d42c46692 | 198 | {0, 0}, /* ACK */ |
jeffknaggs | 0:865d42c46692 | 199 | {0, 0}, /* BEL */ |
jeffknaggs | 0:865d42c46692 | 200 | {0x2a, 0}, /* BS */ /* Keyboard Delete (Backspace) */ |
jeffknaggs | 0:865d42c46692 | 201 | {0x2b, 0}, /* TAB */ /* Keyboard Tab */ |
jeffknaggs | 0:865d42c46692 | 202 | {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */ |
jeffknaggs | 0:865d42c46692 | 203 | {0, 0}, /* VT */ |
jeffknaggs | 0:865d42c46692 | 204 | {0, 0}, /* FF */ |
jeffknaggs | 0:865d42c46692 | 205 | {0, 0}, /* CR */ |
jeffknaggs | 0:865d42c46692 | 206 | {0, 0}, /* SO */ |
jeffknaggs | 0:865d42c46692 | 207 | {0, 0}, /* SI */ |
jeffknaggs | 0:865d42c46692 | 208 | {0, 0}, /* DEL */ |
jeffknaggs | 0:865d42c46692 | 209 | {0, 0}, /* DC1 */ |
jeffknaggs | 0:865d42c46692 | 210 | {0, 0}, /* DC2 */ |
jeffknaggs | 0:865d42c46692 | 211 | {0, 0}, /* DC3 */ |
jeffknaggs | 0:865d42c46692 | 212 | {0, 0}, /* DC4 */ |
jeffknaggs | 0:865d42c46692 | 213 | {0, 0}, /* NAK */ |
jeffknaggs | 0:865d42c46692 | 214 | {0, 0}, /* SYN */ |
jeffknaggs | 0:865d42c46692 | 215 | {0, 0}, /* ETB */ |
jeffknaggs | 0:865d42c46692 | 216 | {0, 0}, /* CAN */ |
jeffknaggs | 0:865d42c46692 | 217 | {0, 0}, /* EM */ |
jeffknaggs | 0:865d42c46692 | 218 | {0, 0}, /* SUB */ |
jeffknaggs | 0:865d42c46692 | 219 | {0, 0}, /* ESC */ |
jeffknaggs | 0:865d42c46692 | 220 | {0, 0}, /* FS */ |
jeffknaggs | 0:865d42c46692 | 221 | {0, 0}, /* GS */ |
jeffknaggs | 0:865d42c46692 | 222 | {0, 0}, /* RS */ |
jeffknaggs | 0:865d42c46692 | 223 | {0, 0}, /* US */ |
jeffknaggs | 0:865d42c46692 | 224 | {0x2c, 0}, /* */ |
jeffknaggs | 0:865d42c46692 | 225 | {0x1e, KEY_SHIFT}, /* ! */ |
jeffknaggs | 0:865d42c46692 | 226 | {0x1f, KEY_SHIFT}, /* " */ |
jeffknaggs | 0:865d42c46692 | 227 | {0x32, 0}, /* # */ |
jeffknaggs | 0:865d42c46692 | 228 | {0x21, KEY_SHIFT}, /* $ */ |
jeffknaggs | 0:865d42c46692 | 229 | {0x22, KEY_SHIFT}, /* % */ |
jeffknaggs | 0:865d42c46692 | 230 | {0x24, KEY_SHIFT}, /* & */ |
jeffknaggs | 0:865d42c46692 | 231 | {0x34, 0}, /* ' */ |
jeffknaggs | 0:865d42c46692 | 232 | {0x26, KEY_SHIFT}, /* ( */ |
jeffknaggs | 0:865d42c46692 | 233 | {0x27, KEY_SHIFT}, /* ) */ |
jeffknaggs | 0:865d42c46692 | 234 | {0x25, KEY_SHIFT}, /* * */ |
jeffknaggs | 0:865d42c46692 | 235 | {0x2e, KEY_SHIFT}, /* + */ |
jeffknaggs | 0:865d42c46692 | 236 | {0x36, 0}, /* , */ |
jeffknaggs | 0:865d42c46692 | 237 | {0x2d, 0}, /* - */ |
jeffknaggs | 0:865d42c46692 | 238 | {0x37, 0}, /* . */ |
jeffknaggs | 0:865d42c46692 | 239 | {0x38, 0}, /* / */ |
jeffknaggs | 0:865d42c46692 | 240 | {0x27, 0}, /* 0 */ |
jeffknaggs | 0:865d42c46692 | 241 | {0x1e, 0}, /* 1 */ |
jeffknaggs | 0:865d42c46692 | 242 | {0x1f, 0}, /* 2 */ |
jeffknaggs | 0:865d42c46692 | 243 | {0x20, 0}, /* 3 */ |
jeffknaggs | 0:865d42c46692 | 244 | {0x21, 0}, /* 4 */ |
jeffknaggs | 0:865d42c46692 | 245 | {0x22, 0}, /* 5 */ |
jeffknaggs | 0:865d42c46692 | 246 | {0x23, 0}, /* 6 */ |
jeffknaggs | 0:865d42c46692 | 247 | {0x24, 0}, /* 7 */ |
jeffknaggs | 0:865d42c46692 | 248 | {0x25, 0}, /* 8 */ |
jeffknaggs | 0:865d42c46692 | 249 | {0x26, 0}, /* 9 */ |
jeffknaggs | 0:865d42c46692 | 250 | {0x33, KEY_SHIFT}, /* : */ |
jeffknaggs | 0:865d42c46692 | 251 | {0x33, 0}, /* ; */ |
jeffknaggs | 0:865d42c46692 | 252 | {0x36, KEY_SHIFT}, /* < */ |
jeffknaggs | 0:865d42c46692 | 253 | {0x2e, 0}, /* = */ |
jeffknaggs | 0:865d42c46692 | 254 | {0x37, KEY_SHIFT}, /* > */ |
jeffknaggs | 0:865d42c46692 | 255 | {0x38, KEY_SHIFT}, /* ? */ |
jeffknaggs | 0:865d42c46692 | 256 | {0x34, KEY_SHIFT}, /* @ */ |
jeffknaggs | 0:865d42c46692 | 257 | {0x04, KEY_SHIFT}, /* A */ |
jeffknaggs | 0:865d42c46692 | 258 | {0x05, KEY_SHIFT}, /* B */ |
jeffknaggs | 0:865d42c46692 | 259 | {0x06, KEY_SHIFT}, /* C */ |
jeffknaggs | 0:865d42c46692 | 260 | {0x07, KEY_SHIFT}, /* D */ |
jeffknaggs | 0:865d42c46692 | 261 | {0x08, KEY_SHIFT}, /* E */ |
jeffknaggs | 0:865d42c46692 | 262 | {0x09, KEY_SHIFT}, /* F */ |
jeffknaggs | 0:865d42c46692 | 263 | {0x0a, KEY_SHIFT}, /* G */ |
jeffknaggs | 0:865d42c46692 | 264 | {0x0b, KEY_SHIFT}, /* H */ |
jeffknaggs | 0:865d42c46692 | 265 | {0x0c, KEY_SHIFT}, /* I */ |
jeffknaggs | 0:865d42c46692 | 266 | {0x0d, KEY_SHIFT}, /* J */ |
jeffknaggs | 0:865d42c46692 | 267 | {0x0e, KEY_SHIFT}, /* K */ |
jeffknaggs | 0:865d42c46692 | 268 | {0x0f, KEY_SHIFT}, /* L */ |
jeffknaggs | 0:865d42c46692 | 269 | {0x10, KEY_SHIFT}, /* M */ |
jeffknaggs | 0:865d42c46692 | 270 | {0x11, KEY_SHIFT}, /* N */ |
jeffknaggs | 0:865d42c46692 | 271 | {0x12, KEY_SHIFT}, /* O */ |
jeffknaggs | 0:865d42c46692 | 272 | {0x13, KEY_SHIFT}, /* P */ |
jeffknaggs | 0:865d42c46692 | 273 | {0x14, KEY_SHIFT}, /* Q */ |
jeffknaggs | 0:865d42c46692 | 274 | {0x15, KEY_SHIFT}, /* R */ |
jeffknaggs | 0:865d42c46692 | 275 | {0x16, KEY_SHIFT}, /* S */ |
jeffknaggs | 0:865d42c46692 | 276 | {0x17, KEY_SHIFT}, /* T */ |
jeffknaggs | 0:865d42c46692 | 277 | {0x18, KEY_SHIFT}, /* U */ |
jeffknaggs | 0:865d42c46692 | 278 | {0x19, KEY_SHIFT}, /* V */ |
jeffknaggs | 0:865d42c46692 | 279 | {0x1a, KEY_SHIFT}, /* W */ |
jeffknaggs | 0:865d42c46692 | 280 | {0x1b, KEY_SHIFT}, /* X */ |
jeffknaggs | 0:865d42c46692 | 281 | {0x1c, KEY_SHIFT}, /* Y */ |
jeffknaggs | 0:865d42c46692 | 282 | {0x1d, KEY_SHIFT}, /* Z */ |
jeffknaggs | 0:865d42c46692 | 283 | {0x2f, 0}, /* [ */ |
jeffknaggs | 0:865d42c46692 | 284 | {0x64, 0}, /* \ */ |
jeffknaggs | 0:865d42c46692 | 285 | {0x30, 0}, /* ] */ |
jeffknaggs | 0:865d42c46692 | 286 | {0x23, KEY_SHIFT}, /* ^ */ |
jeffknaggs | 0:865d42c46692 | 287 | {0x2d, KEY_SHIFT}, /* _ */ |
jeffknaggs | 0:865d42c46692 | 288 | {0x35, 0}, /* ` */ |
jeffknaggs | 0:865d42c46692 | 289 | {0x04, 0}, /* a */ |
jeffknaggs | 0:865d42c46692 | 290 | {0x05, 0}, /* b */ |
jeffknaggs | 0:865d42c46692 | 291 | {0x06, 0}, /* c */ |
jeffknaggs | 0:865d42c46692 | 292 | {0x07, 0}, /* d */ |
jeffknaggs | 0:865d42c46692 | 293 | {0x08, 0}, /* e */ |
jeffknaggs | 0:865d42c46692 | 294 | {0x09, 0}, /* f */ |
jeffknaggs | 0:865d42c46692 | 295 | {0x0a, 0}, /* g */ |
jeffknaggs | 0:865d42c46692 | 296 | {0x0b, 0}, /* h */ |
jeffknaggs | 0:865d42c46692 | 297 | {0x0c, 0}, /* i */ |
jeffknaggs | 0:865d42c46692 | 298 | {0x0d, 0}, /* j */ |
jeffknaggs | 0:865d42c46692 | 299 | {0x0e, 0}, /* k */ |
jeffknaggs | 0:865d42c46692 | 300 | {0x0f, 0}, /* l */ |
jeffknaggs | 0:865d42c46692 | 301 | {0x10, 0}, /* m */ |
jeffknaggs | 0:865d42c46692 | 302 | {0x11, 0}, /* n */ |
jeffknaggs | 0:865d42c46692 | 303 | {0x12, 0}, /* o */ |
jeffknaggs | 0:865d42c46692 | 304 | {0x13, 0}, /* p */ |
jeffknaggs | 0:865d42c46692 | 305 | {0x14, 0}, /* q */ |
jeffknaggs | 0:865d42c46692 | 306 | {0x15, 0}, /* r */ |
jeffknaggs | 0:865d42c46692 | 307 | {0x16, 0}, /* s */ |
jeffknaggs | 0:865d42c46692 | 308 | {0x17, 0}, /* t */ |
jeffknaggs | 0:865d42c46692 | 309 | {0x18, 0}, /* u */ |
jeffknaggs | 0:865d42c46692 | 310 | {0x19, 0}, /* v */ |
jeffknaggs | 0:865d42c46692 | 311 | {0x1a, 0}, /* w */ |
jeffknaggs | 0:865d42c46692 | 312 | {0x1b, 0}, /* x */ |
jeffknaggs | 0:865d42c46692 | 313 | {0x1c, 0}, /* y */ |
jeffknaggs | 0:865d42c46692 | 314 | {0x1d, 0}, /* z */ |
jeffknaggs | 0:865d42c46692 | 315 | {0x2f, KEY_SHIFT}, /* { */ |
jeffknaggs | 0:865d42c46692 | 316 | {0x64, KEY_SHIFT}, /* | */ |
jeffknaggs | 0:865d42c46692 | 317 | {0x30, KEY_SHIFT}, /* } */ |
jeffknaggs | 0:865d42c46692 | 318 | {0x32, KEY_SHIFT}, /* ~ */ |
jeffknaggs | 0:865d42c46692 | 319 | {0,0}, /* DEL */ |
jeffknaggs | 0:865d42c46692 | 320 | |
jeffknaggs | 0:865d42c46692 | 321 | {0x3a, 0}, /* F1 */ |
jeffknaggs | 0:865d42c46692 | 322 | {0x3b, 0}, /* F2 */ |
jeffknaggs | 0:865d42c46692 | 323 | {0x3c, 0}, /* F3 */ |
jeffknaggs | 0:865d42c46692 | 324 | {0x3d, 0}, /* F4 */ |
jeffknaggs | 0:865d42c46692 | 325 | {0x3e, 0}, /* F5 */ |
jeffknaggs | 0:865d42c46692 | 326 | {0x3f, 0}, /* F6 */ |
jeffknaggs | 0:865d42c46692 | 327 | {0x40, 0}, /* F7 */ |
jeffknaggs | 0:865d42c46692 | 328 | {0x41, 0}, /* F8 */ |
jeffknaggs | 0:865d42c46692 | 329 | {0x42, 0}, /* F9 */ |
jeffknaggs | 0:865d42c46692 | 330 | {0x43, 0}, /* F10 */ |
jeffknaggs | 0:865d42c46692 | 331 | {0x44, 0}, /* F11 */ |
jeffknaggs | 0:865d42c46692 | 332 | {0x45, 0}, /* F12 */ |
jeffknaggs | 0:865d42c46692 | 333 | |
jeffknaggs | 0:865d42c46692 | 334 | {0x46, 0}, /* PRINT_SCREEN */ |
jeffknaggs | 0:865d42c46692 | 335 | {0x47, 0}, /* SCROLL_LOCK */ |
jeffknaggs | 0:865d42c46692 | 336 | {0x39, 0}, /* CAPS_LOCK */ |
jeffknaggs | 0:865d42c46692 | 337 | {0x53, 0}, /* NUM_LOCK */ |
jeffknaggs | 0:865d42c46692 | 338 | {0x49, 0}, /* INSERT */ |
jeffknaggs | 0:865d42c46692 | 339 | {0x4a, 0}, /* HOME */ |
jeffknaggs | 0:865d42c46692 | 340 | {0x4b, 0}, /* PAGE_UP */ |
jeffknaggs | 0:865d42c46692 | 341 | {0x4e, 0}, /* PAGE_DOWN */ |
jeffknaggs | 0:865d42c46692 | 342 | |
jeffknaggs | 0:865d42c46692 | 343 | {0x4f, 0}, /* RIGHT_ARROW */ |
jeffknaggs | 0:865d42c46692 | 344 | {0x50, 0}, /* LEFT_ARROW */ |
jeffknaggs | 0:865d42c46692 | 345 | {0x51, 0}, /* DOWN_ARROW */ |
jeffknaggs | 0:865d42c46692 | 346 | {0x52, 0}, /* UP_ARROW */ |
jeffknaggs | 0:865d42c46692 | 347 | }; |
jeffknaggs | 0:865d42c46692 | 348 | #endif |
jeffknaggs | 0:865d42c46692 | 349 | |
jeffknaggs | 0:865d42c46692 | 350 | |
jeffknaggs | 0:865d42c46692 | 351 | uint8_t * USBMouseKeyboard::reportDesc() { |
jeffknaggs | 0:865d42c46692 | 352 | if (mouse_type == REL_MOUSE) { |
jeffknaggs | 0:865d42c46692 | 353 | static uint8_t reportDescriptor[] = { |
jeffknaggs | 0:865d42c46692 | 354 | // Keyboard |
jeffknaggs | 0:865d42c46692 | 355 | USAGE_PAGE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 356 | USAGE(1), 0x06, |
jeffknaggs | 0:865d42c46692 | 357 | COLLECTION(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 358 | REPORT_ID(1), REPORT_ID_KEYBOARD, |
jeffknaggs | 0:865d42c46692 | 359 | USAGE_PAGE(1), 0x07, |
jeffknaggs | 0:865d42c46692 | 360 | USAGE_MINIMUM(1), 0xE0, |
jeffknaggs | 0:865d42c46692 | 361 | USAGE_MAXIMUM(1), 0xE7, |
jeffknaggs | 0:865d42c46692 | 362 | LOGICAL_MINIMUM(1), 0x00, |
jeffknaggs | 0:865d42c46692 | 363 | LOGICAL_MAXIMUM(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 364 | REPORT_SIZE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 365 | REPORT_COUNT(1), 0x08, |
jeffknaggs | 0:865d42c46692 | 366 | INPUT(1), 0x02, |
jeffknaggs | 0:865d42c46692 | 367 | REPORT_COUNT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 368 | REPORT_SIZE(1), 0x08, |
jeffknaggs | 0:865d42c46692 | 369 | INPUT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 370 | REPORT_COUNT(1), 0x05, |
jeffknaggs | 0:865d42c46692 | 371 | REPORT_SIZE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 372 | USAGE_PAGE(1), 0x08, |
jeffknaggs | 0:865d42c46692 | 373 | USAGE_MINIMUM(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 374 | USAGE_MAXIMUM(1), 0x05, |
jeffknaggs | 0:865d42c46692 | 375 | OUTPUT(1), 0x02, |
jeffknaggs | 0:865d42c46692 | 376 | REPORT_COUNT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 377 | REPORT_SIZE(1), 0x03, |
jeffknaggs | 0:865d42c46692 | 378 | OUTPUT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 379 | REPORT_COUNT(1), 0x06, |
jeffknaggs | 0:865d42c46692 | 380 | REPORT_SIZE(1), 0x08, |
jeffknaggs | 0:865d42c46692 | 381 | LOGICAL_MINIMUM(1), 0x00, |
jeffknaggs | 0:865d42c46692 | 382 | LOGICAL_MAXIMUM(2), 0xff, 0x00, |
jeffknaggs | 0:865d42c46692 | 383 | USAGE_PAGE(1), 0x07, |
jeffknaggs | 0:865d42c46692 | 384 | USAGE_MINIMUM(1), 0x00, |
jeffknaggs | 0:865d42c46692 | 385 | USAGE_MAXIMUM(2), 0xff, 0x00, |
jeffknaggs | 0:865d42c46692 | 386 | INPUT(1), 0x00, |
jeffknaggs | 0:865d42c46692 | 387 | END_COLLECTION(0), |
jeffknaggs | 0:865d42c46692 | 388 | |
jeffknaggs | 0:865d42c46692 | 389 | // Mouse |
jeffknaggs | 0:865d42c46692 | 390 | USAGE_PAGE(1), 0x01, // Generic Desktop |
jeffknaggs | 0:865d42c46692 | 391 | USAGE(1), 0x02, // Mouse |
jeffknaggs | 0:865d42c46692 | 392 | COLLECTION(1), 0x01, // Application |
jeffknaggs | 0:865d42c46692 | 393 | USAGE(1), 0x01, // Pointer |
jeffknaggs | 0:865d42c46692 | 394 | COLLECTION(1), 0x00, // Physical |
jeffknaggs | 0:865d42c46692 | 395 | REPORT_ID(1), REPORT_ID_MOUSE, |
jeffknaggs | 0:865d42c46692 | 396 | REPORT_COUNT(1), 0x03, |
jeffknaggs | 0:865d42c46692 | 397 | REPORT_SIZE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 398 | USAGE_PAGE(1), 0x09, // Buttons |
jeffknaggs | 0:865d42c46692 | 399 | USAGE_MINIMUM(1), 0x1, |
jeffknaggs | 0:865d42c46692 | 400 | USAGE_MAXIMUM(1), 0x3, |
jeffknaggs | 0:865d42c46692 | 401 | LOGICAL_MINIMUM(1), 0x00, |
jeffknaggs | 0:865d42c46692 | 402 | LOGICAL_MAXIMUM(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 403 | INPUT(1), 0x02, |
jeffknaggs | 0:865d42c46692 | 404 | REPORT_COUNT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 405 | REPORT_SIZE(1), 0x05, |
jeffknaggs | 0:865d42c46692 | 406 | INPUT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 407 | REPORT_COUNT(1), 0x03, |
jeffknaggs | 0:865d42c46692 | 408 | REPORT_SIZE(1), 0x08, |
jeffknaggs | 0:865d42c46692 | 409 | USAGE_PAGE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 410 | USAGE(1), 0x30, // X |
jeffknaggs | 0:865d42c46692 | 411 | USAGE(1), 0x31, // Y |
jeffknaggs | 0:865d42c46692 | 412 | USAGE(1), 0x38, // scroll |
jeffknaggs | 0:865d42c46692 | 413 | LOGICAL_MINIMUM(1), 0x81, |
jeffknaggs | 0:865d42c46692 | 414 | LOGICAL_MAXIMUM(1), 0x7f, |
jeffknaggs | 0:865d42c46692 | 415 | INPUT(1), 0x06, |
jeffknaggs | 0:865d42c46692 | 416 | END_COLLECTION(0), |
jeffknaggs | 0:865d42c46692 | 417 | END_COLLECTION(0), |
jeffknaggs | 0:865d42c46692 | 418 | |
jeffknaggs | 0:865d42c46692 | 419 | |
jeffknaggs | 0:865d42c46692 | 420 | // Media Control |
jeffknaggs | 0:865d42c46692 | 421 | USAGE_PAGE(1), 0x0C, |
jeffknaggs | 0:865d42c46692 | 422 | USAGE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 423 | COLLECTION(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 424 | REPORT_ID(1), REPORT_ID_VOLUME, |
jeffknaggs | 0:865d42c46692 | 425 | USAGE_PAGE(1), 0x0C, |
jeffknaggs | 0:865d42c46692 | 426 | LOGICAL_MINIMUM(1), 0x00, |
jeffknaggs | 0:865d42c46692 | 427 | LOGICAL_MAXIMUM(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 428 | REPORT_SIZE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 429 | REPORT_COUNT(1), 0x07, |
jeffknaggs | 0:865d42c46692 | 430 | USAGE(1), 0xB5, // Next Track |
jeffknaggs | 0:865d42c46692 | 431 | USAGE(1), 0xB6, // Previous Track |
jeffknaggs | 0:865d42c46692 | 432 | USAGE(1), 0xB7, // Stop |
jeffknaggs | 0:865d42c46692 | 433 | USAGE(1), 0xCD, // Play / Pause |
jeffknaggs | 0:865d42c46692 | 434 | USAGE(1), 0xE2, // Mute |
jeffknaggs | 0:865d42c46692 | 435 | USAGE(1), 0xE9, // Volume Up |
jeffknaggs | 0:865d42c46692 | 436 | USAGE(1), 0xEA, // Volume Down |
jeffknaggs | 0:865d42c46692 | 437 | INPUT(1), 0x02, // Input (Data, Variable, Absolute) |
jeffknaggs | 0:865d42c46692 | 438 | REPORT_COUNT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 439 | INPUT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 440 | END_COLLECTION(0), |
jeffknaggs | 0:865d42c46692 | 441 | }; |
jeffknaggs | 0:865d42c46692 | 442 | reportLength = sizeof(reportDescriptor); |
jeffknaggs | 0:865d42c46692 | 443 | return reportDescriptor; |
jeffknaggs | 0:865d42c46692 | 444 | } else if (mouse_type == ABS_MOUSE) { |
jeffknaggs | 0:865d42c46692 | 445 | static uint8_t reportDescriptor[] = { |
jeffknaggs | 0:865d42c46692 | 446 | |
jeffknaggs | 0:865d42c46692 | 447 | // Keyboard |
jeffknaggs | 0:865d42c46692 | 448 | USAGE_PAGE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 449 | USAGE(1), 0x06, |
jeffknaggs | 0:865d42c46692 | 450 | COLLECTION(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 451 | REPORT_ID(1), REPORT_ID_KEYBOARD, |
jeffknaggs | 0:865d42c46692 | 452 | USAGE_PAGE(1), 0x07, |
jeffknaggs | 0:865d42c46692 | 453 | USAGE_MINIMUM(1), 0xE0, |
jeffknaggs | 0:865d42c46692 | 454 | USAGE_MAXIMUM(1), 0xE7, |
jeffknaggs | 0:865d42c46692 | 455 | LOGICAL_MINIMUM(1), 0x00, |
jeffknaggs | 0:865d42c46692 | 456 | LOGICAL_MAXIMUM(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 457 | REPORT_SIZE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 458 | REPORT_COUNT(1), 0x08, |
jeffknaggs | 0:865d42c46692 | 459 | INPUT(1), 0x02, |
jeffknaggs | 0:865d42c46692 | 460 | REPORT_COUNT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 461 | REPORT_SIZE(1), 0x08, |
jeffknaggs | 0:865d42c46692 | 462 | INPUT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 463 | REPORT_COUNT(1), 0x05, |
jeffknaggs | 0:865d42c46692 | 464 | REPORT_SIZE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 465 | USAGE_PAGE(1), 0x08, |
jeffknaggs | 0:865d42c46692 | 466 | USAGE_MINIMUM(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 467 | USAGE_MAXIMUM(1), 0x05, |
jeffknaggs | 0:865d42c46692 | 468 | OUTPUT(1), 0x02, |
jeffknaggs | 0:865d42c46692 | 469 | REPORT_COUNT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 470 | REPORT_SIZE(1), 0x03, |
jeffknaggs | 0:865d42c46692 | 471 | OUTPUT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 472 | REPORT_COUNT(1), 0x06, |
jeffknaggs | 0:865d42c46692 | 473 | REPORT_SIZE(1), 0x08, |
jeffknaggs | 0:865d42c46692 | 474 | LOGICAL_MINIMUM(1), 0x00, |
jeffknaggs | 0:865d42c46692 | 475 | LOGICAL_MAXIMUM(2), 0xff, 0x00, |
jeffknaggs | 0:865d42c46692 | 476 | USAGE_PAGE(1), 0x07, |
jeffknaggs | 0:865d42c46692 | 477 | USAGE_MINIMUM(1), 0x00, |
jeffknaggs | 0:865d42c46692 | 478 | USAGE_MAXIMUM(2), 0xff, 0x00, |
jeffknaggs | 0:865d42c46692 | 479 | INPUT(1), 0x00, |
jeffknaggs | 0:865d42c46692 | 480 | END_COLLECTION(0), |
jeffknaggs | 0:865d42c46692 | 481 | |
jeffknaggs | 0:865d42c46692 | 482 | // Mouse |
jeffknaggs | 0:865d42c46692 | 483 | USAGE_PAGE(1), 0x01, // Generic Desktop |
jeffknaggs | 0:865d42c46692 | 484 | USAGE(1), 0x02, // Mouse |
jeffknaggs | 0:865d42c46692 | 485 | COLLECTION(1), 0x01, // Application |
jeffknaggs | 0:865d42c46692 | 486 | USAGE(1), 0x01, // Pointer |
jeffknaggs | 0:865d42c46692 | 487 | COLLECTION(1), 0x00, // Physical |
jeffknaggs | 0:865d42c46692 | 488 | REPORT_ID(1), REPORT_ID_MOUSE, |
jeffknaggs | 0:865d42c46692 | 489 | |
jeffknaggs | 0:865d42c46692 | 490 | USAGE_PAGE(1), 0x01, // Generic Desktop |
jeffknaggs | 0:865d42c46692 | 491 | USAGE(1), 0x30, // X |
jeffknaggs | 0:865d42c46692 | 492 | USAGE(1), 0x31, // Y |
jeffknaggs | 0:865d42c46692 | 493 | LOGICAL_MINIMUM(1), 0x00, // 0 |
jeffknaggs | 0:865d42c46692 | 494 | LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767 |
jeffknaggs | 0:865d42c46692 | 495 | REPORT_SIZE(1), 0x10, |
jeffknaggs | 0:865d42c46692 | 496 | REPORT_COUNT(1), 0x02, |
jeffknaggs | 0:865d42c46692 | 497 | INPUT(1), 0x02, // Data, Variable, Absolute |
jeffknaggs | 0:865d42c46692 | 498 | |
jeffknaggs | 0:865d42c46692 | 499 | USAGE_PAGE(1), 0x01, // Generic Desktop |
jeffknaggs | 0:865d42c46692 | 500 | USAGE(1), 0x38, // scroll |
jeffknaggs | 0:865d42c46692 | 501 | LOGICAL_MINIMUM(1), 0x81, // -127 |
jeffknaggs | 0:865d42c46692 | 502 | LOGICAL_MAXIMUM(1), 0x7f, // 127 |
jeffknaggs | 0:865d42c46692 | 503 | REPORT_SIZE(1), 0x08, |
jeffknaggs | 0:865d42c46692 | 504 | REPORT_COUNT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 505 | INPUT(1), 0x06, // Data, Variable, Relative |
jeffknaggs | 0:865d42c46692 | 506 | |
jeffknaggs | 0:865d42c46692 | 507 | USAGE_PAGE(1), 0x09, // Buttons |
jeffknaggs | 0:865d42c46692 | 508 | USAGE_MINIMUM(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 509 | USAGE_MAXIMUM(1), 0x03, |
jeffknaggs | 0:865d42c46692 | 510 | LOGICAL_MINIMUM(1), 0x00, // 0 |
jeffknaggs | 0:865d42c46692 | 511 | LOGICAL_MAXIMUM(1), 0x01, // 1 |
jeffknaggs | 0:865d42c46692 | 512 | REPORT_COUNT(1), 0x03, |
jeffknaggs | 0:865d42c46692 | 513 | REPORT_SIZE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 514 | INPUT(1), 0x02, // Data, Variable, Absolute |
jeffknaggs | 0:865d42c46692 | 515 | REPORT_COUNT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 516 | REPORT_SIZE(1), 0x05, |
jeffknaggs | 0:865d42c46692 | 517 | INPUT(1), 0x01, // Constant |
jeffknaggs | 0:865d42c46692 | 518 | |
jeffknaggs | 0:865d42c46692 | 519 | END_COLLECTION(0), |
jeffknaggs | 0:865d42c46692 | 520 | END_COLLECTION(0), |
jeffknaggs | 0:865d42c46692 | 521 | |
jeffknaggs | 0:865d42c46692 | 522 | // Media Control |
jeffknaggs | 0:865d42c46692 | 523 | USAGE_PAGE(1), 0x0C, |
jeffknaggs | 0:865d42c46692 | 524 | USAGE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 525 | COLLECTION(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 526 | REPORT_ID(1), REPORT_ID_VOLUME, |
jeffknaggs | 0:865d42c46692 | 527 | USAGE_PAGE(1), 0x0C, |
jeffknaggs | 0:865d42c46692 | 528 | LOGICAL_MINIMUM(1), 0x00, |
jeffknaggs | 0:865d42c46692 | 529 | LOGICAL_MAXIMUM(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 530 | REPORT_SIZE(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 531 | REPORT_COUNT(1), 0x07, |
jeffknaggs | 0:865d42c46692 | 532 | USAGE(1), 0xB5, // Next Track |
jeffknaggs | 0:865d42c46692 | 533 | USAGE(1), 0xB6, // Previous Track |
jeffknaggs | 0:865d42c46692 | 534 | USAGE(1), 0xB7, // Stop |
jeffknaggs | 0:865d42c46692 | 535 | USAGE(1), 0xCD, // Play / Pause |
jeffknaggs | 0:865d42c46692 | 536 | USAGE(1), 0xE2, // Mute |
jeffknaggs | 0:865d42c46692 | 537 | USAGE(1), 0xE9, // Volume Up |
jeffknaggs | 0:865d42c46692 | 538 | USAGE(1), 0xEA, // Volume Down |
jeffknaggs | 0:865d42c46692 | 539 | INPUT(1), 0x02, // Input (Data, Variable, Absolute) |
jeffknaggs | 0:865d42c46692 | 540 | REPORT_COUNT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 541 | INPUT(1), 0x01, |
jeffknaggs | 0:865d42c46692 | 542 | END_COLLECTION(0), |
jeffknaggs | 0:865d42c46692 | 543 | }; |
jeffknaggs | 0:865d42c46692 | 544 | reportLength = sizeof(reportDescriptor); |
jeffknaggs | 0:865d42c46692 | 545 | return reportDescriptor; |
jeffknaggs | 0:865d42c46692 | 546 | } |
jeffknaggs | 0:865d42c46692 | 547 | |
jeffknaggs | 0:865d42c46692 | 548 | return NULL; |
jeffknaggs | 0:865d42c46692 | 549 | } |
jeffknaggs | 0:865d42c46692 | 550 | |
jeffknaggs | 0:865d42c46692 | 551 | bool USBMouseKeyboard::EP1_OUT_callback() { |
jeffknaggs | 0:865d42c46692 | 552 | uint32_t bytesRead = 0; |
jeffknaggs | 0:865d42c46692 | 553 | uint8_t led[65]; |
jeffknaggs | 0:865d42c46692 | 554 | USBDevice::readEP(EPINT_OUT, led, &bytesRead, MAX_HID_REPORT_SIZE); |
jeffknaggs | 0:865d42c46692 | 555 | |
jeffknaggs | 0:865d42c46692 | 556 | // we take led[1] because led[0] is the report ID |
jeffknaggs | 0:865d42c46692 | 557 | lock_status = led[1] & 0x07; |
jeffknaggs | 0:865d42c46692 | 558 | |
jeffknaggs | 0:865d42c46692 | 559 | // We activate the endpoint to be able to recceive data |
jeffknaggs | 0:865d42c46692 | 560 | if (!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE)) |
jeffknaggs | 0:865d42c46692 | 561 | return false; |
jeffknaggs | 0:865d42c46692 | 562 | return true; |
jeffknaggs | 0:865d42c46692 | 563 | } |
jeffknaggs | 0:865d42c46692 | 564 | |
jeffknaggs | 0:865d42c46692 | 565 | uint8_t USBMouseKeyboard::lockStatus() { |
jeffknaggs | 0:865d42c46692 | 566 | return lock_status; |
jeffknaggs | 0:865d42c46692 | 567 | } |
jeffknaggs | 0:865d42c46692 | 568 | |
jeffknaggs | 0:865d42c46692 | 569 | bool USBMouseKeyboard::update(int16_t x, int16_t y, uint8_t button, int8_t z) { |
jeffknaggs | 0:865d42c46692 | 570 | switch (mouse_type) { |
jeffknaggs | 0:865d42c46692 | 571 | case REL_MOUSE: |
jeffknaggs | 0:865d42c46692 | 572 | while (x > 127) { |
jeffknaggs | 0:865d42c46692 | 573 | if (!mouseSend(127, 0, button, z)) return false; |
jeffknaggs | 0:865d42c46692 | 574 | x = x - 127; |
jeffknaggs | 0:865d42c46692 | 575 | } |
jeffknaggs | 0:865d42c46692 | 576 | while (x < -128) { |
jeffknaggs | 0:865d42c46692 | 577 | if (!mouseSend(-128, 0, button, z)) return false; |
jeffknaggs | 0:865d42c46692 | 578 | x = x + 128; |
jeffknaggs | 0:865d42c46692 | 579 | } |
jeffknaggs | 0:865d42c46692 | 580 | while (y > 127) { |
jeffknaggs | 0:865d42c46692 | 581 | if (!mouseSend(0, 127, button, z)) return false; |
jeffknaggs | 0:865d42c46692 | 582 | y = y - 127; |
jeffknaggs | 0:865d42c46692 | 583 | } |
jeffknaggs | 0:865d42c46692 | 584 | while (y < -128) { |
jeffknaggs | 0:865d42c46692 | 585 | if (!mouseSend(0, -128, button, z)) return false; |
jeffknaggs | 0:865d42c46692 | 586 | y = y + 128; |
jeffknaggs | 0:865d42c46692 | 587 | } |
jeffknaggs | 0:865d42c46692 | 588 | return mouseSend(x, y, button, z); |
jeffknaggs | 0:865d42c46692 | 589 | case ABS_MOUSE: |
jeffknaggs | 0:865d42c46692 | 590 | HID_REPORT report; |
jeffknaggs | 0:865d42c46692 | 591 | |
jeffknaggs | 0:865d42c46692 | 592 | report.data[0] = REPORT_ID_MOUSE; |
jeffknaggs | 0:865d42c46692 | 593 | report.data[1] = x & 0xff; |
jeffknaggs | 0:865d42c46692 | 594 | report.data[2] = (x >> 8) & 0xff; |
jeffknaggs | 0:865d42c46692 | 595 | report.data[3] = y & 0xff; |
jeffknaggs | 0:865d42c46692 | 596 | report.data[4] = (y >> 8) & 0xff; |
jeffknaggs | 0:865d42c46692 | 597 | report.data[5] = -z; |
jeffknaggs | 0:865d42c46692 | 598 | report.data[6] = button & 0x07; |
jeffknaggs | 0:865d42c46692 | 599 | |
jeffknaggs | 0:865d42c46692 | 600 | report.length = 7; |
jeffknaggs | 0:865d42c46692 | 601 | |
jeffknaggs | 0:865d42c46692 | 602 | return send(&report); |
jeffknaggs | 0:865d42c46692 | 603 | default: |
jeffknaggs | 0:865d42c46692 | 604 | return false; |
jeffknaggs | 0:865d42c46692 | 605 | } |
jeffknaggs | 0:865d42c46692 | 606 | } |
jeffknaggs | 0:865d42c46692 | 607 | |
jeffknaggs | 0:865d42c46692 | 608 | bool USBMouseKeyboard::mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z) { |
jeffknaggs | 0:865d42c46692 | 609 | HID_REPORT report; |
jeffknaggs | 0:865d42c46692 | 610 | report.data[0] = REPORT_ID_MOUSE; |
jeffknaggs | 0:865d42c46692 | 611 | report.data[1] = buttons & 0x07; |
jeffknaggs | 0:865d42c46692 | 612 | report.data[2] = x; |
jeffknaggs | 0:865d42c46692 | 613 | report.data[3] = y; |
jeffknaggs | 0:865d42c46692 | 614 | report.data[4] = -z; // >0 to scroll down, <0 to scroll up |
jeffknaggs | 0:865d42c46692 | 615 | |
jeffknaggs | 0:865d42c46692 | 616 | report.length = 5; |
jeffknaggs | 0:865d42c46692 | 617 | |
jeffknaggs | 0:865d42c46692 | 618 | return send(&report); |
jeffknaggs | 0:865d42c46692 | 619 | } |
jeffknaggs | 0:865d42c46692 | 620 | |
jeffknaggs | 0:865d42c46692 | 621 | bool USBMouseKeyboard::move(int16_t x, int16_t y) { |
jeffknaggs | 0:865d42c46692 | 622 | return update(x, y, button, 0); |
jeffknaggs | 0:865d42c46692 | 623 | } |
jeffknaggs | 0:865d42c46692 | 624 | |
jeffknaggs | 0:865d42c46692 | 625 | bool USBMouseKeyboard::scroll(int8_t z) { |
jeffknaggs | 0:865d42c46692 | 626 | return update(0, 0, button, z); |
jeffknaggs | 0:865d42c46692 | 627 | } |
jeffknaggs | 0:865d42c46692 | 628 | |
jeffknaggs | 0:865d42c46692 | 629 | bool USBMouseKeyboard::doubleClick() { |
jeffknaggs | 0:865d42c46692 | 630 | if (!click(MOUSE_LEFT)) |
jeffknaggs | 0:865d42c46692 | 631 | return false; |
jeffknaggs | 0:865d42c46692 | 632 | wait(0.1); |
jeffknaggs | 0:865d42c46692 | 633 | return click(MOUSE_LEFT); |
jeffknaggs | 0:865d42c46692 | 634 | } |
jeffknaggs | 0:865d42c46692 | 635 | |
jeffknaggs | 0:865d42c46692 | 636 | bool USBMouseKeyboard::click(uint8_t button) { |
jeffknaggs | 0:865d42c46692 | 637 | if (!update(0, 0, button, 0)) |
jeffknaggs | 0:865d42c46692 | 638 | return false; |
jeffknaggs | 0:865d42c46692 | 639 | wait(0.01); |
jeffknaggs | 0:865d42c46692 | 640 | return update(0, 0, 0, 0); |
jeffknaggs | 0:865d42c46692 | 641 | } |
jeffknaggs | 0:865d42c46692 | 642 | |
jeffknaggs | 0:865d42c46692 | 643 | bool USBMouseKeyboard::press(uint8_t button_) { |
jeffknaggs | 0:865d42c46692 | 644 | button = button_ & 0x07; |
jeffknaggs | 0:865d42c46692 | 645 | return update(0, 0, button, 0); |
jeffknaggs | 0:865d42c46692 | 646 | } |
jeffknaggs | 0:865d42c46692 | 647 | |
jeffknaggs | 0:865d42c46692 | 648 | bool USBMouseKeyboard::release(uint8_t button_) { |
jeffknaggs | 0:865d42c46692 | 649 | button = (button & (~button_)) & 0x07; |
jeffknaggs | 0:865d42c46692 | 650 | return update(0, 0, button, 0); |
jeffknaggs | 0:865d42c46692 | 651 | } |
jeffknaggs | 0:865d42c46692 | 652 | |
jeffknaggs | 0:865d42c46692 | 653 | int USBMouseKeyboard::_putc(int c) { |
jeffknaggs | 0:865d42c46692 | 654 | return keyCode(c, keymap[c].modifier); |
jeffknaggs | 0:865d42c46692 | 655 | } |
jeffknaggs | 0:865d42c46692 | 656 | |
jeffknaggs | 0:865d42c46692 | 657 | bool USBMouseKeyboard::keyCode(uint8_t key, uint8_t modifier) { |
jeffknaggs | 0:865d42c46692 | 658 | // Send a simulated keyboard keypress. Returns true if successful. |
jeffknaggs | 0:865d42c46692 | 659 | |
jeffknaggs | 0:865d42c46692 | 660 | HID_REPORT report; |
jeffknaggs | 0:865d42c46692 | 661 | |
jeffknaggs | 0:865d42c46692 | 662 | report.data[0] = REPORT_ID_KEYBOARD; |
jeffknaggs | 0:865d42c46692 | 663 | report.data[1] = modifier; |
jeffknaggs | 0:865d42c46692 | 664 | report.data[2] = 0; |
jeffknaggs | 0:865d42c46692 | 665 | report.data[3] = keymap[key].usage; |
jeffknaggs | 0:865d42c46692 | 666 | report.data[4] = 0; |
jeffknaggs | 0:865d42c46692 | 667 | report.data[5] = 0; |
jeffknaggs | 0:865d42c46692 | 668 | report.data[6] = 0; |
jeffknaggs | 0:865d42c46692 | 669 | report.data[7] = 0; |
jeffknaggs | 0:865d42c46692 | 670 | report.data[8] = 0; |
jeffknaggs | 0:865d42c46692 | 671 | |
jeffknaggs | 0:865d42c46692 | 672 | report.length = 9; |
jeffknaggs | 0:865d42c46692 | 673 | |
jeffknaggs | 0:865d42c46692 | 674 | if (!send(&report)) { |
jeffknaggs | 0:865d42c46692 | 675 | return false; |
jeffknaggs | 0:865d42c46692 | 676 | } |
jeffknaggs | 0:865d42c46692 | 677 | |
jeffknaggs | 0:865d42c46692 | 678 | report.data[1] = 0; |
jeffknaggs | 0:865d42c46692 | 679 | report.data[3] = 0; |
jeffknaggs | 0:865d42c46692 | 680 | |
jeffknaggs | 0:865d42c46692 | 681 | if (!send(&report)) { |
jeffknaggs | 0:865d42c46692 | 682 | return false; |
jeffknaggs | 0:865d42c46692 | 683 | } |
jeffknaggs | 0:865d42c46692 | 684 | |
jeffknaggs | 0:865d42c46692 | 685 | return true; |
jeffknaggs | 0:865d42c46692 | 686 | |
jeffknaggs | 0:865d42c46692 | 687 | } |
jeffknaggs | 0:865d42c46692 | 688 | |
jeffknaggs | 0:865d42c46692 | 689 | |
jeffknaggs | 0:865d42c46692 | 690 | bool USBMouseKeyboard::mediaControl(MEDIA_KEY key) { |
jeffknaggs | 0:865d42c46692 | 691 | HID_REPORT report; |
jeffknaggs | 0:865d42c46692 | 692 | |
jeffknaggs | 0:865d42c46692 | 693 | report.data[0] = REPORT_ID_VOLUME; |
jeffknaggs | 0:865d42c46692 | 694 | report.data[1] = (1 << key) & 0x7f; |
jeffknaggs | 0:865d42c46692 | 695 | |
jeffknaggs | 0:865d42c46692 | 696 | report.length = 2; |
jeffknaggs | 0:865d42c46692 | 697 | |
jeffknaggs | 0:865d42c46692 | 698 | send(&report); |
jeffknaggs | 0:865d42c46692 | 699 | |
jeffknaggs | 0:865d42c46692 | 700 | report.data[0] = REPORT_ID_VOLUME; |
jeffknaggs | 0:865d42c46692 | 701 | report.data[1] = 0; |
jeffknaggs | 0:865d42c46692 | 702 | |
jeffknaggs | 0:865d42c46692 | 703 | report.length = 2; |
jeffknaggs | 0:865d42c46692 | 704 | |
jeffknaggs | 0:865d42c46692 | 705 | return send(&report); |
jeffknaggs | 0:865d42c46692 | 706 | } |