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 #include "USBMouseKeyboard.h"
lharoon 0:22612ae617a0 21
lharoon 0:22612ae617a0 22 typedef struct {
lharoon 0:22612ae617a0 23 unsigned char usage;
lharoon 0:22612ae617a0 24 unsigned char modifier;
lharoon 0:22612ae617a0 25 } KEYMAP;
lharoon 0:22612ae617a0 26
lharoon 0:22612ae617a0 27 #ifdef US_KEYBOARD
lharoon 0:22612ae617a0 28 /* US keyboard (as HID standard) */
lharoon 0:22612ae617a0 29 #define KEYMAP_SIZE (148)
lharoon 0:22612ae617a0 30 const KEYMAP keymap[KEYMAP_SIZE] = {
lharoon 0:22612ae617a0 31 {0, 0}, /* NUL */
lharoon 0:22612ae617a0 32 {0, 0}, /* SOH */
lharoon 0:22612ae617a0 33 {0, 0}, /* STX */
lharoon 0:22612ae617a0 34 {0, 0}, /* ETX */
lharoon 0:22612ae617a0 35 {0, 0}, /* EOT */
lharoon 0:22612ae617a0 36 {0, 0}, /* ENQ */
lharoon 0:22612ae617a0 37 {0, 0}, /* ACK */
lharoon 0:22612ae617a0 38 {0, 0}, /* BEL */
lharoon 0:22612ae617a0 39 {0x2a, 0}, /* BS */ /* Keyboard Delete (Backspace) */
lharoon 0:22612ae617a0 40 {0x2b, 0}, /* TAB */ /* Keyboard Tab */
lharoon 0:22612ae617a0 41 {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */
lharoon 0:22612ae617a0 42 {0, 0}, /* VT */
lharoon 0:22612ae617a0 43 {0, 0}, /* FF */
lharoon 0:22612ae617a0 44 {0, 0}, /* CR */
lharoon 0:22612ae617a0 45 {0, 0}, /* SO */
lharoon 0:22612ae617a0 46 {0, 0}, /* SI */
lharoon 0:22612ae617a0 47 {0, 0}, /* DEL */
lharoon 0:22612ae617a0 48 {0, 0}, /* DC1 */
lharoon 0:22612ae617a0 49 {0, 0}, /* DC2 */
lharoon 0:22612ae617a0 50 {0, 0}, /* DC3 */
lharoon 0:22612ae617a0 51 {0, 0}, /* DC4 */
lharoon 0:22612ae617a0 52 {0, 0}, /* NAK */
lharoon 0:22612ae617a0 53 {0, 0}, /* SYN */
lharoon 0:22612ae617a0 54 {0, 0}, /* ETB */
lharoon 0:22612ae617a0 55 {0, 0}, /* CAN */
lharoon 0:22612ae617a0 56 {0, 0}, /* EM */
lharoon 0:22612ae617a0 57 {0, 0}, /* SUB */
lharoon 0:22612ae617a0 58 {0, 0}, /* ESC */
lharoon 0:22612ae617a0 59 {0, 0}, /* FS */
lharoon 0:22612ae617a0 60 {0, 0}, /* GS */
lharoon 0:22612ae617a0 61 {0, 0}, /* RS */
lharoon 0:22612ae617a0 62 {0, 0}, /* US */
lharoon 0:22612ae617a0 63 {0x2c, 0}, /* */
lharoon 0:22612ae617a0 64 {0x1e, KEY_SHIFT}, /* ! */
lharoon 0:22612ae617a0 65 {0x34, KEY_SHIFT}, /* " */
lharoon 0:22612ae617a0 66 {0x20, KEY_SHIFT}, /* # */
lharoon 0:22612ae617a0 67 {0x21, KEY_SHIFT}, /* $ */
lharoon 0:22612ae617a0 68 {0x22, KEY_SHIFT}, /* % */
lharoon 0:22612ae617a0 69 {0x24, KEY_SHIFT}, /* & */
lharoon 0:22612ae617a0 70 {0x34, 0}, /* ' */
lharoon 0:22612ae617a0 71 {0x26, KEY_SHIFT}, /* ( */
lharoon 0:22612ae617a0 72 {0x27, KEY_SHIFT}, /* ) */
lharoon 0:22612ae617a0 73 {0x25, KEY_SHIFT}, /* * */
lharoon 0:22612ae617a0 74 {0x2e, KEY_SHIFT}, /* + */
lharoon 0:22612ae617a0 75 {0x36, 0}, /* , */
lharoon 0:22612ae617a0 76 {0x2d, 0}, /* - */
lharoon 0:22612ae617a0 77 {0x37, 0}, /* . */
lharoon 0:22612ae617a0 78 {0x38, 0}, /* / */
lharoon 0:22612ae617a0 79 {0x27, 0}, /* 0 */
lharoon 0:22612ae617a0 80 {0x1e, 0}, /* 1 */
lharoon 0:22612ae617a0 81 {0x1f, 0}, /* 2 */
lharoon 0:22612ae617a0 82 {0x20, 0}, /* 3 */
lharoon 0:22612ae617a0 83 {0x21, 0}, /* 4 */
lharoon 0:22612ae617a0 84 {0x22, 0}, /* 5 */
lharoon 0:22612ae617a0 85 {0x23, 0}, /* 6 */
lharoon 0:22612ae617a0 86 {0x24, 0}, /* 7 */
lharoon 0:22612ae617a0 87 {0x25, 0}, /* 8 */
lharoon 0:22612ae617a0 88 {0x26, 0}, /* 9 */
lharoon 0:22612ae617a0 89 {0x33, KEY_SHIFT}, /* : */
lharoon 0:22612ae617a0 90 {0x33, 0}, /* ; */
lharoon 0:22612ae617a0 91 {0x36, KEY_SHIFT}, /* < */
lharoon 0:22612ae617a0 92 {0x2e, 0}, /* = */
lharoon 0:22612ae617a0 93 {0x37, KEY_SHIFT}, /* > */
lharoon 0:22612ae617a0 94 {0x38, KEY_SHIFT}, /* ? */
lharoon 0:22612ae617a0 95 {0x1f, KEY_SHIFT}, /* @ */
lharoon 0:22612ae617a0 96 {0x04, KEY_SHIFT}, /* A */
lharoon 0:22612ae617a0 97 {0x05, KEY_SHIFT}, /* B */
lharoon 0:22612ae617a0 98 {0x06, KEY_SHIFT}, /* C */
lharoon 0:22612ae617a0 99 {0x07, KEY_SHIFT}, /* D */
lharoon 0:22612ae617a0 100 {0x08, KEY_SHIFT}, /* E */
lharoon 0:22612ae617a0 101 {0x09, KEY_SHIFT}, /* F */
lharoon 0:22612ae617a0 102 {0x0a, KEY_SHIFT}, /* G */
lharoon 0:22612ae617a0 103 {0x0b, KEY_SHIFT}, /* H */
lharoon 0:22612ae617a0 104 {0x0c, KEY_SHIFT}, /* I */
lharoon 0:22612ae617a0 105 {0x0d, KEY_SHIFT}, /* J */
lharoon 0:22612ae617a0 106 {0x0e, KEY_SHIFT}, /* K */
lharoon 0:22612ae617a0 107 {0x0f, KEY_SHIFT}, /* L */
lharoon 0:22612ae617a0 108 {0x10, KEY_SHIFT}, /* M */
lharoon 0:22612ae617a0 109 {0x11, KEY_SHIFT}, /* N */
lharoon 0:22612ae617a0 110 {0x12, KEY_SHIFT}, /* O */
lharoon 0:22612ae617a0 111 {0x13, KEY_SHIFT}, /* P */
lharoon 0:22612ae617a0 112 {0x14, KEY_SHIFT}, /* Q */
lharoon 0:22612ae617a0 113 {0x15, KEY_SHIFT}, /* R */
lharoon 0:22612ae617a0 114 {0x16, KEY_SHIFT}, /* S */
lharoon 0:22612ae617a0 115 {0x17, KEY_SHIFT}, /* T */
lharoon 0:22612ae617a0 116 {0x18, KEY_SHIFT}, /* U */
lharoon 0:22612ae617a0 117 {0x19, KEY_SHIFT}, /* V */
lharoon 0:22612ae617a0 118 {0x1a, KEY_SHIFT}, /* W */
lharoon 0:22612ae617a0 119 {0x1b, KEY_SHIFT}, /* X */
lharoon 0:22612ae617a0 120 {0x1c, KEY_SHIFT}, /* Y */
lharoon 0:22612ae617a0 121 {0x1d, KEY_SHIFT}, /* Z */
lharoon 0:22612ae617a0 122 {0x2f, 0}, /* [ */
lharoon 0:22612ae617a0 123 {0x31, 0}, /* \ */
lharoon 0:22612ae617a0 124 {0x30, 0}, /* ] */
lharoon 0:22612ae617a0 125 {0x23, KEY_SHIFT}, /* ^ */
lharoon 0:22612ae617a0 126 {0x2d, KEY_SHIFT}, /* _ */
lharoon 0:22612ae617a0 127 {0x35, 0}, /* ` */
lharoon 0:22612ae617a0 128 {0x04, 0}, /* a */
lharoon 0:22612ae617a0 129 {0x05, 0}, /* b */
lharoon 0:22612ae617a0 130 {0x06, 0}, /* c */
lharoon 0:22612ae617a0 131 {0x07, 0}, /* d */
lharoon 0:22612ae617a0 132 {0x08, 0}, /* e */
lharoon 0:22612ae617a0 133 {0x09, 0}, /* f */
lharoon 0:22612ae617a0 134 {0x0a, 0}, /* g */
lharoon 0:22612ae617a0 135 {0x0b, 0}, /* h */
lharoon 0:22612ae617a0 136 {0x0c, 0}, /* i */
lharoon 0:22612ae617a0 137 {0x0d, 0}, /* j */
lharoon 0:22612ae617a0 138 {0x0e, 0}, /* k */
lharoon 0:22612ae617a0 139 {0x0f, 0}, /* l */
lharoon 0:22612ae617a0 140 {0x10, 0}, /* m */
lharoon 0:22612ae617a0 141 {0x11, 0}, /* n */
lharoon 0:22612ae617a0 142 {0x12, 0}, /* o */
lharoon 0:22612ae617a0 143 {0x13, 0}, /* p */
lharoon 0:22612ae617a0 144 {0x14, 0}, /* q */
lharoon 0:22612ae617a0 145 {0x15, 0}, /* r */
lharoon 0:22612ae617a0 146 {0x16, 0}, /* s */
lharoon 0:22612ae617a0 147 {0x17, 0}, /* t */
lharoon 0:22612ae617a0 148 {0x18, 0}, /* u */
lharoon 0:22612ae617a0 149 {0x19, 0}, /* v */
lharoon 0:22612ae617a0 150 {0x1a, 0}, /* w */
lharoon 0:22612ae617a0 151 {0x1b, 0}, /* x */
lharoon 0:22612ae617a0 152 {0x1c, 0}, /* y */
lharoon 0:22612ae617a0 153 {0x1d, 0}, /* z */
lharoon 0:22612ae617a0 154 {0x2f, KEY_SHIFT}, /* { */
lharoon 0:22612ae617a0 155 {0x31, KEY_SHIFT}, /* | */
lharoon 0:22612ae617a0 156 {0x30, KEY_SHIFT}, /* } */
lharoon 0:22612ae617a0 157 {0x35, KEY_SHIFT}, /* ~ */
lharoon 0:22612ae617a0 158 {0,0}, /* DEL */
lharoon 0:22612ae617a0 159
lharoon 0:22612ae617a0 160 {0x3a, 0}, /* F1 */
lharoon 0:22612ae617a0 161 {0x3b, 0}, /* F2 */
lharoon 0:22612ae617a0 162 {0x3c, 0}, /* F3 */
lharoon 0:22612ae617a0 163 {0x3d, 0}, /* F4 */
lharoon 0:22612ae617a0 164 {0x3e, 0}, /* F5 */
lharoon 0:22612ae617a0 165 {0x3f, 0}, /* F6 */
lharoon 0:22612ae617a0 166 {0x40, 0}, /* F7 */
lharoon 0:22612ae617a0 167 {0x41, 0}, /* F8 */
lharoon 0:22612ae617a0 168 {0x42, 0}, /* F9 */
lharoon 0:22612ae617a0 169 {0x43, 0}, /* F10 */
lharoon 0:22612ae617a0 170 {0x44, 0}, /* F11 */
lharoon 0:22612ae617a0 171 {0x45, 0}, /* F12 */
lharoon 0:22612ae617a0 172
lharoon 0:22612ae617a0 173 {0x46, 0}, /* PRINT_SCREEN */
lharoon 0:22612ae617a0 174 {0x47, 0}, /* SCROLL_LOCK */
lharoon 0:22612ae617a0 175 {0x39, 0}, /* CAPS_LOCK */
lharoon 0:22612ae617a0 176 {0x53, 0}, /* NUM_LOCK */
lharoon 0:22612ae617a0 177 {0x49, 0}, /* INSERT */
lharoon 0:22612ae617a0 178 {0x4a, 0}, /* HOME */
lharoon 0:22612ae617a0 179 {0x4b, 0}, /* PAGE_UP */
lharoon 0:22612ae617a0 180 {0x4e, 0}, /* PAGE_DOWN */
lharoon 0:22612ae617a0 181 };
lharoon 0:22612ae617a0 182
lharoon 0:22612ae617a0 183 #else
lharoon 0:22612ae617a0 184 /* UK keyboard */
lharoon 0:22612ae617a0 185 #define KEYMAP_SIZE (148)
lharoon 0:22612ae617a0 186 const KEYMAP keymap[KEYMAP_SIZE] = {
lharoon 0:22612ae617a0 187 {0, 0}, /* NUL */
lharoon 0:22612ae617a0 188 {0, 0}, /* SOH */
lharoon 0:22612ae617a0 189 {0, 0}, /* STX */
lharoon 0:22612ae617a0 190 {0, 0}, /* ETX */
lharoon 0:22612ae617a0 191 {0, 0}, /* EOT */
lharoon 0:22612ae617a0 192 {0, 0}, /* ENQ */
lharoon 0:22612ae617a0 193 {0, 0}, /* ACK */
lharoon 0:22612ae617a0 194 {0, 0}, /* BEL */
lharoon 0:22612ae617a0 195 {0x2a, 0}, /* BS */ /* Keyboard Delete (Backspace) */
lharoon 0:22612ae617a0 196 {0x2b, 0}, /* TAB */ /* Keyboard Tab */
lharoon 0:22612ae617a0 197 {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */
lharoon 0:22612ae617a0 198 {0, 0}, /* VT */
lharoon 0:22612ae617a0 199 {0, 0}, /* FF */
lharoon 0:22612ae617a0 200 {0, 0}, /* CR */
lharoon 0:22612ae617a0 201 {0, 0}, /* SO */
lharoon 0:22612ae617a0 202 {0, 0}, /* SI */
lharoon 0:22612ae617a0 203 {0, 0}, /* DEL */
lharoon 0:22612ae617a0 204 {0, 0}, /* DC1 */
lharoon 0:22612ae617a0 205 {0, 0}, /* DC2 */
lharoon 0:22612ae617a0 206 {0, 0}, /* DC3 */
lharoon 0:22612ae617a0 207 {0, 0}, /* DC4 */
lharoon 0:22612ae617a0 208 {0, 0}, /* NAK */
lharoon 0:22612ae617a0 209 {0, 0}, /* SYN */
lharoon 0:22612ae617a0 210 {0, 0}, /* ETB */
lharoon 0:22612ae617a0 211 {0, 0}, /* CAN */
lharoon 0:22612ae617a0 212 {0, 0}, /* EM */
lharoon 0:22612ae617a0 213 {0, 0}, /* SUB */
lharoon 0:22612ae617a0 214 {0, 0}, /* ESC */
lharoon 0:22612ae617a0 215 {0, 0}, /* FS */
lharoon 0:22612ae617a0 216 {0, 0}, /* GS */
lharoon 0:22612ae617a0 217 {0, 0}, /* RS */
lharoon 0:22612ae617a0 218 {0, 0}, /* US */
lharoon 0:22612ae617a0 219 {0x2c, 0}, /* */
lharoon 0:22612ae617a0 220 {0x1e, KEY_SHIFT}, /* ! */
lharoon 0:22612ae617a0 221 {0x1f, KEY_SHIFT}, /* " */
lharoon 0:22612ae617a0 222 {0x32, 0}, /* # */
lharoon 0:22612ae617a0 223 {0x21, KEY_SHIFT}, /* $ */
lharoon 0:22612ae617a0 224 {0x22, KEY_SHIFT}, /* % */
lharoon 0:22612ae617a0 225 {0x24, KEY_SHIFT}, /* & */
lharoon 0:22612ae617a0 226 {0x34, 0}, /* ' */
lharoon 0:22612ae617a0 227 {0x26, KEY_SHIFT}, /* ( */
lharoon 0:22612ae617a0 228 {0x27, KEY_SHIFT}, /* ) */
lharoon 0:22612ae617a0 229 {0x25, KEY_SHIFT}, /* * */
lharoon 0:22612ae617a0 230 {0x2e, KEY_SHIFT}, /* + */
lharoon 0:22612ae617a0 231 {0x36, 0}, /* , */
lharoon 0:22612ae617a0 232 {0x2d, 0}, /* - */
lharoon 0:22612ae617a0 233 {0x37, 0}, /* . */
lharoon 0:22612ae617a0 234 {0x38, 0}, /* / */
lharoon 0:22612ae617a0 235 {0x27, 0}, /* 0 */
lharoon 0:22612ae617a0 236 {0x1e, 0}, /* 1 */
lharoon 0:22612ae617a0 237 {0x1f, 0}, /* 2 */
lharoon 0:22612ae617a0 238 {0x20, 0}, /* 3 */
lharoon 0:22612ae617a0 239 {0x21, 0}, /* 4 */
lharoon 0:22612ae617a0 240 {0x22, 0}, /* 5 */
lharoon 0:22612ae617a0 241 {0x23, 0}, /* 6 */
lharoon 0:22612ae617a0 242 {0x24, 0}, /* 7 */
lharoon 0:22612ae617a0 243 {0x25, 0}, /* 8 */
lharoon 0:22612ae617a0 244 {0x26, 0}, /* 9 */
lharoon 0:22612ae617a0 245 {0x33, KEY_SHIFT}, /* : */
lharoon 0:22612ae617a0 246 {0x33, 0}, /* ; */
lharoon 0:22612ae617a0 247 {0x36, KEY_SHIFT}, /* < */
lharoon 0:22612ae617a0 248 {0x2e, 0}, /* = */
lharoon 0:22612ae617a0 249 {0x37, KEY_SHIFT}, /* > */
lharoon 0:22612ae617a0 250 {0x38, KEY_SHIFT}, /* ? */
lharoon 0:22612ae617a0 251 {0x34, KEY_SHIFT}, /* @ */
lharoon 0:22612ae617a0 252 {0x04, KEY_SHIFT}, /* A */
lharoon 0:22612ae617a0 253 {0x05, KEY_SHIFT}, /* B */
lharoon 0:22612ae617a0 254 {0x06, KEY_SHIFT}, /* C */
lharoon 0:22612ae617a0 255 {0x07, KEY_SHIFT}, /* D */
lharoon 0:22612ae617a0 256 {0x08, KEY_SHIFT}, /* E */
lharoon 0:22612ae617a0 257 {0x09, KEY_SHIFT}, /* F */
lharoon 0:22612ae617a0 258 {0x0a, KEY_SHIFT}, /* G */
lharoon 0:22612ae617a0 259 {0x0b, KEY_SHIFT}, /* H */
lharoon 0:22612ae617a0 260 {0x0c, KEY_SHIFT}, /* I */
lharoon 0:22612ae617a0 261 {0x0d, KEY_SHIFT}, /* J */
lharoon 0:22612ae617a0 262 {0x0e, KEY_SHIFT}, /* K */
lharoon 0:22612ae617a0 263 {0x0f, KEY_SHIFT}, /* L */
lharoon 0:22612ae617a0 264 {0x10, KEY_SHIFT}, /* M */
lharoon 0:22612ae617a0 265 {0x11, KEY_SHIFT}, /* N */
lharoon 0:22612ae617a0 266 {0x12, KEY_SHIFT}, /* O */
lharoon 0:22612ae617a0 267 {0x13, KEY_SHIFT}, /* P */
lharoon 0:22612ae617a0 268 {0x14, KEY_SHIFT}, /* Q */
lharoon 0:22612ae617a0 269 {0x15, KEY_SHIFT}, /* R */
lharoon 0:22612ae617a0 270 {0x16, KEY_SHIFT}, /* S */
lharoon 0:22612ae617a0 271 {0x17, KEY_SHIFT}, /* T */
lharoon 0:22612ae617a0 272 {0x18, KEY_SHIFT}, /* U */
lharoon 0:22612ae617a0 273 {0x19, KEY_SHIFT}, /* V */
lharoon 0:22612ae617a0 274 {0x1a, KEY_SHIFT}, /* W */
lharoon 0:22612ae617a0 275 {0x1b, KEY_SHIFT}, /* X */
lharoon 0:22612ae617a0 276 {0x1c, KEY_SHIFT}, /* Y */
lharoon 0:22612ae617a0 277 {0x1d, KEY_SHIFT}, /* Z */
lharoon 0:22612ae617a0 278 {0x2f, 0}, /* [ */
lharoon 0:22612ae617a0 279 {0x64, 0}, /* \ */
lharoon 0:22612ae617a0 280 {0x30, 0}, /* ] */
lharoon 0:22612ae617a0 281 {0x23, KEY_SHIFT}, /* ^ */
lharoon 0:22612ae617a0 282 {0x2d, KEY_SHIFT}, /* _ */
lharoon 0:22612ae617a0 283 {0x35, 0}, /* ` */
lharoon 0:22612ae617a0 284 {0x04, 0}, /* a */
lharoon 0:22612ae617a0 285 {0x05, 0}, /* b */
lharoon 0:22612ae617a0 286 {0x06, 0}, /* c */
lharoon 0:22612ae617a0 287 {0x07, 0}, /* d */
lharoon 0:22612ae617a0 288 {0x08, 0}, /* e */
lharoon 0:22612ae617a0 289 {0x09, 0}, /* f */
lharoon 0:22612ae617a0 290 {0x0a, 0}, /* g */
lharoon 0:22612ae617a0 291 {0x0b, 0}, /* h */
lharoon 0:22612ae617a0 292 {0x0c, 0}, /* i */
lharoon 0:22612ae617a0 293 {0x0d, 0}, /* j */
lharoon 0:22612ae617a0 294 {0x0e, 0}, /* k */
lharoon 0:22612ae617a0 295 {0x0f, 0}, /* l */
lharoon 0:22612ae617a0 296 {0x10, 0}, /* m */
lharoon 0:22612ae617a0 297 {0x11, 0}, /* n */
lharoon 0:22612ae617a0 298 {0x12, 0}, /* o */
lharoon 0:22612ae617a0 299 {0x13, 0}, /* p */
lharoon 0:22612ae617a0 300 {0x14, 0}, /* q */
lharoon 0:22612ae617a0 301 {0x15, 0}, /* r */
lharoon 0:22612ae617a0 302 {0x16, 0}, /* s */
lharoon 0:22612ae617a0 303 {0x17, 0}, /* t */
lharoon 0:22612ae617a0 304 {0x18, 0}, /* u */
lharoon 0:22612ae617a0 305 {0x19, 0}, /* v */
lharoon 0:22612ae617a0 306 {0x1a, 0}, /* w */
lharoon 0:22612ae617a0 307 {0x1b, 0}, /* x */
lharoon 0:22612ae617a0 308 {0x1c, 0}, /* y */
lharoon 0:22612ae617a0 309 {0x1d, 0}, /* z */
lharoon 0:22612ae617a0 310 {0x2f, KEY_SHIFT}, /* { */
lharoon 0:22612ae617a0 311 {0x64, KEY_SHIFT}, /* | */
lharoon 0:22612ae617a0 312 {0x30, KEY_SHIFT}, /* } */
lharoon 0:22612ae617a0 313 {0x32, KEY_SHIFT}, /* ~ */
lharoon 0:22612ae617a0 314 {0,0}, /* DEL */
lharoon 0:22612ae617a0 315
lharoon 0:22612ae617a0 316 {0x3a, 0}, /* F1 */
lharoon 0:22612ae617a0 317 {0x3b, 0}, /* F2 */
lharoon 0:22612ae617a0 318 {0x3c, 0}, /* F3 */
lharoon 0:22612ae617a0 319 {0x3d, 0}, /* F4 */
lharoon 0:22612ae617a0 320 {0x3e, 0}, /* F5 */
lharoon 0:22612ae617a0 321 {0x3f, 0}, /* F6 */
lharoon 0:22612ae617a0 322 {0x40, 0}, /* F7 */
lharoon 0:22612ae617a0 323 {0x41, 0}, /* F8 */
lharoon 0:22612ae617a0 324 {0x42, 0}, /* F9 */
lharoon 0:22612ae617a0 325 {0x43, 0}, /* F10 */
lharoon 0:22612ae617a0 326 {0x44, 0}, /* F11 */
lharoon 0:22612ae617a0 327 {0x45, 0}, /* F12 */
lharoon 0:22612ae617a0 328
lharoon 0:22612ae617a0 329 {0x46, 0}, /* PRINT_SCREEN */
lharoon 0:22612ae617a0 330 {0x47, 0}, /* SCROLL_LOCK */
lharoon 0:22612ae617a0 331 {0x39, 0}, /* CAPS_LOCK */
lharoon 0:22612ae617a0 332 {0x53, 0}, /* NUM_LOCK */
lharoon 0:22612ae617a0 333 {0x49, 0}, /* INSERT */
lharoon 0:22612ae617a0 334 {0x4a, 0}, /* HOME */
lharoon 0:22612ae617a0 335 {0x4b, 0}, /* PAGE_UP */
lharoon 0:22612ae617a0 336 {0x4e, 0}, /* PAGE_DOWN */
lharoon 0:22612ae617a0 337 };
lharoon 0:22612ae617a0 338 #endif
lharoon 0:22612ae617a0 339
lharoon 0:22612ae617a0 340
lharoon 0:22612ae617a0 341 uint8_t * USBMouseKeyboard::reportDesc() {
lharoon 0:22612ae617a0 342 if (mouse_type == REL_MOUSE) {
lharoon 0:22612ae617a0 343 static uint8_t reportDescriptor[] = {
lharoon 0:22612ae617a0 344 // Keyboard
lharoon 0:22612ae617a0 345 USAGE_PAGE(1), 0x01,
lharoon 0:22612ae617a0 346 USAGE(1), 0x06,
lharoon 0:22612ae617a0 347 COLLECTION(1), 0x01,
lharoon 0:22612ae617a0 348 REPORT_ID(1), REPORT_ID_KEYBOARD,
lharoon 0:22612ae617a0 349 USAGE_PAGE(1), 0x07,
lharoon 0:22612ae617a0 350 USAGE_MINIMUM(1), 0xE0,
lharoon 0:22612ae617a0 351 USAGE_MAXIMUM(1), 0xE7,
lharoon 0:22612ae617a0 352 LOGICAL_MINIMUM(1), 0x00,
lharoon 0:22612ae617a0 353 LOGICAL_MAXIMUM(1), 0x01,
lharoon 0:22612ae617a0 354 REPORT_SIZE(1), 0x01,
lharoon 0:22612ae617a0 355 REPORT_COUNT(1), 0x08,
lharoon 0:22612ae617a0 356 INPUT(1), 0x02,
lharoon 0:22612ae617a0 357 REPORT_COUNT(1), 0x01,
lharoon 0:22612ae617a0 358 REPORT_SIZE(1), 0x08,
lharoon 0:22612ae617a0 359 INPUT(1), 0x01,
lharoon 0:22612ae617a0 360 REPORT_COUNT(1), 0x05,
lharoon 0:22612ae617a0 361 REPORT_SIZE(1), 0x01,
lharoon 0:22612ae617a0 362 USAGE_PAGE(1), 0x08,
lharoon 0:22612ae617a0 363 USAGE_MINIMUM(1), 0x01,
lharoon 0:22612ae617a0 364 USAGE_MAXIMUM(1), 0x05,
lharoon 0:22612ae617a0 365 OUTPUT(1), 0x02,
lharoon 0:22612ae617a0 366 REPORT_COUNT(1), 0x01,
lharoon 0:22612ae617a0 367 REPORT_SIZE(1), 0x03,
lharoon 0:22612ae617a0 368 OUTPUT(1), 0x01,
lharoon 0:22612ae617a0 369 REPORT_COUNT(1), 0x06,
lharoon 0:22612ae617a0 370 REPORT_SIZE(1), 0x08,
lharoon 0:22612ae617a0 371 LOGICAL_MINIMUM(1), 0x00,
lharoon 0:22612ae617a0 372 LOGICAL_MAXIMUM(2), 0xff, 0x00,
lharoon 0:22612ae617a0 373 USAGE_PAGE(1), 0x07,
lharoon 0:22612ae617a0 374 USAGE_MINIMUM(1), 0x00,
lharoon 0:22612ae617a0 375 USAGE_MAXIMUM(2), 0xff, 0x00,
lharoon 0:22612ae617a0 376 INPUT(1), 0x00,
lharoon 0:22612ae617a0 377 END_COLLECTION(0),
lharoon 0:22612ae617a0 378
lharoon 0:22612ae617a0 379 // Mouse
lharoon 0:22612ae617a0 380 USAGE_PAGE(1), 0x01, // Generic Desktop
lharoon 0:22612ae617a0 381 USAGE(1), 0x02, // Mouse
lharoon 0:22612ae617a0 382 COLLECTION(1), 0x01, // Application
lharoon 0:22612ae617a0 383 USAGE(1), 0x01, // Pointer
lharoon 0:22612ae617a0 384 COLLECTION(1), 0x00, // Physical
lharoon 0:22612ae617a0 385 REPORT_ID(1), REPORT_ID_MOUSE,
lharoon 0:22612ae617a0 386 REPORT_COUNT(1), 0x03,
lharoon 0:22612ae617a0 387 REPORT_SIZE(1), 0x01,
lharoon 0:22612ae617a0 388 USAGE_PAGE(1), 0x09, // Buttons
lharoon 0:22612ae617a0 389 USAGE_MINIMUM(1), 0x1,
lharoon 0:22612ae617a0 390 USAGE_MAXIMUM(1), 0x3,
lharoon 0:22612ae617a0 391 LOGICAL_MINIMUM(1), 0x00,
lharoon 0:22612ae617a0 392 LOGICAL_MAXIMUM(1), 0x01,
lharoon 0:22612ae617a0 393 INPUT(1), 0x02,
lharoon 0:22612ae617a0 394 REPORT_COUNT(1), 0x01,
lharoon 0:22612ae617a0 395 REPORT_SIZE(1), 0x05,
lharoon 0:22612ae617a0 396 INPUT(1), 0x01,
lharoon 0:22612ae617a0 397 REPORT_COUNT(1), 0x03,
lharoon 0:22612ae617a0 398 REPORT_SIZE(1), 0x08,
lharoon 0:22612ae617a0 399 USAGE_PAGE(1), 0x01,
lharoon 0:22612ae617a0 400 USAGE(1), 0x30, // X
lharoon 0:22612ae617a0 401 USAGE(1), 0x31, // Y
lharoon 0:22612ae617a0 402 USAGE(1), 0x38, // scroll
lharoon 0:22612ae617a0 403 LOGICAL_MINIMUM(1), 0x81,
lharoon 0:22612ae617a0 404 LOGICAL_MAXIMUM(1), 0x7f,
lharoon 0:22612ae617a0 405 INPUT(1), 0x06,
lharoon 0:22612ae617a0 406 END_COLLECTION(0),
lharoon 0:22612ae617a0 407 END_COLLECTION(0),
lharoon 0:22612ae617a0 408
lharoon 0:22612ae617a0 409
lharoon 0:22612ae617a0 410 // Media Control
lharoon 0:22612ae617a0 411 USAGE_PAGE(1), 0x0C,
lharoon 0:22612ae617a0 412 USAGE(1), 0x01,
lharoon 0:22612ae617a0 413 COLLECTION(1), 0x01,
lharoon 0:22612ae617a0 414 REPORT_ID(1), REPORT_ID_VOLUME,
lharoon 0:22612ae617a0 415 USAGE_PAGE(1), 0x0C,
lharoon 0:22612ae617a0 416 LOGICAL_MINIMUM(1), 0x00,
lharoon 0:22612ae617a0 417 LOGICAL_MAXIMUM(1), 0x01,
lharoon 0:22612ae617a0 418 REPORT_SIZE(1), 0x01,
lharoon 0:22612ae617a0 419 REPORT_COUNT(1), 0x07,
lharoon 0:22612ae617a0 420 USAGE(1), 0xB5, // Next Track
lharoon 0:22612ae617a0 421 USAGE(1), 0xB6, // Previous Track
lharoon 0:22612ae617a0 422 USAGE(1), 0xB7, // Stop
lharoon 0:22612ae617a0 423 USAGE(1), 0xCD, // Play / Pause
lharoon 0:22612ae617a0 424 USAGE(1), 0xE2, // Mute
lharoon 0:22612ae617a0 425 USAGE(1), 0xE9, // Volume Up
lharoon 0:22612ae617a0 426 USAGE(1), 0xEA, // Volume Down
lharoon 0:22612ae617a0 427 INPUT(1), 0x02, // Input (Data, Variable, Absolute)
lharoon 0:22612ae617a0 428 REPORT_COUNT(1), 0x01,
lharoon 0:22612ae617a0 429 INPUT(1), 0x01,
lharoon 0:22612ae617a0 430 END_COLLECTION(0),
lharoon 0:22612ae617a0 431 };
lharoon 0:22612ae617a0 432 reportLength = sizeof(reportDescriptor);
lharoon 0:22612ae617a0 433 return reportDescriptor;
lharoon 0:22612ae617a0 434 } else if (mouse_type == ABS_MOUSE) {
lharoon 0:22612ae617a0 435 static uint8_t reportDescriptor[] = {
lharoon 0:22612ae617a0 436
lharoon 0:22612ae617a0 437 // Keyboard
lharoon 0:22612ae617a0 438 USAGE_PAGE(1), 0x01,
lharoon 0:22612ae617a0 439 USAGE(1), 0x06,
lharoon 0:22612ae617a0 440 COLLECTION(1), 0x01,
lharoon 0:22612ae617a0 441 REPORT_ID(1), REPORT_ID_KEYBOARD,
lharoon 0:22612ae617a0 442 USAGE_PAGE(1), 0x07,
lharoon 0:22612ae617a0 443 USAGE_MINIMUM(1), 0xE0,
lharoon 0:22612ae617a0 444 USAGE_MAXIMUM(1), 0xE7,
lharoon 0:22612ae617a0 445 LOGICAL_MINIMUM(1), 0x00,
lharoon 0:22612ae617a0 446 LOGICAL_MAXIMUM(1), 0x01,
lharoon 0:22612ae617a0 447 REPORT_SIZE(1), 0x01,
lharoon 0:22612ae617a0 448 REPORT_COUNT(1), 0x08,
lharoon 0:22612ae617a0 449 INPUT(1), 0x02,
lharoon 0:22612ae617a0 450 REPORT_COUNT(1), 0x01,
lharoon 0:22612ae617a0 451 REPORT_SIZE(1), 0x08,
lharoon 0:22612ae617a0 452 INPUT(1), 0x01,
lharoon 0:22612ae617a0 453 REPORT_COUNT(1), 0x05,
lharoon 0:22612ae617a0 454 REPORT_SIZE(1), 0x01,
lharoon 0:22612ae617a0 455 USAGE_PAGE(1), 0x08,
lharoon 0:22612ae617a0 456 USAGE_MINIMUM(1), 0x01,
lharoon 0:22612ae617a0 457 USAGE_MAXIMUM(1), 0x05,
lharoon 0:22612ae617a0 458 OUTPUT(1), 0x02,
lharoon 0:22612ae617a0 459 REPORT_COUNT(1), 0x01,
lharoon 0:22612ae617a0 460 REPORT_SIZE(1), 0x03,
lharoon 0:22612ae617a0 461 OUTPUT(1), 0x01,
lharoon 0:22612ae617a0 462 REPORT_COUNT(1), 0x06,
lharoon 0:22612ae617a0 463 REPORT_SIZE(1), 0x08,
lharoon 0:22612ae617a0 464 LOGICAL_MINIMUM(1), 0x00,
lharoon 0:22612ae617a0 465 LOGICAL_MAXIMUM(2), 0xff, 0x00,
lharoon 0:22612ae617a0 466 USAGE_PAGE(1), 0x07,
lharoon 0:22612ae617a0 467 USAGE_MINIMUM(1), 0x00,
lharoon 0:22612ae617a0 468 USAGE_MAXIMUM(2), 0xff, 0x00,
lharoon 0:22612ae617a0 469 INPUT(1), 0x00,
lharoon 0:22612ae617a0 470 END_COLLECTION(0),
lharoon 0:22612ae617a0 471
lharoon 0:22612ae617a0 472 // Mouse
lharoon 0:22612ae617a0 473 USAGE_PAGE(1), 0x01, // Generic Desktop
lharoon 0:22612ae617a0 474 USAGE(1), 0x02, // Mouse
lharoon 0:22612ae617a0 475 COLLECTION(1), 0x01, // Application
lharoon 0:22612ae617a0 476 USAGE(1), 0x01, // Pointer
lharoon 0:22612ae617a0 477 COLLECTION(1), 0x00, // Physical
lharoon 0:22612ae617a0 478 REPORT_ID(1), REPORT_ID_MOUSE,
lharoon 0:22612ae617a0 479
lharoon 0:22612ae617a0 480 USAGE_PAGE(1), 0x01, // Generic Desktop
lharoon 0:22612ae617a0 481 USAGE(1), 0x30, // X
lharoon 0:22612ae617a0 482 USAGE(1), 0x31, // Y
lharoon 0:22612ae617a0 483 LOGICAL_MINIMUM(1), 0x00, // 0
lharoon 0:22612ae617a0 484 LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767
lharoon 0:22612ae617a0 485 REPORT_SIZE(1), 0x10,
lharoon 0:22612ae617a0 486 REPORT_COUNT(1), 0x02,
lharoon 0:22612ae617a0 487 INPUT(1), 0x02, // Data, Variable, Absolute
lharoon 0:22612ae617a0 488
lharoon 0:22612ae617a0 489 USAGE_PAGE(1), 0x01, // Generic Desktop
lharoon 0:22612ae617a0 490 USAGE(1), 0x38, // scroll
lharoon 0:22612ae617a0 491 LOGICAL_MINIMUM(1), 0x81, // -127
lharoon 0:22612ae617a0 492 LOGICAL_MAXIMUM(1), 0x7f, // 127
lharoon 0:22612ae617a0 493 REPORT_SIZE(1), 0x08,
lharoon 0:22612ae617a0 494 REPORT_COUNT(1), 0x01,
lharoon 0:22612ae617a0 495 INPUT(1), 0x06, // Data, Variable, Relative
lharoon 0:22612ae617a0 496
lharoon 0:22612ae617a0 497 USAGE_PAGE(1), 0x09, // Buttons
lharoon 0:22612ae617a0 498 USAGE_MINIMUM(1), 0x01,
lharoon 0:22612ae617a0 499 USAGE_MAXIMUM(1), 0x03,
lharoon 0:22612ae617a0 500 LOGICAL_MINIMUM(1), 0x00, // 0
lharoon 0:22612ae617a0 501 LOGICAL_MAXIMUM(1), 0x01, // 1
lharoon 0:22612ae617a0 502 REPORT_COUNT(1), 0x03,
lharoon 0:22612ae617a0 503 REPORT_SIZE(1), 0x01,
lharoon 0:22612ae617a0 504 INPUT(1), 0x02, // Data, Variable, Absolute
lharoon 0:22612ae617a0 505 REPORT_COUNT(1), 0x01,
lharoon 0:22612ae617a0 506 REPORT_SIZE(1), 0x05,
lharoon 0:22612ae617a0 507 INPUT(1), 0x01, // Constant
lharoon 0:22612ae617a0 508
lharoon 0:22612ae617a0 509 END_COLLECTION(0),
lharoon 0:22612ae617a0 510 END_COLLECTION(0),
lharoon 0:22612ae617a0 511
lharoon 0:22612ae617a0 512 // Media Control
lharoon 0:22612ae617a0 513 USAGE_PAGE(1), 0x0C,
lharoon 0:22612ae617a0 514 USAGE(1), 0x01,
lharoon 0:22612ae617a0 515 COLLECTION(1), 0x01,
lharoon 0:22612ae617a0 516 REPORT_ID(1), REPORT_ID_VOLUME,
lharoon 0:22612ae617a0 517 USAGE_PAGE(1), 0x0C,
lharoon 0:22612ae617a0 518 LOGICAL_MINIMUM(1), 0x00,
lharoon 0:22612ae617a0 519 LOGICAL_MAXIMUM(1), 0x01,
lharoon 0:22612ae617a0 520 REPORT_SIZE(1), 0x01,
lharoon 0:22612ae617a0 521 REPORT_COUNT(1), 0x07,
lharoon 0:22612ae617a0 522 USAGE(1), 0xB5, // Next Track
lharoon 0:22612ae617a0 523 USAGE(1), 0xB6, // Previous Track
lharoon 0:22612ae617a0 524 USAGE(1), 0xB7, // Stop
lharoon 0:22612ae617a0 525 USAGE(1), 0xCD, // Play / Pause
lharoon 0:22612ae617a0 526 USAGE(1), 0xE2, // Mute
lharoon 0:22612ae617a0 527 USAGE(1), 0xE9, // Volume Up
lharoon 0:22612ae617a0 528 USAGE(1), 0xEA, // Volume Down
lharoon 0:22612ae617a0 529 INPUT(1), 0x02, // Input (Data, Variable, Absolute)
lharoon 0:22612ae617a0 530 REPORT_COUNT(1), 0x01,
lharoon 0:22612ae617a0 531 INPUT(1), 0x01,
lharoon 0:22612ae617a0 532 END_COLLECTION(0),
lharoon 0:22612ae617a0 533 };
lharoon 0:22612ae617a0 534 reportLength = sizeof(reportDescriptor);
lharoon 0:22612ae617a0 535 return reportDescriptor;
lharoon 0:22612ae617a0 536 }
lharoon 0:22612ae617a0 537
lharoon 0:22612ae617a0 538 return NULL;
lharoon 0:22612ae617a0 539 }
lharoon 0:22612ae617a0 540
lharoon 0:22612ae617a0 541 bool USBMouseKeyboard::EP1_OUT_callback() {
lharoon 0:22612ae617a0 542 uint16_t bytesRead = 0;
lharoon 0:22612ae617a0 543 uint8_t led[65];
lharoon 0:22612ae617a0 544 USBDevice::readEP(EPINT_OUT, led, &bytesRead, MAX_HID_REPORT_SIZE);
lharoon 0:22612ae617a0 545
lharoon 0:22612ae617a0 546 // we take led[1] because led[0] is the report ID
lharoon 0:22612ae617a0 547 lock_status = led[1] & 0x07;
lharoon 0:22612ae617a0 548
lharoon 0:22612ae617a0 549 // We activate the endpoint to be able to recceive data
lharoon 0:22612ae617a0 550 if (!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
lharoon 0:22612ae617a0 551 return false;
lharoon 0:22612ae617a0 552 return true;
lharoon 0:22612ae617a0 553 }
lharoon 0:22612ae617a0 554
lharoon 0:22612ae617a0 555 uint8_t USBMouseKeyboard::lockStatus() {
lharoon 0:22612ae617a0 556 return lock_status;
lharoon 0:22612ae617a0 557 }
lharoon 0:22612ae617a0 558
lharoon 0:22612ae617a0 559 bool USBMouseKeyboard::update(int16_t x, int16_t y, uint8_t button, int8_t z) {
lharoon 0:22612ae617a0 560 switch (mouse_type) {
lharoon 0:22612ae617a0 561 case REL_MOUSE:
lharoon 0:22612ae617a0 562 while (x > 127) {
lharoon 0:22612ae617a0 563 if (!mouseSend(127, 0, button, z)) return false;
lharoon 0:22612ae617a0 564 x = x - 127;
lharoon 0:22612ae617a0 565 }
lharoon 0:22612ae617a0 566 while (x < -128) {
lharoon 0:22612ae617a0 567 if (!mouseSend(-128, 0, button, z)) return false;
lharoon 0:22612ae617a0 568 x = x + 128;
lharoon 0:22612ae617a0 569 }
lharoon 0:22612ae617a0 570 while (y > 127) {
lharoon 0:22612ae617a0 571 if (!mouseSend(0, 127, button, z)) return false;
lharoon 0:22612ae617a0 572 y = y - 127;
lharoon 0:22612ae617a0 573 }
lharoon 0:22612ae617a0 574 while (y < -128) {
lharoon 0:22612ae617a0 575 if (!mouseSend(0, -128, button, z)) return false;
lharoon 0:22612ae617a0 576 y = y + 128;
lharoon 0:22612ae617a0 577 }
lharoon 0:22612ae617a0 578 return mouseSend(x, y, button, z);
lharoon 0:22612ae617a0 579 case ABS_MOUSE:
lharoon 0:22612ae617a0 580 HID_REPORT report;
lharoon 0:22612ae617a0 581
lharoon 0:22612ae617a0 582 report.data[0] = REPORT_ID_MOUSE;
lharoon 0:22612ae617a0 583 report.data[1] = x & 0xff;
lharoon 0:22612ae617a0 584 report.data[2] = (x >> 8) & 0xff;
lharoon 0:22612ae617a0 585 report.data[3] = y & 0xff;
lharoon 0:22612ae617a0 586 report.data[4] = (y >> 8) & 0xff;
lharoon 0:22612ae617a0 587 report.data[5] = -z;
lharoon 0:22612ae617a0 588 report.data[6] = button & 0x07;
lharoon 0:22612ae617a0 589
lharoon 0:22612ae617a0 590 report.length = 7;
lharoon 0:22612ae617a0 591
lharoon 0:22612ae617a0 592 return send(&report);
lharoon 0:22612ae617a0 593 default:
lharoon 0:22612ae617a0 594 return false;
lharoon 0:22612ae617a0 595 }
lharoon 0:22612ae617a0 596 }
lharoon 0:22612ae617a0 597
lharoon 0:22612ae617a0 598 bool USBMouseKeyboard::mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z) {
lharoon 0:22612ae617a0 599 HID_REPORT report;
lharoon 0:22612ae617a0 600 report.data[0] = REPORT_ID_MOUSE;
lharoon 0:22612ae617a0 601 report.data[1] = buttons & 0x07;
lharoon 0:22612ae617a0 602 report.data[2] = x;
lharoon 0:22612ae617a0 603 report.data[3] = y;
lharoon 0:22612ae617a0 604 report.data[4] = -z; // >0 to scroll down, <0 to scroll up
lharoon 0:22612ae617a0 605
lharoon 0:22612ae617a0 606 report.length = 5;
lharoon 0:22612ae617a0 607
lharoon 0:22612ae617a0 608 return send(&report);
lharoon 0:22612ae617a0 609 }
lharoon 0:22612ae617a0 610
lharoon 0:22612ae617a0 611 bool USBMouseKeyboard::move(int16_t x, int16_t y) {
lharoon 0:22612ae617a0 612 return update(x, y, button, 0);
lharoon 0:22612ae617a0 613 }
lharoon 0:22612ae617a0 614
lharoon 0:22612ae617a0 615 bool USBMouseKeyboard::scroll(int8_t z) {
lharoon 0:22612ae617a0 616 return update(0, 0, button, z);
lharoon 0:22612ae617a0 617 }
lharoon 0:22612ae617a0 618
lharoon 0:22612ae617a0 619 bool USBMouseKeyboard::doubleClick() {
lharoon 0:22612ae617a0 620 if (!click(MOUSE_LEFT))
lharoon 0:22612ae617a0 621 return false;
lharoon 0:22612ae617a0 622 wait(0.1);
lharoon 0:22612ae617a0 623 return click(MOUSE_LEFT);
lharoon 0:22612ae617a0 624 }
lharoon 0:22612ae617a0 625
lharoon 0:22612ae617a0 626 bool USBMouseKeyboard::click(uint8_t button) {
lharoon 0:22612ae617a0 627 if (!update(0, 0, button, 0))
lharoon 0:22612ae617a0 628 return false;
lharoon 0:22612ae617a0 629 wait(0.01);
lharoon 0:22612ae617a0 630 return update(0, 0, 0, 0);
lharoon 0:22612ae617a0 631 }
lharoon 0:22612ae617a0 632
lharoon 0:22612ae617a0 633 bool USBMouseKeyboard::press(uint8_t button_) {
lharoon 0:22612ae617a0 634 button = button_ & 0x07;
lharoon 0:22612ae617a0 635 return update(0, 0, button, 0);
lharoon 0:22612ae617a0 636 }
lharoon 0:22612ae617a0 637
lharoon 0:22612ae617a0 638 bool USBMouseKeyboard::release(uint8_t button_) {
lharoon 0:22612ae617a0 639 button = (button & (~button_)) & 0x07;
lharoon 0:22612ae617a0 640 return update(0, 0, button, 0);
lharoon 0:22612ae617a0 641 }
lharoon 0:22612ae617a0 642
lharoon 0:22612ae617a0 643 int USBMouseKeyboard::_putc(int c) {
lharoon 0:22612ae617a0 644 return keyCode(c, keymap[c].modifier);
lharoon 0:22612ae617a0 645 }
lharoon 0:22612ae617a0 646
lharoon 0:22612ae617a0 647 bool USBMouseKeyboard::keyCode(uint8_t key, uint8_t modifier) {
lharoon 0:22612ae617a0 648 // Send a simulated keyboard keypress. Returns true if successful.
lharoon 0:22612ae617a0 649
lharoon 0:22612ae617a0 650 HID_REPORT report;
lharoon 0:22612ae617a0 651
lharoon 0:22612ae617a0 652 report.data[0] = REPORT_ID_KEYBOARD;
lharoon 0:22612ae617a0 653 report.data[1] = modifier;
lharoon 0:22612ae617a0 654 report.data[2] = 0;
lharoon 0:22612ae617a0 655 report.data[3] = keymap[key].usage;
lharoon 0:22612ae617a0 656 report.data[4] = 0;
lharoon 0:22612ae617a0 657 report.data[5] = 0;
lharoon 0:22612ae617a0 658 report.data[6] = 0;
lharoon 0:22612ae617a0 659 report.data[7] = 0;
lharoon 0:22612ae617a0 660 report.data[8] = 0;
lharoon 0:22612ae617a0 661
lharoon 0:22612ae617a0 662 report.length = 9;
lharoon 0:22612ae617a0 663
lharoon 0:22612ae617a0 664 if (!send(&report)) {
lharoon 0:22612ae617a0 665 return false;
lharoon 0:22612ae617a0 666 }
lharoon 0:22612ae617a0 667
lharoon 0:22612ae617a0 668 report.data[1] = 0;
lharoon 0:22612ae617a0 669 report.data[3] = 0;
lharoon 0:22612ae617a0 670
lharoon 0:22612ae617a0 671 if (!send(&report)) {
lharoon 0:22612ae617a0 672 return false;
lharoon 0:22612ae617a0 673 }
lharoon 0:22612ae617a0 674
lharoon 0:22612ae617a0 675 return true;
lharoon 0:22612ae617a0 676
lharoon 0:22612ae617a0 677 }
lharoon 0:22612ae617a0 678
lharoon 0:22612ae617a0 679
lharoon 0:22612ae617a0 680 bool USBMouseKeyboard::mediaControl(MEDIA_KEY key) {
lharoon 0:22612ae617a0 681 HID_REPORT report;
lharoon 0:22612ae617a0 682
lharoon 0:22612ae617a0 683 report.data[0] = REPORT_ID_VOLUME;
lharoon 0:22612ae617a0 684 report.data[1] = (1 << key) & 0x7f;
lharoon 0:22612ae617a0 685
lharoon 0:22612ae617a0 686 report.length = 2;
lharoon 0:22612ae617a0 687
lharoon 0:22612ae617a0 688 send(&report);
lharoon 0:22612ae617a0 689
lharoon 0:22612ae617a0 690 report.data[0] = REPORT_ID_VOLUME;
lharoon 0:22612ae617a0 691 report.data[1] = 0;
lharoon 0:22612ae617a0 692
lharoon 0:22612ae617a0 693 report.length = 2;
lharoon 0:22612ae617a0 694
lharoon 0:22612ae617a0 695 return send(&report);
lharoon 0:22612ae617a0 696 }