partly working USB Device lib for STM32F746NG Discovery both Interface are working

Dependents:   DISCO-F746NG-USB_Device McLighTT project_Keyboard_to_the_Keyboard MIDIInstrumentPADProject ... more

Committer:
DieterGraef
Date:
Sun Jul 31 17:47:35 2016 +0000
Revision:
0:0a2eaa300982
partly working USB Device library - serial and MIDI is working

Who changed what in which revision?

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