device USB Samir

Dependents:   USBJoystick_HelloWorld3

Fork of USBDevice by Samuel Mokrani

Committer:
samux
Date:
Wed May 30 18:28:11 2012 +0000
Revision:
0:140cdf8e2d60

        

Who changed what in which revision?

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