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