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