Pinscape Controller version 1 fork. This is a fork to allow for ongoing bug fixes to the original controller version, from before the major changes for the expansion board project.

Dependencies:   FastIO FastPWM SimpleDMA mbed

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Mon Feb 15 23:03:55 2016 +0000
Revision:
68:edfecf67a931
Parent:
52:63f0a9b45f0c
Finalize USB library updates to fix compatibility problems introduced in USBHAL_KL25Z overhaul.

Who changed what in which revision?

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