SD card interface

Committer:
lharoon
Date:
Mon Oct 08 11:14:07 2012 +0000
Revision:
0:22612ae617a0
1st edition

Who changed what in which revision?

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