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