Modified for PS3 Joystick

Dependents:   NiseKabuto

Fork of USBDevice by Samuel Mokrani

Committer:
sankichi
Date:
Sat Jul 27 14:05:26 2013 +0000
Revision:
1:ac5cca60029a
Parent:
0:140cdf8e2d60
First Release

Who changed what in which revision?

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