mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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