![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Slingshot Controller
Dependencies: ADXL345 DebounceIn USBDevice mbed
USBDevice/USBHID/USBKeyboard.cpp@1:2721dc2acc2c, 2012-10-17 (annotated)
- Committer:
- Brandon
- Date:
- Wed Oct 17 16:33:04 2012 +0000
- Revision:
- 1:2721dc2acc2c
- Parent:
- 0:cf17ea89fd09
Updated comments, added names, cleaned old code.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Brandon | 0:cf17ea89fd09 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
Brandon | 0:cf17ea89fd09 | 2 | * |
Brandon | 0:cf17ea89fd09 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
Brandon | 0:cf17ea89fd09 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
Brandon | 0:cf17ea89fd09 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
Brandon | 0:cf17ea89fd09 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
Brandon | 0:cf17ea89fd09 | 7 | * Software is furnished to do so, subject to the following conditions: |
Brandon | 0:cf17ea89fd09 | 8 | * |
Brandon | 0:cf17ea89fd09 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
Brandon | 0:cf17ea89fd09 | 10 | * substantial portions of the Software. |
Brandon | 0:cf17ea89fd09 | 11 | * |
Brandon | 0:cf17ea89fd09 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
Brandon | 0:cf17ea89fd09 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
Brandon | 0:cf17ea89fd09 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
Brandon | 0:cf17ea89fd09 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Brandon | 0:cf17ea89fd09 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Brandon | 0:cf17ea89fd09 | 17 | */ |
Brandon | 0:cf17ea89fd09 | 18 | |
Brandon | 0:cf17ea89fd09 | 19 | #include "stdint.h" |
Brandon | 0:cf17ea89fd09 | 20 | |
Brandon | 0:cf17ea89fd09 | 21 | #include "USBKeyboard.h" |
Brandon | 0:cf17ea89fd09 | 22 | |
Brandon | 0:cf17ea89fd09 | 23 | #define REPORT_ID_KEYBOARD 1 |
Brandon | 0:cf17ea89fd09 | 24 | #define REPORT_ID_VOLUME 3 |
Brandon | 0:cf17ea89fd09 | 25 | |
Brandon | 0:cf17ea89fd09 | 26 | |
Brandon | 0:cf17ea89fd09 | 27 | typedef struct { |
Brandon | 0:cf17ea89fd09 | 28 | unsigned char usage; |
Brandon | 0:cf17ea89fd09 | 29 | unsigned char modifier; |
Brandon | 0:cf17ea89fd09 | 30 | } KEYMAP; |
Brandon | 0:cf17ea89fd09 | 31 | |
Brandon | 0:cf17ea89fd09 | 32 | #ifdef US_KEYBOARD |
Brandon | 0:cf17ea89fd09 | 33 | /* US keyboard (as HID standard) */ |
Brandon | 0:cf17ea89fd09 | 34 | #define KEYMAP_SIZE (152) |
Brandon | 0:cf17ea89fd09 | 35 | const KEYMAP keymap[KEYMAP_SIZE] = { |
Brandon | 0:cf17ea89fd09 | 36 | {0, 0}, /* NUL */ |
Brandon | 0:cf17ea89fd09 | 37 | {0, 0}, /* SOH */ |
Brandon | 0:cf17ea89fd09 | 38 | {0, 0}, /* STX */ |
Brandon | 0:cf17ea89fd09 | 39 | {0, 0}, /* ETX */ |
Brandon | 0:cf17ea89fd09 | 40 | {0, 0}, /* EOT */ |
Brandon | 0:cf17ea89fd09 | 41 | {0, 0}, /* ENQ */ |
Brandon | 0:cf17ea89fd09 | 42 | {0, 0}, /* ACK */ |
Brandon | 0:cf17ea89fd09 | 43 | {0, 0}, /* BEL */ |
Brandon | 0:cf17ea89fd09 | 44 | {0x2a, 0}, /* BS */ /* Keyboard Delete (Backspace) */ |
Brandon | 0:cf17ea89fd09 | 45 | {0x2b, 0}, /* TAB */ /* Keyboard Tab */ |
Brandon | 0:cf17ea89fd09 | 46 | {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */ |
Brandon | 0:cf17ea89fd09 | 47 | {0, 0}, /* VT */ |
Brandon | 0:cf17ea89fd09 | 48 | {0, 0}, /* FF */ |
Brandon | 0:cf17ea89fd09 | 49 | {0, 0}, /* CR */ |
Brandon | 0:cf17ea89fd09 | 50 | {0, 0}, /* SO */ |
Brandon | 0:cf17ea89fd09 | 51 | {0, 0}, /* SI */ |
Brandon | 0:cf17ea89fd09 | 52 | {0, 0}, /* DEL */ |
Brandon | 0:cf17ea89fd09 | 53 | {0, 0}, /* DC1 */ |
Brandon | 0:cf17ea89fd09 | 54 | {0, 0}, /* DC2 */ |
Brandon | 0:cf17ea89fd09 | 55 | {0, 0}, /* DC3 */ |
Brandon | 0:cf17ea89fd09 | 56 | {0, 0}, /* DC4 */ |
Brandon | 0:cf17ea89fd09 | 57 | {0, 0}, /* NAK */ |
Brandon | 0:cf17ea89fd09 | 58 | {0, 0}, /* SYN */ |
Brandon | 0:cf17ea89fd09 | 59 | {0, 0}, /* ETB */ |
Brandon | 0:cf17ea89fd09 | 60 | {0, 0}, /* CAN */ |
Brandon | 0:cf17ea89fd09 | 61 | {0, 0}, /* EM */ |
Brandon | 0:cf17ea89fd09 | 62 | {0, 0}, /* SUB */ |
Brandon | 0:cf17ea89fd09 | 63 | {0, 0}, /* ESC */ |
Brandon | 0:cf17ea89fd09 | 64 | {0, 0}, /* FS */ |
Brandon | 0:cf17ea89fd09 | 65 | {0, 0}, /* GS */ |
Brandon | 0:cf17ea89fd09 | 66 | {0, 0}, /* RS */ |
Brandon | 0:cf17ea89fd09 | 67 | {0, 0}, /* US */ |
Brandon | 0:cf17ea89fd09 | 68 | {0x2c, 0}, /* */ |
Brandon | 0:cf17ea89fd09 | 69 | {0x1e, KEY_SHIFT}, /* ! */ |
Brandon | 0:cf17ea89fd09 | 70 | {0x34, KEY_SHIFT}, /* " */ |
Brandon | 0:cf17ea89fd09 | 71 | {0x20, KEY_SHIFT}, /* # */ |
Brandon | 0:cf17ea89fd09 | 72 | {0x21, KEY_SHIFT}, /* $ */ |
Brandon | 0:cf17ea89fd09 | 73 | {0x22, KEY_SHIFT}, /* % */ |
Brandon | 0:cf17ea89fd09 | 74 | {0x24, KEY_SHIFT}, /* & */ |
Brandon | 0:cf17ea89fd09 | 75 | {0x34, 0}, /* ' */ |
Brandon | 0:cf17ea89fd09 | 76 | {0x26, KEY_SHIFT}, /* ( */ |
Brandon | 0:cf17ea89fd09 | 77 | {0x27, KEY_SHIFT}, /* ) */ |
Brandon | 0:cf17ea89fd09 | 78 | {0x25, KEY_SHIFT}, /* * */ |
Brandon | 0:cf17ea89fd09 | 79 | {0x2e, KEY_SHIFT}, /* + */ |
Brandon | 0:cf17ea89fd09 | 80 | {0x36, 0}, /* , */ |
Brandon | 0:cf17ea89fd09 | 81 | {0x2d, 0}, /* - */ |
Brandon | 0:cf17ea89fd09 | 82 | {0x37, 0}, /* . */ |
Brandon | 0:cf17ea89fd09 | 83 | {0x38, 0}, /* / */ |
Brandon | 0:cf17ea89fd09 | 84 | {0x27, 0}, /* 0 */ |
Brandon | 0:cf17ea89fd09 | 85 | {0x1e, 0}, /* 1 */ |
Brandon | 0:cf17ea89fd09 | 86 | {0x1f, 0}, /* 2 */ |
Brandon | 0:cf17ea89fd09 | 87 | {0x20, 0}, /* 3 */ |
Brandon | 0:cf17ea89fd09 | 88 | {0x21, 0}, /* 4 */ |
Brandon | 0:cf17ea89fd09 | 89 | {0x22, 0}, /* 5 */ |
Brandon | 0:cf17ea89fd09 | 90 | {0x23, 0}, /* 6 */ |
Brandon | 0:cf17ea89fd09 | 91 | {0x24, 0}, /* 7 */ |
Brandon | 0:cf17ea89fd09 | 92 | {0x25, 0}, /* 8 */ |
Brandon | 0:cf17ea89fd09 | 93 | {0x26, 0}, /* 9 */ |
Brandon | 0:cf17ea89fd09 | 94 | {0x33, KEY_SHIFT}, /* : */ |
Brandon | 0:cf17ea89fd09 | 95 | {0x33, 0}, /* ; */ |
Brandon | 0:cf17ea89fd09 | 96 | {0x36, KEY_SHIFT}, /* < */ |
Brandon | 0:cf17ea89fd09 | 97 | {0x2e, 0}, /* = */ |
Brandon | 0:cf17ea89fd09 | 98 | {0x37, KEY_SHIFT}, /* > */ |
Brandon | 0:cf17ea89fd09 | 99 | {0x38, KEY_SHIFT}, /* ? */ |
Brandon | 0:cf17ea89fd09 | 100 | {0x1f, KEY_SHIFT}, /* @ */ |
Brandon | 0:cf17ea89fd09 | 101 | {0x04, KEY_SHIFT}, /* A */ |
Brandon | 0:cf17ea89fd09 | 102 | {0x05, KEY_SHIFT}, /* B */ |
Brandon | 0:cf17ea89fd09 | 103 | {0x06, KEY_SHIFT}, /* C */ |
Brandon | 0:cf17ea89fd09 | 104 | {0x07, KEY_SHIFT}, /* D */ |
Brandon | 0:cf17ea89fd09 | 105 | {0x08, KEY_SHIFT}, /* E */ |
Brandon | 0:cf17ea89fd09 | 106 | {0x09, KEY_SHIFT}, /* F */ |
Brandon | 0:cf17ea89fd09 | 107 | {0x0a, KEY_SHIFT}, /* G */ |
Brandon | 0:cf17ea89fd09 | 108 | {0x0b, KEY_SHIFT}, /* H */ |
Brandon | 0:cf17ea89fd09 | 109 | {0x0c, KEY_SHIFT}, /* I */ |
Brandon | 0:cf17ea89fd09 | 110 | {0x0d, KEY_SHIFT}, /* J */ |
Brandon | 0:cf17ea89fd09 | 111 | {0x0e, KEY_SHIFT}, /* K */ |
Brandon | 0:cf17ea89fd09 | 112 | {0x0f, KEY_SHIFT}, /* L */ |
Brandon | 0:cf17ea89fd09 | 113 | {0x10, KEY_SHIFT}, /* M */ |
Brandon | 0:cf17ea89fd09 | 114 | {0x11, KEY_SHIFT}, /* N */ |
Brandon | 0:cf17ea89fd09 | 115 | {0x12, KEY_SHIFT}, /* O */ |
Brandon | 0:cf17ea89fd09 | 116 | {0x13, KEY_SHIFT}, /* P */ |
Brandon | 0:cf17ea89fd09 | 117 | {0x14, KEY_SHIFT}, /* Q */ |
Brandon | 0:cf17ea89fd09 | 118 | {0x15, KEY_SHIFT}, /* R */ |
Brandon | 0:cf17ea89fd09 | 119 | {0x16, KEY_SHIFT}, /* S */ |
Brandon | 0:cf17ea89fd09 | 120 | {0x17, KEY_SHIFT}, /* T */ |
Brandon | 0:cf17ea89fd09 | 121 | {0x18, KEY_SHIFT}, /* U */ |
Brandon | 0:cf17ea89fd09 | 122 | {0x19, KEY_SHIFT}, /* V */ |
Brandon | 0:cf17ea89fd09 | 123 | {0x1a, KEY_SHIFT}, /* W */ |
Brandon | 0:cf17ea89fd09 | 124 | {0x1b, KEY_SHIFT}, /* X */ |
Brandon | 0:cf17ea89fd09 | 125 | {0x1c, KEY_SHIFT}, /* Y */ |
Brandon | 0:cf17ea89fd09 | 126 | {0x1d, KEY_SHIFT}, /* Z */ |
Brandon | 0:cf17ea89fd09 | 127 | {0x2f, 0}, /* [ */ |
Brandon | 0:cf17ea89fd09 | 128 | {0x31, 0}, /* \ */ |
Brandon | 0:cf17ea89fd09 | 129 | {0x30, 0}, /* ] */ |
Brandon | 0:cf17ea89fd09 | 130 | {0x23, KEY_SHIFT}, /* ^ */ |
Brandon | 0:cf17ea89fd09 | 131 | {0x2d, KEY_SHIFT}, /* _ */ |
Brandon | 0:cf17ea89fd09 | 132 | {0x35, 0}, /* ` */ |
Brandon | 0:cf17ea89fd09 | 133 | {0x04, 0}, /* a */ |
Brandon | 0:cf17ea89fd09 | 134 | {0x05, 0}, /* b */ |
Brandon | 0:cf17ea89fd09 | 135 | {0x06, 0}, /* c */ |
Brandon | 0:cf17ea89fd09 | 136 | {0x07, 0}, /* d */ |
Brandon | 0:cf17ea89fd09 | 137 | {0x08, 0}, /* e */ |
Brandon | 0:cf17ea89fd09 | 138 | {0x09, 0}, /* f */ |
Brandon | 0:cf17ea89fd09 | 139 | {0x0a, 0}, /* g */ |
Brandon | 0:cf17ea89fd09 | 140 | {0x0b, 0}, /* h */ |
Brandon | 0:cf17ea89fd09 | 141 | {0x0c, 0}, /* i */ |
Brandon | 0:cf17ea89fd09 | 142 | {0x0d, 0}, /* j */ |
Brandon | 0:cf17ea89fd09 | 143 | {0x0e, 0}, /* k */ |
Brandon | 0:cf17ea89fd09 | 144 | {0x0f, 0}, /* l */ |
Brandon | 0:cf17ea89fd09 | 145 | {0x10, 0}, /* m */ |
Brandon | 0:cf17ea89fd09 | 146 | {0x11, 0}, /* n */ |
Brandon | 0:cf17ea89fd09 | 147 | {0x12, 0}, /* o */ |
Brandon | 0:cf17ea89fd09 | 148 | {0x13, 0}, /* p */ |
Brandon | 0:cf17ea89fd09 | 149 | {0x14, 0}, /* q */ |
Brandon | 0:cf17ea89fd09 | 150 | {0x15, 0}, /* r */ |
Brandon | 0:cf17ea89fd09 | 151 | {0x16, 0}, /* s */ |
Brandon | 0:cf17ea89fd09 | 152 | {0x17, 0}, /* t */ |
Brandon | 0:cf17ea89fd09 | 153 | {0x18, 0}, /* u */ |
Brandon | 0:cf17ea89fd09 | 154 | {0x19, 0}, /* v */ |
Brandon | 0:cf17ea89fd09 | 155 | {0x1a, 0}, /* w */ |
Brandon | 0:cf17ea89fd09 | 156 | {0x1b, 0}, /* x */ |
Brandon | 0:cf17ea89fd09 | 157 | {0x1c, 0}, /* y */ |
Brandon | 0:cf17ea89fd09 | 158 | {0x1d, 0}, /* z */ |
Brandon | 0:cf17ea89fd09 | 159 | {0x2f, KEY_SHIFT}, /* { */ |
Brandon | 0:cf17ea89fd09 | 160 | {0x31, KEY_SHIFT}, /* | */ |
Brandon | 0:cf17ea89fd09 | 161 | {0x30, KEY_SHIFT}, /* } */ |
Brandon | 0:cf17ea89fd09 | 162 | {0x35, KEY_SHIFT}, /* ~ */ |
Brandon | 0:cf17ea89fd09 | 163 | {0,0}, /* DEL */ |
Brandon | 0:cf17ea89fd09 | 164 | |
Brandon | 0:cf17ea89fd09 | 165 | {0x3a, 0}, /* F1 */ |
Brandon | 0:cf17ea89fd09 | 166 | {0x3b, 0}, /* F2 */ |
Brandon | 0:cf17ea89fd09 | 167 | {0x3c, 0}, /* F3 */ |
Brandon | 0:cf17ea89fd09 | 168 | {0x3d, 0}, /* F4 */ |
Brandon | 0:cf17ea89fd09 | 169 | {0x3e, 0}, /* F5 */ |
Brandon | 0:cf17ea89fd09 | 170 | {0x3f, 0}, /* F6 */ |
Brandon | 0:cf17ea89fd09 | 171 | {0x40, 0}, /* F7 */ |
Brandon | 0:cf17ea89fd09 | 172 | {0x41, 0}, /* F8 */ |
Brandon | 0:cf17ea89fd09 | 173 | {0x42, 0}, /* F9 */ |
Brandon | 0:cf17ea89fd09 | 174 | {0x43, 0}, /* F10 */ |
Brandon | 0:cf17ea89fd09 | 175 | {0x44, 0}, /* F11 */ |
Brandon | 0:cf17ea89fd09 | 176 | {0x45, 0}, /* F12 */ |
Brandon | 0:cf17ea89fd09 | 177 | |
Brandon | 0:cf17ea89fd09 | 178 | {0x46, 0}, /* PRINT_SCREEN */ |
Brandon | 0:cf17ea89fd09 | 179 | {0x47, 0}, /* SCROLL_LOCK */ |
Brandon | 0:cf17ea89fd09 | 180 | {0x39, 0}, /* CAPS_LOCK */ |
Brandon | 0:cf17ea89fd09 | 181 | {0x53, 0}, /* NUM_LOCK */ |
Brandon | 0:cf17ea89fd09 | 182 | {0x49, 0}, /* INSERT */ |
Brandon | 0:cf17ea89fd09 | 183 | {0x4a, 0}, /* HOME */ |
Brandon | 0:cf17ea89fd09 | 184 | {0x4b, 0}, /* PAGE_UP */ |
Brandon | 0:cf17ea89fd09 | 185 | {0x4e, 0}, /* PAGE_DOWN */ |
Brandon | 0:cf17ea89fd09 | 186 | |
Brandon | 0:cf17ea89fd09 | 187 | {0x4f, 0}, /* RIGHT_ARROW */ |
Brandon | 0:cf17ea89fd09 | 188 | {0x50, 0}, /* LEFT_ARROW */ |
Brandon | 0:cf17ea89fd09 | 189 | {0x51, 0}, /* DOWN_ARROW */ |
Brandon | 0:cf17ea89fd09 | 190 | {0x52, 0}, /* UP_ARROW */ |
Brandon | 0:cf17ea89fd09 | 191 | }; |
Brandon | 0:cf17ea89fd09 | 192 | |
Brandon | 0:cf17ea89fd09 | 193 | #else |
Brandon | 0:cf17ea89fd09 | 194 | /* UK keyboard */ |
Brandon | 0:cf17ea89fd09 | 195 | #define KEYMAP_SIZE (152) |
Brandon | 0:cf17ea89fd09 | 196 | const KEYMAP keymap[KEYMAP_SIZE] = { |
Brandon | 0:cf17ea89fd09 | 197 | {0, 0}, /* NUL */ |
Brandon | 0:cf17ea89fd09 | 198 | {0, 0}, /* SOH */ |
Brandon | 0:cf17ea89fd09 | 199 | {0, 0}, /* STX */ |
Brandon | 0:cf17ea89fd09 | 200 | {0, 0}, /* ETX */ |
Brandon | 0:cf17ea89fd09 | 201 | {0, 0}, /* EOT */ |
Brandon | 0:cf17ea89fd09 | 202 | {0, 0}, /* ENQ */ |
Brandon | 0:cf17ea89fd09 | 203 | {0, 0}, /* ACK */ |
Brandon | 0:cf17ea89fd09 | 204 | {0, 0}, /* BEL */ |
Brandon | 0:cf17ea89fd09 | 205 | {0x2a, 0}, /* BS */ /* Keyboard Delete (Backspace) */ |
Brandon | 0:cf17ea89fd09 | 206 | {0x2b, 0}, /* TAB */ /* Keyboard Tab */ |
Brandon | 0:cf17ea89fd09 | 207 | {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */ |
Brandon | 0:cf17ea89fd09 | 208 | {0, 0}, /* VT */ |
Brandon | 0:cf17ea89fd09 | 209 | {0, 0}, /* FF */ |
Brandon | 0:cf17ea89fd09 | 210 | {0, 0}, /* CR */ |
Brandon | 0:cf17ea89fd09 | 211 | {0, 0}, /* SO */ |
Brandon | 0:cf17ea89fd09 | 212 | {0, 0}, /* SI */ |
Brandon | 0:cf17ea89fd09 | 213 | {0, 0}, /* DEL */ |
Brandon | 0:cf17ea89fd09 | 214 | {0, 0}, /* DC1 */ |
Brandon | 0:cf17ea89fd09 | 215 | {0, 0}, /* DC2 */ |
Brandon | 0:cf17ea89fd09 | 216 | {0, 0}, /* DC3 */ |
Brandon | 0:cf17ea89fd09 | 217 | {0, 0}, /* DC4 */ |
Brandon | 0:cf17ea89fd09 | 218 | {0, 0}, /* NAK */ |
Brandon | 0:cf17ea89fd09 | 219 | {0, 0}, /* SYN */ |
Brandon | 0:cf17ea89fd09 | 220 | {0, 0}, /* ETB */ |
Brandon | 0:cf17ea89fd09 | 221 | {0, 0}, /* CAN */ |
Brandon | 0:cf17ea89fd09 | 222 | {0, 0}, /* EM */ |
Brandon | 0:cf17ea89fd09 | 223 | {0, 0}, /* SUB */ |
Brandon | 0:cf17ea89fd09 | 224 | {0, 0}, /* ESC */ |
Brandon | 0:cf17ea89fd09 | 225 | {0, 0}, /* FS */ |
Brandon | 0:cf17ea89fd09 | 226 | {0, 0}, /* GS */ |
Brandon | 0:cf17ea89fd09 | 227 | {0, 0}, /* RS */ |
Brandon | 0:cf17ea89fd09 | 228 | {0, 0}, /* US */ |
Brandon | 0:cf17ea89fd09 | 229 | {0x2c, 0}, /* */ |
Brandon | 0:cf17ea89fd09 | 230 | {0x1e, KEY_SHIFT}, /* ! */ |
Brandon | 0:cf17ea89fd09 | 231 | {0x1f, KEY_SHIFT}, /* " */ |
Brandon | 0:cf17ea89fd09 | 232 | {0x32, 0}, /* # */ |
Brandon | 0:cf17ea89fd09 | 233 | {0x21, KEY_SHIFT}, /* $ */ |
Brandon | 0:cf17ea89fd09 | 234 | {0x22, KEY_SHIFT}, /* % */ |
Brandon | 0:cf17ea89fd09 | 235 | {0x24, KEY_SHIFT}, /* & */ |
Brandon | 0:cf17ea89fd09 | 236 | {0x34, 0}, /* ' */ |
Brandon | 0:cf17ea89fd09 | 237 | {0x26, KEY_SHIFT}, /* ( */ |
Brandon | 0:cf17ea89fd09 | 238 | {0x27, KEY_SHIFT}, /* ) */ |
Brandon | 0:cf17ea89fd09 | 239 | {0x25, KEY_SHIFT}, /* * */ |
Brandon | 0:cf17ea89fd09 | 240 | {0x2e, KEY_SHIFT}, /* + */ |
Brandon | 0:cf17ea89fd09 | 241 | {0x36, 0}, /* , */ |
Brandon | 0:cf17ea89fd09 | 242 | {0x2d, 0}, /* - */ |
Brandon | 0:cf17ea89fd09 | 243 | {0x37, 0}, /* . */ |
Brandon | 0:cf17ea89fd09 | 244 | {0x38, 0}, /* / */ |
Brandon | 0:cf17ea89fd09 | 245 | {0x27, 0}, /* 0 */ |
Brandon | 0:cf17ea89fd09 | 246 | {0x1e, 0}, /* 1 */ |
Brandon | 0:cf17ea89fd09 | 247 | {0x1f, 0}, /* 2 */ |
Brandon | 0:cf17ea89fd09 | 248 | {0x20, 0}, /* 3 */ |
Brandon | 0:cf17ea89fd09 | 249 | {0x21, 0}, /* 4 */ |
Brandon | 0:cf17ea89fd09 | 250 | {0x22, 0}, /* 5 */ |
Brandon | 0:cf17ea89fd09 | 251 | {0x23, 0}, /* 6 */ |
Brandon | 0:cf17ea89fd09 | 252 | {0x24, 0}, /* 7 */ |
Brandon | 0:cf17ea89fd09 | 253 | {0x25, 0}, /* 8 */ |
Brandon | 0:cf17ea89fd09 | 254 | {0x26, 0}, /* 9 */ |
Brandon | 0:cf17ea89fd09 | 255 | {0x33, KEY_SHIFT}, /* : */ |
Brandon | 0:cf17ea89fd09 | 256 | {0x33, 0}, /* ; */ |
Brandon | 0:cf17ea89fd09 | 257 | {0x36, KEY_SHIFT}, /* < */ |
Brandon | 0:cf17ea89fd09 | 258 | {0x2e, 0}, /* = */ |
Brandon | 0:cf17ea89fd09 | 259 | {0x37, KEY_SHIFT}, /* > */ |
Brandon | 0:cf17ea89fd09 | 260 | {0x38, KEY_SHIFT}, /* ? */ |
Brandon | 0:cf17ea89fd09 | 261 | {0x34, KEY_SHIFT}, /* @ */ |
Brandon | 0:cf17ea89fd09 | 262 | {0x04, KEY_SHIFT}, /* A */ |
Brandon | 0:cf17ea89fd09 | 263 | {0x05, KEY_SHIFT}, /* B */ |
Brandon | 0:cf17ea89fd09 | 264 | {0x06, KEY_SHIFT}, /* C */ |
Brandon | 0:cf17ea89fd09 | 265 | {0x07, KEY_SHIFT}, /* D */ |
Brandon | 0:cf17ea89fd09 | 266 | {0x08, KEY_SHIFT}, /* E */ |
Brandon | 0:cf17ea89fd09 | 267 | {0x09, KEY_SHIFT}, /* F */ |
Brandon | 0:cf17ea89fd09 | 268 | {0x0a, KEY_SHIFT}, /* G */ |
Brandon | 0:cf17ea89fd09 | 269 | {0x0b, KEY_SHIFT}, /* H */ |
Brandon | 0:cf17ea89fd09 | 270 | {0x0c, KEY_SHIFT}, /* I */ |
Brandon | 0:cf17ea89fd09 | 271 | {0x0d, KEY_SHIFT}, /* J */ |
Brandon | 0:cf17ea89fd09 | 272 | {0x0e, KEY_SHIFT}, /* K */ |
Brandon | 0:cf17ea89fd09 | 273 | {0x0f, KEY_SHIFT}, /* L */ |
Brandon | 0:cf17ea89fd09 | 274 | {0x10, KEY_SHIFT}, /* M */ |
Brandon | 0:cf17ea89fd09 | 275 | {0x11, KEY_SHIFT}, /* N */ |
Brandon | 0:cf17ea89fd09 | 276 | {0x12, KEY_SHIFT}, /* O */ |
Brandon | 0:cf17ea89fd09 | 277 | {0x13, KEY_SHIFT}, /* P */ |
Brandon | 0:cf17ea89fd09 | 278 | {0x14, KEY_SHIFT}, /* Q */ |
Brandon | 0:cf17ea89fd09 | 279 | {0x15, KEY_SHIFT}, /* R */ |
Brandon | 0:cf17ea89fd09 | 280 | {0x16, KEY_SHIFT}, /* S */ |
Brandon | 0:cf17ea89fd09 | 281 | {0x17, KEY_SHIFT}, /* T */ |
Brandon | 0:cf17ea89fd09 | 282 | {0x18, KEY_SHIFT}, /* U */ |
Brandon | 0:cf17ea89fd09 | 283 | {0x19, KEY_SHIFT}, /* V */ |
Brandon | 0:cf17ea89fd09 | 284 | {0x1a, KEY_SHIFT}, /* W */ |
Brandon | 0:cf17ea89fd09 | 285 | {0x1b, KEY_SHIFT}, /* X */ |
Brandon | 0:cf17ea89fd09 | 286 | {0x1c, KEY_SHIFT}, /* Y */ |
Brandon | 0:cf17ea89fd09 | 287 | {0x1d, KEY_SHIFT}, /* Z */ |
Brandon | 0:cf17ea89fd09 | 288 | {0x2f, 0}, /* [ */ |
Brandon | 0:cf17ea89fd09 | 289 | {0x64, 0}, /* \ */ |
Brandon | 0:cf17ea89fd09 | 290 | {0x30, 0}, /* ] */ |
Brandon | 0:cf17ea89fd09 | 291 | {0x23, KEY_SHIFT}, /* ^ */ |
Brandon | 0:cf17ea89fd09 | 292 | {0x2d, KEY_SHIFT}, /* _ */ |
Brandon | 0:cf17ea89fd09 | 293 | {0x35, 0}, /* ` */ |
Brandon | 0:cf17ea89fd09 | 294 | {0x04, 0}, /* a */ |
Brandon | 0:cf17ea89fd09 | 295 | {0x05, 0}, /* b */ |
Brandon | 0:cf17ea89fd09 | 296 | {0x06, 0}, /* c */ |
Brandon | 0:cf17ea89fd09 | 297 | {0x07, 0}, /* d */ |
Brandon | 0:cf17ea89fd09 | 298 | {0x08, 0}, /* e */ |
Brandon | 0:cf17ea89fd09 | 299 | {0x09, 0}, /* f */ |
Brandon | 0:cf17ea89fd09 | 300 | {0x0a, 0}, /* g */ |
Brandon | 0:cf17ea89fd09 | 301 | {0x0b, 0}, /* h */ |
Brandon | 0:cf17ea89fd09 | 302 | {0x0c, 0}, /* i */ |
Brandon | 0:cf17ea89fd09 | 303 | {0x0d, 0}, /* j */ |
Brandon | 0:cf17ea89fd09 | 304 | {0x0e, 0}, /* k */ |
Brandon | 0:cf17ea89fd09 | 305 | {0x0f, 0}, /* l */ |
Brandon | 0:cf17ea89fd09 | 306 | {0x10, 0}, /* m */ |
Brandon | 0:cf17ea89fd09 | 307 | {0x11, 0}, /* n */ |
Brandon | 0:cf17ea89fd09 | 308 | {0x12, 0}, /* o */ |
Brandon | 0:cf17ea89fd09 | 309 | {0x13, 0}, /* p */ |
Brandon | 0:cf17ea89fd09 | 310 | {0x14, 0}, /* q */ |
Brandon | 0:cf17ea89fd09 | 311 | {0x15, 0}, /* r */ |
Brandon | 0:cf17ea89fd09 | 312 | {0x16, 0}, /* s */ |
Brandon | 0:cf17ea89fd09 | 313 | {0x17, 0}, /* t */ |
Brandon | 0:cf17ea89fd09 | 314 | {0x18, 0}, /* u */ |
Brandon | 0:cf17ea89fd09 | 315 | {0x19, 0}, /* v */ |
Brandon | 0:cf17ea89fd09 | 316 | {0x1a, 0}, /* w */ |
Brandon | 0:cf17ea89fd09 | 317 | {0x1b, 0}, /* x */ |
Brandon | 0:cf17ea89fd09 | 318 | {0x1c, 0}, /* y */ |
Brandon | 0:cf17ea89fd09 | 319 | {0x1d, 0}, /* z */ |
Brandon | 0:cf17ea89fd09 | 320 | {0x2f, KEY_SHIFT}, /* { */ |
Brandon | 0:cf17ea89fd09 | 321 | {0x64, KEY_SHIFT}, /* | */ |
Brandon | 0:cf17ea89fd09 | 322 | {0x30, KEY_SHIFT}, /* } */ |
Brandon | 0:cf17ea89fd09 | 323 | {0x32, KEY_SHIFT}, /* ~ */ |
Brandon | 0:cf17ea89fd09 | 324 | {0,0}, /* DEL */ |
Brandon | 0:cf17ea89fd09 | 325 | |
Brandon | 0:cf17ea89fd09 | 326 | {0x3a, 0}, /* F1 */ |
Brandon | 0:cf17ea89fd09 | 327 | {0x3b, 0}, /* F2 */ |
Brandon | 0:cf17ea89fd09 | 328 | {0x3c, 0}, /* F3 */ |
Brandon | 0:cf17ea89fd09 | 329 | {0x3d, 0}, /* F4 */ |
Brandon | 0:cf17ea89fd09 | 330 | {0x3e, 0}, /* F5 */ |
Brandon | 0:cf17ea89fd09 | 331 | {0x3f, 0}, /* F6 */ |
Brandon | 0:cf17ea89fd09 | 332 | {0x40, 0}, /* F7 */ |
Brandon | 0:cf17ea89fd09 | 333 | {0x41, 0}, /* F8 */ |
Brandon | 0:cf17ea89fd09 | 334 | {0x42, 0}, /* F9 */ |
Brandon | 0:cf17ea89fd09 | 335 | {0x43, 0}, /* F10 */ |
Brandon | 0:cf17ea89fd09 | 336 | {0x44, 0}, /* F11 */ |
Brandon | 0:cf17ea89fd09 | 337 | {0x45, 0}, /* F12 */ |
Brandon | 0:cf17ea89fd09 | 338 | |
Brandon | 0:cf17ea89fd09 | 339 | {0x46, 0}, /* PRINT_SCREEN */ |
Brandon | 0:cf17ea89fd09 | 340 | {0x47, 0}, /* SCROLL_LOCK */ |
Brandon | 0:cf17ea89fd09 | 341 | {0x39, 0}, /* CAPS_LOCK */ |
Brandon | 0:cf17ea89fd09 | 342 | {0x53, 0}, /* NUM_LOCK */ |
Brandon | 0:cf17ea89fd09 | 343 | {0x49, 0}, /* INSERT */ |
Brandon | 0:cf17ea89fd09 | 344 | {0x4a, 0}, /* HOME */ |
Brandon | 0:cf17ea89fd09 | 345 | {0x4b, 0}, /* PAGE_UP */ |
Brandon | 0:cf17ea89fd09 | 346 | {0x4e, 0}, /* PAGE_DOWN */ |
Brandon | 0:cf17ea89fd09 | 347 | |
Brandon | 0:cf17ea89fd09 | 348 | {0x4f, 0}, /* RIGHT_ARROW */ |
Brandon | 0:cf17ea89fd09 | 349 | {0x50, 0}, /* LEFT_ARROW */ |
Brandon | 0:cf17ea89fd09 | 350 | {0x51, 0}, /* DOWN_ARROW */ |
Brandon | 0:cf17ea89fd09 | 351 | {0x52, 0}, /* UP_ARROW */ |
Brandon | 0:cf17ea89fd09 | 352 | }; |
Brandon | 0:cf17ea89fd09 | 353 | #endif |
Brandon | 0:cf17ea89fd09 | 354 | |
Brandon | 0:cf17ea89fd09 | 355 | uint8_t * USBKeyboard::reportDesc() { |
Brandon | 0:cf17ea89fd09 | 356 | static uint8_t reportDescriptor[] = { |
Brandon | 0:cf17ea89fd09 | 357 | USAGE_PAGE(1), 0x01, // Generic Desktop |
Brandon | 0:cf17ea89fd09 | 358 | USAGE(1), 0x06, // Keyboard |
Brandon | 0:cf17ea89fd09 | 359 | COLLECTION(1), 0x01, // Application |
Brandon | 0:cf17ea89fd09 | 360 | REPORT_ID(1), REPORT_ID_KEYBOARD, |
Brandon | 0:cf17ea89fd09 | 361 | |
Brandon | 0:cf17ea89fd09 | 362 | USAGE_PAGE(1), 0x07, // Key Codes |
Brandon | 0:cf17ea89fd09 | 363 | USAGE_MINIMUM(1), 0xE0, |
Brandon | 0:cf17ea89fd09 | 364 | USAGE_MAXIMUM(1), 0xE7, |
Brandon | 0:cf17ea89fd09 | 365 | LOGICAL_MINIMUM(1), 0x00, |
Brandon | 0:cf17ea89fd09 | 366 | LOGICAL_MAXIMUM(1), 0x01, |
Brandon | 0:cf17ea89fd09 | 367 | REPORT_SIZE(1), 0x01, |
Brandon | 0:cf17ea89fd09 | 368 | REPORT_COUNT(1), 0x08, |
Brandon | 0:cf17ea89fd09 | 369 | INPUT(1), 0x02, // Data, Variable, Absolute |
Brandon | 0:cf17ea89fd09 | 370 | REPORT_COUNT(1), 0x01, |
Brandon | 0:cf17ea89fd09 | 371 | REPORT_SIZE(1), 0x08, |
Brandon | 0:cf17ea89fd09 | 372 | INPUT(1), 0x01, // Constant |
Brandon | 0:cf17ea89fd09 | 373 | |
Brandon | 0:cf17ea89fd09 | 374 | |
Brandon | 0:cf17ea89fd09 | 375 | REPORT_COUNT(1), 0x05, |
Brandon | 0:cf17ea89fd09 | 376 | REPORT_SIZE(1), 0x01, |
Brandon | 0:cf17ea89fd09 | 377 | USAGE_PAGE(1), 0x08, // LEDs |
Brandon | 0:cf17ea89fd09 | 378 | USAGE_MINIMUM(1), 0x01, |
Brandon | 0:cf17ea89fd09 | 379 | USAGE_MAXIMUM(1), 0x05, |
Brandon | 0:cf17ea89fd09 | 380 | OUTPUT(1), 0x02, // Data, Variable, Absolute |
Brandon | 0:cf17ea89fd09 | 381 | REPORT_COUNT(1), 0x01, |
Brandon | 0:cf17ea89fd09 | 382 | REPORT_SIZE(1), 0x03, |
Brandon | 0:cf17ea89fd09 | 383 | OUTPUT(1), 0x01, // Constant |
Brandon | 0:cf17ea89fd09 | 384 | |
Brandon | 0:cf17ea89fd09 | 385 | |
Brandon | 0:cf17ea89fd09 | 386 | REPORT_COUNT(1), 0x06, |
Brandon | 0:cf17ea89fd09 | 387 | REPORT_SIZE(1), 0x08, |
Brandon | 0:cf17ea89fd09 | 388 | LOGICAL_MINIMUM(1), 0x00, |
Brandon | 0:cf17ea89fd09 | 389 | LOGICAL_MAXIMUM(1), 0x65, |
Brandon | 0:cf17ea89fd09 | 390 | USAGE_PAGE(1), 0x07, // Key Codes |
Brandon | 0:cf17ea89fd09 | 391 | USAGE_MINIMUM(1), 0x00, |
Brandon | 0:cf17ea89fd09 | 392 | USAGE_MAXIMUM(1), 0x65, |
Brandon | 0:cf17ea89fd09 | 393 | INPUT(1), 0x00, // Data, Array |
Brandon | 0:cf17ea89fd09 | 394 | END_COLLECTION(0), |
Brandon | 0:cf17ea89fd09 | 395 | |
Brandon | 0:cf17ea89fd09 | 396 | // Media Control |
Brandon | 0:cf17ea89fd09 | 397 | USAGE_PAGE(1), 0x0C, |
Brandon | 0:cf17ea89fd09 | 398 | USAGE(1), 0x01, |
Brandon | 0:cf17ea89fd09 | 399 | COLLECTION(1), 0x01, |
Brandon | 0:cf17ea89fd09 | 400 | REPORT_ID(1), REPORT_ID_VOLUME, |
Brandon | 0:cf17ea89fd09 | 401 | USAGE_PAGE(1), 0x0C, |
Brandon | 0:cf17ea89fd09 | 402 | LOGICAL_MINIMUM(1), 0x00, |
Brandon | 0:cf17ea89fd09 | 403 | LOGICAL_MAXIMUM(1), 0x01, |
Brandon | 0:cf17ea89fd09 | 404 | REPORT_SIZE(1), 0x01, |
Brandon | 0:cf17ea89fd09 | 405 | REPORT_COUNT(1), 0x07, |
Brandon | 0:cf17ea89fd09 | 406 | USAGE(1), 0xB5, // Next Track |
Brandon | 0:cf17ea89fd09 | 407 | USAGE(1), 0xB6, // Previous Track |
Brandon | 0:cf17ea89fd09 | 408 | USAGE(1), 0xB7, // Stop |
Brandon | 0:cf17ea89fd09 | 409 | USAGE(1), 0xCD, // Play / Pause |
Brandon | 0:cf17ea89fd09 | 410 | USAGE(1), 0xE2, // Mute |
Brandon | 0:cf17ea89fd09 | 411 | USAGE(1), 0xE9, // Volume Up |
Brandon | 0:cf17ea89fd09 | 412 | USAGE(1), 0xEA, // Volume Down |
Brandon | 0:cf17ea89fd09 | 413 | INPUT(1), 0x02, // Input (Data, Variable, Absolute) |
Brandon | 0:cf17ea89fd09 | 414 | REPORT_COUNT(1), 0x01, |
Brandon | 0:cf17ea89fd09 | 415 | INPUT(1), 0x01, |
Brandon | 0:cf17ea89fd09 | 416 | END_COLLECTION(0), |
Brandon | 0:cf17ea89fd09 | 417 | }; |
Brandon | 0:cf17ea89fd09 | 418 | reportLength = sizeof(reportDescriptor); |
Brandon | 0:cf17ea89fd09 | 419 | return reportDescriptor; |
Brandon | 0:cf17ea89fd09 | 420 | } |
Brandon | 0:cf17ea89fd09 | 421 | |
Brandon | 0:cf17ea89fd09 | 422 | |
Brandon | 0:cf17ea89fd09 | 423 | bool USBKeyboard::EP1_OUT_callback() { |
Brandon | 0:cf17ea89fd09 | 424 | uint32_t bytesRead = 0; |
Brandon | 0:cf17ea89fd09 | 425 | uint8_t led[65]; |
Brandon | 0:cf17ea89fd09 | 426 | USBDevice::readEP(EPINT_OUT, led, &bytesRead, MAX_HID_REPORT_SIZE); |
Brandon | 0:cf17ea89fd09 | 427 | |
Brandon | 0:cf17ea89fd09 | 428 | // we take led[1] because led[0] is the report ID |
Brandon | 0:cf17ea89fd09 | 429 | lock_status = led[1] & 0x07; |
Brandon | 0:cf17ea89fd09 | 430 | |
Brandon | 0:cf17ea89fd09 | 431 | // We activate the endpoint to be able to recceive data |
Brandon | 0:cf17ea89fd09 | 432 | if (!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE)) |
Brandon | 0:cf17ea89fd09 | 433 | return false; |
Brandon | 0:cf17ea89fd09 | 434 | return true; |
Brandon | 0:cf17ea89fd09 | 435 | } |
Brandon | 0:cf17ea89fd09 | 436 | |
Brandon | 0:cf17ea89fd09 | 437 | uint8_t USBKeyboard::lockStatus() { |
Brandon | 0:cf17ea89fd09 | 438 | return lock_status; |
Brandon | 0:cf17ea89fd09 | 439 | } |
Brandon | 0:cf17ea89fd09 | 440 | |
Brandon | 0:cf17ea89fd09 | 441 | int USBKeyboard::_putc(int c) { |
Brandon | 0:cf17ea89fd09 | 442 | return keyCode(c, keymap[c].modifier); |
Brandon | 0:cf17ea89fd09 | 443 | } |
Brandon | 0:cf17ea89fd09 | 444 | |
Brandon | 0:cf17ea89fd09 | 445 | bool USBKeyboard::keyCode(uint8_t key, uint8_t modifier) { |
Brandon | 0:cf17ea89fd09 | 446 | // Send a simulated keyboard keypress. Returns true if successful. |
Brandon | 0:cf17ea89fd09 | 447 | HID_REPORT report; |
Brandon | 0:cf17ea89fd09 | 448 | |
Brandon | 0:cf17ea89fd09 | 449 | report.data[0] = REPORT_ID_KEYBOARD; |
Brandon | 0:cf17ea89fd09 | 450 | report.data[1] = modifier; |
Brandon | 0:cf17ea89fd09 | 451 | report.data[2] = 0; |
Brandon | 0:cf17ea89fd09 | 452 | report.data[3] = keymap[key].usage; |
Brandon | 0:cf17ea89fd09 | 453 | report.data[4] = 0; |
Brandon | 0:cf17ea89fd09 | 454 | report.data[5] = 0; |
Brandon | 0:cf17ea89fd09 | 455 | report.data[6] = 0; |
Brandon | 0:cf17ea89fd09 | 456 | report.data[7] = 0; |
Brandon | 0:cf17ea89fd09 | 457 | report.data[8] = 0; |
Brandon | 0:cf17ea89fd09 | 458 | |
Brandon | 0:cf17ea89fd09 | 459 | report.length = 9; |
Brandon | 0:cf17ea89fd09 | 460 | |
Brandon | 0:cf17ea89fd09 | 461 | if (!send(&report)) { |
Brandon | 0:cf17ea89fd09 | 462 | return false; |
Brandon | 0:cf17ea89fd09 | 463 | } |
Brandon | 0:cf17ea89fd09 | 464 | |
Brandon | 0:cf17ea89fd09 | 465 | report.data[1] = 0; |
Brandon | 0:cf17ea89fd09 | 466 | report.data[3] = 0; |
Brandon | 0:cf17ea89fd09 | 467 | |
Brandon | 0:cf17ea89fd09 | 468 | if (!send(&report)) { |
Brandon | 0:cf17ea89fd09 | 469 | return false; |
Brandon | 0:cf17ea89fd09 | 470 | } |
Brandon | 0:cf17ea89fd09 | 471 | |
Brandon | 0:cf17ea89fd09 | 472 | return true; |
Brandon | 0:cf17ea89fd09 | 473 | |
Brandon | 0:cf17ea89fd09 | 474 | } |
Brandon | 0:cf17ea89fd09 | 475 | |
Brandon | 0:cf17ea89fd09 | 476 | |
Brandon | 0:cf17ea89fd09 | 477 | bool USBKeyboard::mediaControl(MEDIA_KEY key) { |
Brandon | 0:cf17ea89fd09 | 478 | HID_REPORT report; |
Brandon | 0:cf17ea89fd09 | 479 | |
Brandon | 0:cf17ea89fd09 | 480 | report.data[0] = REPORT_ID_VOLUME; |
Brandon | 0:cf17ea89fd09 | 481 | report.data[1] = (1 << key) & 0x7f; |
Brandon | 0:cf17ea89fd09 | 482 | |
Brandon | 0:cf17ea89fd09 | 483 | report.length = 2; |
Brandon | 0:cf17ea89fd09 | 484 | |
Brandon | 0:cf17ea89fd09 | 485 | if (!send(&report)) { |
Brandon | 0:cf17ea89fd09 | 486 | return false; |
Brandon | 0:cf17ea89fd09 | 487 | } |
Brandon | 0:cf17ea89fd09 | 488 | |
Brandon | 0:cf17ea89fd09 | 489 | report.data[0] = REPORT_ID_VOLUME; |
Brandon | 0:cf17ea89fd09 | 490 | report.data[1] = 0; |
Brandon | 0:cf17ea89fd09 | 491 | |
Brandon | 0:cf17ea89fd09 | 492 | report.length = 2; |
Brandon | 0:cf17ea89fd09 | 493 | |
Brandon | 0:cf17ea89fd09 | 494 | return send(&report); |
Brandon | 0:cf17ea89fd09 | 495 | } |
Brandon | 0:cf17ea89fd09 | 496 | |
Brandon | 0:cf17ea89fd09 | 497 | |
Brandon | 0:cf17ea89fd09 | 498 | #define DEFAULT_CONFIGURATION (1) |
Brandon | 0:cf17ea89fd09 | 499 | #define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \ |
Brandon | 0:cf17ea89fd09 | 500 | + (1 * INTERFACE_DESCRIPTOR_LENGTH) \ |
Brandon | 0:cf17ea89fd09 | 501 | + (1 * HID_DESCRIPTOR_LENGTH) \ |
Brandon | 0:cf17ea89fd09 | 502 | + (2 * ENDPOINT_DESCRIPTOR_LENGTH)) |
Brandon | 0:cf17ea89fd09 | 503 | |
Brandon | 0:cf17ea89fd09 | 504 | uint8_t * USBKeyboard::configurationDesc() { |
Brandon | 0:cf17ea89fd09 | 505 | static uint8_t configurationDescriptor[] = { |
Brandon | 0:cf17ea89fd09 | 506 | CONFIGURATION_DESCRIPTOR_LENGTH,// bLength |
Brandon | 0:cf17ea89fd09 | 507 | CONFIGURATION_DESCRIPTOR, // bDescriptorType |
Brandon | 0:cf17ea89fd09 | 508 | LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB) |
Brandon | 0:cf17ea89fd09 | 509 | MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB) |
Brandon | 0:cf17ea89fd09 | 510 | 0x01, // bNumInterfaces |
Brandon | 0:cf17ea89fd09 | 511 | DEFAULT_CONFIGURATION, // bConfigurationValue |
Brandon | 0:cf17ea89fd09 | 512 | 0x00, // iConfiguration |
Brandon | 0:cf17ea89fd09 | 513 | C_RESERVED | C_SELF_POWERED, // bmAttributes |
Brandon | 0:cf17ea89fd09 | 514 | C_POWER(0), // bMaxPowerHello World from Mbed |
Brandon | 0:cf17ea89fd09 | 515 | |
Brandon | 0:cf17ea89fd09 | 516 | INTERFACE_DESCRIPTOR_LENGTH, // bLength |
Brandon | 0:cf17ea89fd09 | 517 | INTERFACE_DESCRIPTOR, // bDescriptorType |
Brandon | 0:cf17ea89fd09 | 518 | 0x00, // bInterfaceNumber |
Brandon | 0:cf17ea89fd09 | 519 | 0x00, // bAlternateSetting |
Brandon | 0:cf17ea89fd09 | 520 | 0x02, // bNumEndpoints |
Brandon | 0:cf17ea89fd09 | 521 | HID_CLASS, // bInterfaceClass |
Brandon | 0:cf17ea89fd09 | 522 | 1, // bInterfaceSubClass |
Brandon | 0:cf17ea89fd09 | 523 | 1, // bInterfaceProtocol (keyboard) |
Brandon | 0:cf17ea89fd09 | 524 | 0x00, // iInterface |
Brandon | 0:cf17ea89fd09 | 525 | |
Brandon | 0:cf17ea89fd09 | 526 | HID_DESCRIPTOR_LENGTH, // bLength |
Brandon | 0:cf17ea89fd09 | 527 | HID_DESCRIPTOR, // bDescriptorType |
Brandon | 0:cf17ea89fd09 | 528 | LSB(HID_VERSION_1_11), // bcdHID (LSB) |
Brandon | 0:cf17ea89fd09 | 529 | MSB(HID_VERSION_1_11), // bcdHID (MSB) |
Brandon | 0:cf17ea89fd09 | 530 | 0x00, // bCountryCode |
Brandon | 0:cf17ea89fd09 | 531 | 0x01, // bNumDescriptors |
Brandon | 0:cf17ea89fd09 | 532 | REPORT_DESCRIPTOR, // bDescriptorType |
Brandon | 0:cf17ea89fd09 | 533 | LSB(reportDescLength()), // wDescriptorLength (LSB) |
Brandon | 0:cf17ea89fd09 | 534 | MSB(reportDescLength()), // wDescriptorLength (MSB) |
Brandon | 0:cf17ea89fd09 | 535 | |
Brandon | 0:cf17ea89fd09 | 536 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
Brandon | 0:cf17ea89fd09 | 537 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
Brandon | 0:cf17ea89fd09 | 538 | PHY_TO_DESC(EPINT_IN), // bEndpointAddress |
Brandon | 0:cf17ea89fd09 | 539 | E_INTERRUPT, // bmAttributes |
Brandon | 0:cf17ea89fd09 | 540 | LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) |
Brandon | 0:cf17ea89fd09 | 541 | MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) |
Brandon | 0:cf17ea89fd09 | 542 | 1, // bInterval (milliseconds) |
Brandon | 0:cf17ea89fd09 | 543 | |
Brandon | 0:cf17ea89fd09 | 544 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
Brandon | 0:cf17ea89fd09 | 545 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
Brandon | 0:cf17ea89fd09 | 546 | PHY_TO_DESC(EPINT_OUT), // bEndpointAddress |
Brandon | 0:cf17ea89fd09 | 547 | E_INTERRUPT, // bmAttributes |
Brandon | 0:cf17ea89fd09 | 548 | LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) |
Brandon | 0:cf17ea89fd09 | 549 | MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) |
Brandon | 0:cf17ea89fd09 | 550 | 1, // bInterval (milliseconds) |
Brandon | 0:cf17ea89fd09 | 551 | }; |
Brandon | 0:cf17ea89fd09 | 552 | return configurationDescriptor; |
Brandon | 0:cf17ea89fd09 | 553 | } |