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