USB Serial application

Fork of USBSerial_HelloWorld by Samuel Mokrani

Committer:
Zaitsev
Date:
Tue Jan 10 20:42:26 2017 +0000
Revision:
10:41552d038a69
USB Serial bi-directional bridge

Who changed what in which revision?

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