Control the wondrous spinning-frog game of Zuma's Revenge with a rotating chair and an Airzooka. Maps compass rotation, flex sensor and push button input to USB actions to control Zuma's Revenge (http://www.popcap.com/games/zumas-revenge/online)

Dependencies:   LSM303DLHC mbed

Note that content for USB HID and USB Device is actually from the USBDevice mbed library. However, we made a couple of small changes to this library (allowing USB clicks at a particular location) that required us to break it off from the main project if we wanted to publish without pushing upstream.

Committer:
andrewhead
Date:
Mon Sep 29 01:12:20 2014 +0000
Revision:
0:4df415dde990
Initial Commit.

Who changed what in which revision?

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