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.h@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 | #ifndef USBMOUSEKEYBOARD_H |
mbed2f | 0:7610d342c76e | 20 | #define USBMOUSEKEYBOARD_H |
mbed2f | 0:7610d342c76e | 21 | |
mbed2f | 0:7610d342c76e | 22 | #define REPORT_ID_KEYBOARD 1 |
mbed2f | 0:7610d342c76e | 23 | #define REPORT_ID_MOUSE 2 |
mbed2f | 0:7610d342c76e | 24 | #define REPORT_ID_VOLUME 3 |
mbed2f | 0:7610d342c76e | 25 | |
mbed2f | 0:7610d342c76e | 26 | #include "USBMouse.h" |
mbed2f | 0:7610d342c76e | 27 | #include "USBKeyboard.h" |
mbed2f | 0:7610d342c76e | 28 | #include "Stream.h" |
mbed2f | 0:7610d342c76e | 29 | #include "USBHID.h" |
mbed2f | 0:7610d342c76e | 30 | |
mbed2f | 0:7610d342c76e | 31 | /** |
mbed2f | 0:7610d342c76e | 32 | * USBMouseKeyboard example |
mbed2f | 0:7610d342c76e | 33 | * @code |
mbed2f | 0:7610d342c76e | 34 | * |
mbed2f | 0:7610d342c76e | 35 | * #include "mbed.h" |
mbed2f | 0:7610d342c76e | 36 | * #include "USBMouseKeyboard.h" |
mbed2f | 0:7610d342c76e | 37 | * |
mbed2f | 0:7610d342c76e | 38 | * USBMouseKeyboard key_mouse; |
mbed2f | 0:7610d342c76e | 39 | * |
mbed2f | 0:7610d342c76e | 40 | * int main(void) |
mbed2f | 0:7610d342c76e | 41 | * { |
mbed2f | 0:7610d342c76e | 42 | * while(1) |
mbed2f | 0:7610d342c76e | 43 | * { |
mbed2f | 0:7610d342c76e | 44 | * key_mouse.move(20, 0); |
mbed2f | 0:7610d342c76e | 45 | * key_mouse.printf("Hello From MBED\r\n"); |
mbed2f | 0:7610d342c76e | 46 | * wait(1); |
mbed2f | 0:7610d342c76e | 47 | * } |
mbed2f | 0:7610d342c76e | 48 | * } |
mbed2f | 0:7610d342c76e | 49 | * @endcode |
mbed2f | 0:7610d342c76e | 50 | * |
mbed2f | 0:7610d342c76e | 51 | * |
mbed2f | 0:7610d342c76e | 52 | * @code |
mbed2f | 0:7610d342c76e | 53 | * |
mbed2f | 0:7610d342c76e | 54 | * #include "mbed.h" |
mbed2f | 0:7610d342c76e | 55 | * #include "USBMouseKeyboard.h" |
mbed2f | 0:7610d342c76e | 56 | * |
mbed2f | 0:7610d342c76e | 57 | * USBMouseKeyboard key_mouse(ABS_MOUSE); |
mbed2f | 0:7610d342c76e | 58 | * |
mbed2f | 0:7610d342c76e | 59 | * int main(void) |
mbed2f | 0:7610d342c76e | 60 | * { |
mbed2f | 0:7610d342c76e | 61 | * while(1) |
mbed2f | 0:7610d342c76e | 62 | * { |
mbed2f | 0:7610d342c76e | 63 | * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2); |
mbed2f | 0:7610d342c76e | 64 | * key_mouse.printf("Hello from MBED\r\n"); |
mbed2f | 0:7610d342c76e | 65 | * wait(1); |
mbed2f | 0:7610d342c76e | 66 | * } |
mbed2f | 0:7610d342c76e | 67 | * } |
mbed2f | 0:7610d342c76e | 68 | * @endcode |
mbed2f | 0:7610d342c76e | 69 | */ |
mbed2f | 0:7610d342c76e | 70 | class USBMouseKeyboard: public USBHID, public Stream |
mbed2f | 0:7610d342c76e | 71 | { |
mbed2f | 0:7610d342c76e | 72 | public: |
mbed2f | 0:7610d342c76e | 73 | |
mbed2f | 0:7610d342c76e | 74 | /** |
mbed2f | 0:7610d342c76e | 75 | * Constructor |
mbed2f | 0:7610d342c76e | 76 | * |
mbed2f | 0:7610d342c76e | 77 | * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE) |
mbed2f | 0:7610d342c76e | 78 | * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK |
mbed2f | 0:7610d342c76e | 79 | * @param vendor_id Your vendor_id (default: 0x1234) |
mbed2f | 0:7610d342c76e | 80 | * @param product_id Your product_id (default: 0x0001) |
mbed2f | 0:7610d342c76e | 81 | * @param product_release Your preoduct_release (default: 0x0001) |
mbed2f | 0:7610d342c76e | 82 | * |
mbed2f | 0:7610d342c76e | 83 | */ |
mbed2f | 0:7610d342c76e | 84 | USBMouseKeyboard(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x0021, uint16_t product_id = 0x0011, uint16_t product_release = 0x0001): |
mbed2f | 0:7610d342c76e | 85 | USBHID(0, 0, vendor_id, product_id, product_release, false) |
mbed2f | 0:7610d342c76e | 86 | { |
mbed2f | 0:7610d342c76e | 87 | lock_status = 0; |
mbed2f | 0:7610d342c76e | 88 | button = 0; |
mbed2f | 0:7610d342c76e | 89 | this->mouse_type = mouse_type; |
mbed2f | 0:7610d342c76e | 90 | connect(); |
mbed2f | 0:7610d342c76e | 91 | }; |
mbed2f | 0:7610d342c76e | 92 | |
mbed2f | 0:7610d342c76e | 93 | /** |
mbed2f | 0:7610d342c76e | 94 | * Write a state of the mouse |
mbed2f | 0:7610d342c76e | 95 | * |
mbed2f | 0:7610d342c76e | 96 | * @param x x-axis position |
mbed2f | 0:7610d342c76e | 97 | * @param y y-axis position |
mbed2f | 0:7610d342c76e | 98 | * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE) |
mbed2f | 0:7610d342c76e | 99 | * @param z wheel state (>0 to scroll down, <0 to scroll up) |
mbed2f | 0:7610d342c76e | 100 | * @returns true if there is no error, false otherwise |
mbed2f | 0:7610d342c76e | 101 | */ |
mbed2f | 0:7610d342c76e | 102 | bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z); |
mbed2f | 0:7610d342c76e | 103 | |
mbed2f | 0:7610d342c76e | 104 | |
mbed2f | 0:7610d342c76e | 105 | /** |
mbed2f | 0:7610d342c76e | 106 | * Move the cursor to (x, y) |
mbed2f | 0:7610d342c76e | 107 | * |
mbed2f | 0:7610d342c76e | 108 | * @param x x-axis position |
mbed2f | 0:7610d342c76e | 109 | * @param y y-axis position |
mbed2f | 0:7610d342c76e | 110 | * @returns true if there is no error, false otherwise |
mbed2f | 0:7610d342c76e | 111 | */ |
mbed2f | 0:7610d342c76e | 112 | bool move(int16_t x, int16_t y); |
mbed2f | 0:7610d342c76e | 113 | |
mbed2f | 0:7610d342c76e | 114 | /** |
mbed2f | 0:7610d342c76e | 115 | * Press one or several buttons |
mbed2f | 0:7610d342c76e | 116 | * |
mbed2f | 0:7610d342c76e | 117 | * @param button button state (ex: press(MOUSE_LEFT)) |
mbed2f | 0:7610d342c76e | 118 | * @returns true if there is no error, false otherwise |
mbed2f | 0:7610d342c76e | 119 | */ |
mbed2f | 0:7610d342c76e | 120 | bool press(uint8_t button); |
mbed2f | 0:7610d342c76e | 121 | |
mbed2f | 0:7610d342c76e | 122 | /** |
mbed2f | 0:7610d342c76e | 123 | * Release one or several buttons |
mbed2f | 0:7610d342c76e | 124 | * |
mbed2f | 0:7610d342c76e | 125 | * @param button button state (ex: release(MOUSE_LEFT)) |
mbed2f | 0:7610d342c76e | 126 | * @returns true if there is no error, false otherwise |
mbed2f | 0:7610d342c76e | 127 | */ |
mbed2f | 0:7610d342c76e | 128 | bool release(uint8_t button); |
mbed2f | 0:7610d342c76e | 129 | |
mbed2f | 0:7610d342c76e | 130 | /** |
mbed2f | 0:7610d342c76e | 131 | * Double click (MOUSE_LEFT) |
mbed2f | 0:7610d342c76e | 132 | * |
mbed2f | 0:7610d342c76e | 133 | * @returns true if there is no error, false otherwise |
mbed2f | 0:7610d342c76e | 134 | */ |
mbed2f | 0:7610d342c76e | 135 | bool doubleClick(); |
mbed2f | 0:7610d342c76e | 136 | |
mbed2f | 0:7610d342c76e | 137 | /** |
mbed2f | 0:7610d342c76e | 138 | * Click |
mbed2f | 0:7610d342c76e | 139 | * |
mbed2f | 0:7610d342c76e | 140 | * @param button state of the buttons ( ex: clic(MOUSE_LEFT)) |
mbed2f | 0:7610d342c76e | 141 | * @returns true if there is no error, false otherwise |
mbed2f | 0:7610d342c76e | 142 | */ |
mbed2f | 0:7610d342c76e | 143 | bool click(uint8_t button); |
mbed2f | 0:7610d342c76e | 144 | |
mbed2f | 0:7610d342c76e | 145 | /** |
mbed2f | 0:7610d342c76e | 146 | * Scrolling |
mbed2f | 0:7610d342c76e | 147 | * |
mbed2f | 0:7610d342c76e | 148 | * @param z value of the wheel (>0 to go down, <0 to go up) |
mbed2f | 0:7610d342c76e | 149 | * @returns true if there is no error, false otherwise |
mbed2f | 0:7610d342c76e | 150 | */ |
mbed2f | 0:7610d342c76e | 151 | bool scroll(int8_t z); |
mbed2f | 0:7610d342c76e | 152 | |
mbed2f | 0:7610d342c76e | 153 | /** |
mbed2f | 0:7610d342c76e | 154 | * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key |
mbed2f | 0:7610d342c76e | 155 | * |
mbed2f | 0:7610d342c76e | 156 | * @code |
mbed2f | 0:7610d342c76e | 157 | * //To send CTRL + s (save) |
mbed2f | 0:7610d342c76e | 158 | * keyboard.keyCode('s', KEY_CTRL); |
mbed2f | 0:7610d342c76e | 159 | * @endcode |
mbed2f | 0:7610d342c76e | 160 | * |
mbed2f | 0:7610d342c76e | 161 | * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0) |
mbed2f | 0:7610d342c76e | 162 | * @param key character to send |
mbed2f | 0:7610d342c76e | 163 | * @returns true if there is no error, false otherwise |
mbed2f | 0:7610d342c76e | 164 | */ |
mbed2f | 0:7610d342c76e | 165 | bool keyCode(uint8_t key, uint8_t modifier = 0); |
mbed2f | 0:7610d342c76e | 166 | |
mbed2f | 0:7610d342c76e | 167 | /** |
mbed2f | 0:7610d342c76e | 168 | * Send a character |
mbed2f | 0:7610d342c76e | 169 | * |
mbed2f | 0:7610d342c76e | 170 | * @param c character to be sent |
mbed2f | 0:7610d342c76e | 171 | * @returns true if there is no error, false otherwise |
mbed2f | 0:7610d342c76e | 172 | */ |
mbed2f | 0:7610d342c76e | 173 | virtual int _putc(int c); |
mbed2f | 0:7610d342c76e | 174 | |
mbed2f | 0:7610d342c76e | 175 | /** |
mbed2f | 0:7610d342c76e | 176 | * Control media keys |
mbed2f | 0:7610d342c76e | 177 | * |
mbed2f | 0:7610d342c76e | 178 | * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN) |
mbed2f | 0:7610d342c76e | 179 | * @returns true if there is no error, false otherwise |
mbed2f | 0:7610d342c76e | 180 | */ |
mbed2f | 0:7610d342c76e | 181 | bool mediaControl(MEDIA_KEY key); |
mbed2f | 0:7610d342c76e | 182 | |
mbed2f | 0:7610d342c76e | 183 | /** |
mbed2f | 0:7610d342c76e | 184 | * Read status of lock keys. Useful to switch-on/off leds according to key pressed. Only the first three bits of the result is important: |
mbed2f | 0:7610d342c76e | 185 | * - First bit: NUM_LOCK |
mbed2f | 0:7610d342c76e | 186 | * - Second bit: CAPS_LOCK |
mbed2f | 0:7610d342c76e | 187 | * - Third bit: SCROLL_LOCK |
mbed2f | 0:7610d342c76e | 188 | * |
mbed2f | 0:7610d342c76e | 189 | * @returns status of lock keys |
mbed2f | 0:7610d342c76e | 190 | */ |
mbed2f | 0:7610d342c76e | 191 | uint8_t lockStatus(); |
mbed2f | 0:7610d342c76e | 192 | |
mbed2f | 0:7610d342c76e | 193 | /* |
mbed2f | 0:7610d342c76e | 194 | * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
mbed2f | 0:7610d342c76e | 195 | * |
mbed2f | 0:7610d342c76e | 196 | * @returns pointer to the report descriptor |
mbed2f | 0:7610d342c76e | 197 | */ |
mbed2f | 0:7610d342c76e | 198 | virtual uint8_t * reportDesc(); |
mbed2f | 0:7610d342c76e | 199 | |
mbed2f | 0:7610d342c76e | 200 | /* |
mbed2f | 0:7610d342c76e | 201 | * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys |
mbed2f | 0:7610d342c76e | 202 | * |
mbed2f | 0:7610d342c76e | 203 | * @returns if handle by subclass, return true |
mbed2f | 0:7610d342c76e | 204 | */ |
mbed2f | 0:7610d342c76e | 205 | virtual bool EP1_OUT_callback(); |
mbed2f | 0:7610d342c76e | 206 | |
mbed2f | 0:7610d342c76e | 207 | |
mbed2f | 0:7610d342c76e | 208 | private: |
mbed2f | 0:7610d342c76e | 209 | bool mouseWrite(int8_t x, int8_t y, uint8_t buttons, int8_t z); |
mbed2f | 0:7610d342c76e | 210 | MOUSE_TYPE mouse_type; |
mbed2f | 0:7610d342c76e | 211 | uint8_t button; |
mbed2f | 0:7610d342c76e | 212 | bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z); |
mbed2f | 0:7610d342c76e | 213 | |
mbed2f | 0:7610d342c76e | 214 | uint8_t lock_status; |
mbed2f | 0:7610d342c76e | 215 | |
mbed2f | 0:7610d342c76e | 216 | //dummy otherwise it doesn't compile (we must define all methods of an abstract class) |
mbed2f | 0:7610d342c76e | 217 | virtual int _getc() { return -1;} |
mbed2f | 0:7610d342c76e | 218 | }; |
mbed2f | 0:7610d342c76e | 219 | |
mbed2f | 0:7610d342c76e | 220 | #endif |