max4146x_comp

Dependencies:   MAX14690

Committer:
sdivarci
Date:
Sun Oct 25 20:10:02 2020 +0000
Revision:
0:0061165683ee
sdivarci

Who changed what in which revision?

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