USBMSD test for GR-PEACH
Dependencies: USBDevice USBMSD_SD mbed
Fork of USBMSD_SD_HelloWorld_Mbed by
USBDevice/USBHID/USBMouseKeyboard.h@11:a26e7b7a1221, 2011-11-16 (annotated)
- Committer:
- samux
- Date:
- Wed Nov 16 17:17:42 2011 +0000
- Revision:
- 11:a26e7b7a1221
GOOD COMMIT: msd and hid work even on MAC...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux |
11:a26e7b7a1221 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
samux |
11:a26e7b7a1221 | 2 | * |
samux |
11:a26e7b7a1221 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
samux |
11:a26e7b7a1221 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
samux |
11:a26e7b7a1221 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
samux |
11:a26e7b7a1221 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
samux |
11:a26e7b7a1221 | 7 | * Software is furnished to do so, subject to the following conditions: |
samux |
11:a26e7b7a1221 | 8 | * |
samux |
11:a26e7b7a1221 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
samux |
11:a26e7b7a1221 | 10 | * substantial portions of the Software. |
samux |
11:a26e7b7a1221 | 11 | * |
samux |
11:a26e7b7a1221 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
samux |
11:a26e7b7a1221 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
samux |
11:a26e7b7a1221 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
samux |
11:a26e7b7a1221 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
samux |
11:a26e7b7a1221 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
samux |
11:a26e7b7a1221 | 17 | */ |
samux |
11:a26e7b7a1221 | 18 | |
samux |
11:a26e7b7a1221 | 19 | #ifndef USBMOUSEKEYBOARD_H |
samux |
11:a26e7b7a1221 | 20 | #define USBMOUSEKEYBOARD_H |
samux |
11:a26e7b7a1221 | 21 | |
samux |
11:a26e7b7a1221 | 22 | #define REPORT_ID_KEYBOARD 1 |
samux |
11:a26e7b7a1221 | 23 | #define REPORT_ID_MOUSE 2 |
samux |
11:a26e7b7a1221 | 24 | #define REPORT_ID_VOLUME 3 |
samux |
11:a26e7b7a1221 | 25 | |
samux |
11:a26e7b7a1221 | 26 | #include "USBMouse.h" |
samux |
11:a26e7b7a1221 | 27 | #include "USBKeyboard.h" |
samux |
11:a26e7b7a1221 | 28 | #include "Stream.h" |
samux |
11:a26e7b7a1221 | 29 | #include "USBHID.h" |
samux |
11:a26e7b7a1221 | 30 | |
samux |
11:a26e7b7a1221 | 31 | /** |
samux |
11:a26e7b7a1221 | 32 | * USBMouseKeyboard example |
samux |
11:a26e7b7a1221 | 33 | * @code |
samux |
11:a26e7b7a1221 | 34 | * |
samux |
11:a26e7b7a1221 | 35 | * #include "mbed.h" |
samux |
11:a26e7b7a1221 | 36 | * #include "USBMouseKeyboard.h" |
samux |
11:a26e7b7a1221 | 37 | * |
samux |
11:a26e7b7a1221 | 38 | * USBMouseKeyboard key_mouse; |
samux |
11:a26e7b7a1221 | 39 | * |
samux |
11:a26e7b7a1221 | 40 | * int main(void) |
samux |
11:a26e7b7a1221 | 41 | * { |
samux |
11:a26e7b7a1221 | 42 | * while(1) |
samux |
11:a26e7b7a1221 | 43 | * { |
samux |
11:a26e7b7a1221 | 44 | * key_mouse.move(20, 0); |
samux |
11:a26e7b7a1221 | 45 | * key_mouse.printf("Hello From MBED\r\n"); |
samux |
11:a26e7b7a1221 | 46 | * wait(1); |
samux |
11:a26e7b7a1221 | 47 | * } |
samux |
11:a26e7b7a1221 | 48 | * } |
samux |
11:a26e7b7a1221 | 49 | * @endcode |
samux |
11:a26e7b7a1221 | 50 | * |
samux |
11:a26e7b7a1221 | 51 | * |
samux |
11:a26e7b7a1221 | 52 | * @code |
samux |
11:a26e7b7a1221 | 53 | * |
samux |
11:a26e7b7a1221 | 54 | * #include "mbed.h" |
samux |
11:a26e7b7a1221 | 55 | * #include "USBMouseKeyboard.h" |
samux |
11:a26e7b7a1221 | 56 | * |
samux |
11:a26e7b7a1221 | 57 | * USBMouseKeyboard key_mouse(ABS_MOUSE); |
samux |
11:a26e7b7a1221 | 58 | * |
samux |
11:a26e7b7a1221 | 59 | * int main(void) |
samux |
11:a26e7b7a1221 | 60 | * { |
samux |
11:a26e7b7a1221 | 61 | * while(1) |
samux |
11:a26e7b7a1221 | 62 | * { |
samux |
11:a26e7b7a1221 | 63 | * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2); |
samux |
11:a26e7b7a1221 | 64 | * key_mouse.printf("Hello from MBED\r\n"); |
samux |
11:a26e7b7a1221 | 65 | * wait(1); |
samux |
11:a26e7b7a1221 | 66 | * } |
samux |
11:a26e7b7a1221 | 67 | * } |
samux |
11:a26e7b7a1221 | 68 | * @endcode |
samux |
11:a26e7b7a1221 | 69 | */ |
samux |
11:a26e7b7a1221 | 70 | class USBMouseKeyboard: public USBHID, public Stream |
samux |
11:a26e7b7a1221 | 71 | { |
samux |
11:a26e7b7a1221 | 72 | public: |
samux |
11:a26e7b7a1221 | 73 | |
samux |
11:a26e7b7a1221 | 74 | /** |
samux |
11:a26e7b7a1221 | 75 | * Constructor |
samux |
11:a26e7b7a1221 | 76 | * |
samux |
11:a26e7b7a1221 | 77 | * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE) |
samux |
11:a26e7b7a1221 | 78 | * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK |
samux |
11:a26e7b7a1221 | 79 | * @param vendor_id Your vendor_id (default: 0x1234) |
samux |
11:a26e7b7a1221 | 80 | * @param product_id Your product_id (default: 0x0001) |
samux |
11:a26e7b7a1221 | 81 | * @param product_release Your preoduct_release (default: 0x0001) |
samux |
11:a26e7b7a1221 | 82 | * |
samux |
11:a26e7b7a1221 | 83 | */ |
samux |
11:a26e7b7a1221 | 84 | USBMouseKeyboard(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x0021, uint16_t product_id = 0x0011, uint16_t product_release = 0x0001): |
samux |
11:a26e7b7a1221 | 85 | USBHID(0, 0, vendor_id, product_id, product_release) |
samux |
11:a26e7b7a1221 | 86 | { |
samux |
11:a26e7b7a1221 | 87 | lock_status = 0; |
samux |
11:a26e7b7a1221 | 88 | button = 0; |
samux |
11:a26e7b7a1221 | 89 | this->mouse_type = mouse_type; |
samux |
11:a26e7b7a1221 | 90 | }; |
samux |
11:a26e7b7a1221 | 91 | |
samux |
11:a26e7b7a1221 | 92 | /** |
samux |
11:a26e7b7a1221 | 93 | * Write a state of the mouse |
samux |
11:a26e7b7a1221 | 94 | * |
samux |
11:a26e7b7a1221 | 95 | * @param x x-axis position |
samux |
11:a26e7b7a1221 | 96 | * @param y y-axis position |
samux |
11:a26e7b7a1221 | 97 | * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE) |
samux |
11:a26e7b7a1221 | 98 | * @param z wheel state (>0 to scroll down, <0 to scroll up) |
samux |
11:a26e7b7a1221 | 99 | * @returns true if there is no error, false otherwise |
samux |
11:a26e7b7a1221 | 100 | */ |
samux |
11:a26e7b7a1221 | 101 | bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z); |
samux |
11:a26e7b7a1221 | 102 | |
samux |
11:a26e7b7a1221 | 103 | |
samux |
11:a26e7b7a1221 | 104 | /** |
samux |
11:a26e7b7a1221 | 105 | * Move the cursor to (x, y) |
samux |
11:a26e7b7a1221 | 106 | * |
samux |
11:a26e7b7a1221 | 107 | * @param x x-axis position |
samux |
11:a26e7b7a1221 | 108 | * @param y y-axis position |
samux |
11:a26e7b7a1221 | 109 | * @returns true if there is no error, false otherwise |
samux |
11:a26e7b7a1221 | 110 | */ |
samux |
11:a26e7b7a1221 | 111 | bool move(int16_t x, int16_t y); |
samux |
11:a26e7b7a1221 | 112 | |
samux |
11:a26e7b7a1221 | 113 | /** |
samux |
11:a26e7b7a1221 | 114 | * Press one or several buttons |
samux |
11:a26e7b7a1221 | 115 | * |
samux |
11:a26e7b7a1221 | 116 | * @param button button state (ex: press(MOUSE_LEFT)) |
samux |
11:a26e7b7a1221 | 117 | * @returns true if there is no error, false otherwise |
samux |
11:a26e7b7a1221 | 118 | */ |
samux |
11:a26e7b7a1221 | 119 | bool press(uint8_t button); |
samux |
11:a26e7b7a1221 | 120 | |
samux |
11:a26e7b7a1221 | 121 | /** |
samux |
11:a26e7b7a1221 | 122 | * Release one or several buttons |
samux |
11:a26e7b7a1221 | 123 | * |
samux |
11:a26e7b7a1221 | 124 | * @param button button state (ex: release(MOUSE_LEFT)) |
samux |
11:a26e7b7a1221 | 125 | * @returns true if there is no error, false otherwise |
samux |
11:a26e7b7a1221 | 126 | */ |
samux |
11:a26e7b7a1221 | 127 | bool release(uint8_t button); |
samux |
11:a26e7b7a1221 | 128 | |
samux |
11:a26e7b7a1221 | 129 | /** |
samux |
11:a26e7b7a1221 | 130 | * Double click (MOUSE_LEFT) |
samux |
11:a26e7b7a1221 | 131 | * |
samux |
11:a26e7b7a1221 | 132 | * @returns true if there is no error, false otherwise |
samux |
11:a26e7b7a1221 | 133 | */ |
samux |
11:a26e7b7a1221 | 134 | bool doubleClick(); |
samux |
11:a26e7b7a1221 | 135 | |
samux |
11:a26e7b7a1221 | 136 | /** |
samux |
11:a26e7b7a1221 | 137 | * Click |
samux |
11:a26e7b7a1221 | 138 | * |
samux |
11:a26e7b7a1221 | 139 | * @param button state of the buttons ( ex: clic(MOUSE_LEFT)) |
samux |
11:a26e7b7a1221 | 140 | * @returns true if there is no error, false otherwise |
samux |
11:a26e7b7a1221 | 141 | */ |
samux |
11:a26e7b7a1221 | 142 | bool click(uint8_t button); |
samux |
11:a26e7b7a1221 | 143 | |
samux |
11:a26e7b7a1221 | 144 | /** |
samux |
11:a26e7b7a1221 | 145 | * Scrolling |
samux |
11:a26e7b7a1221 | 146 | * |
samux |
11:a26e7b7a1221 | 147 | * @param z value of the wheel (>0 to go down, <0 to go up) |
samux |
11:a26e7b7a1221 | 148 | * @returns true if there is no error, false otherwise |
samux |
11:a26e7b7a1221 | 149 | */ |
samux |
11:a26e7b7a1221 | 150 | bool scroll(int8_t z); |
samux |
11:a26e7b7a1221 | 151 | |
samux |
11:a26e7b7a1221 | 152 | /** |
samux |
11:a26e7b7a1221 | 153 | * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key |
samux |
11:a26e7b7a1221 | 154 | * |
samux |
11:a26e7b7a1221 | 155 | * @code |
samux |
11:a26e7b7a1221 | 156 | * //To send CTRL + s (save) |
samux |
11:a26e7b7a1221 | 157 | * keyboard.keyCode('s', KEY_CTRL); |
samux |
11:a26e7b7a1221 | 158 | * @endcode |
samux |
11:a26e7b7a1221 | 159 | * |
samux |
11:a26e7b7a1221 | 160 | * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0) |
samux |
11:a26e7b7a1221 | 161 | * @param key character to send |
samux |
11:a26e7b7a1221 | 162 | * @returns true if there is no error, false otherwise |
samux |
11:a26e7b7a1221 | 163 | */ |
samux |
11:a26e7b7a1221 | 164 | bool keyCode(uint8_t key, uint8_t modifier = 0); |
samux |
11:a26e7b7a1221 | 165 | |
samux |
11:a26e7b7a1221 | 166 | /** |
samux |
11:a26e7b7a1221 | 167 | * Send a character |
samux |
11:a26e7b7a1221 | 168 | * |
samux |
11:a26e7b7a1221 | 169 | * @param c character to be sent |
samux |
11:a26e7b7a1221 | 170 | * @returns true if there is no error, false otherwise |
samux |
11:a26e7b7a1221 | 171 | */ |
samux |
11:a26e7b7a1221 | 172 | virtual int _putc(int c); |
samux |
11:a26e7b7a1221 | 173 | |
samux |
11:a26e7b7a1221 | 174 | /** |
samux |
11:a26e7b7a1221 | 175 | * Control media keys |
samux |
11:a26e7b7a1221 | 176 | * |
samux |
11:a26e7b7a1221 | 177 | * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN) |
samux |
11:a26e7b7a1221 | 178 | * @returns true if there is no error, false otherwise |
samux |
11:a26e7b7a1221 | 179 | */ |
samux |
11:a26e7b7a1221 | 180 | bool mediaControl(MEDIA_KEY key); |
samux |
11:a26e7b7a1221 | 181 | |
samux |
11:a26e7b7a1221 | 182 | /** |
samux |
11:a26e7b7a1221 | 183 | * 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: |
samux |
11:a26e7b7a1221 | 184 | * - First bit: NUM_LOCK |
samux |
11:a26e7b7a1221 | 185 | * - Second bit: CAPS_LOCK |
samux |
11:a26e7b7a1221 | 186 | * - Third bit: SCROLL_LOCK |
samux |
11:a26e7b7a1221 | 187 | * |
samux |
11:a26e7b7a1221 | 188 | * @returns status of lock keys |
samux |
11:a26e7b7a1221 | 189 | */ |
samux |
11:a26e7b7a1221 | 190 | uint8_t lockStatus(); |
samux |
11:a26e7b7a1221 | 191 | |
samux |
11:a26e7b7a1221 | 192 | /* |
samux |
11:a26e7b7a1221 | 193 | * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
samux |
11:a26e7b7a1221 | 194 | * |
samux |
11:a26e7b7a1221 | 195 | * @returns pointer to the report descriptor |
samux |
11:a26e7b7a1221 | 196 | */ |
samux |
11:a26e7b7a1221 | 197 | virtual uint8_t * reportDesc(); |
samux |
11:a26e7b7a1221 | 198 | |
samux |
11:a26e7b7a1221 | 199 | /* |
samux |
11:a26e7b7a1221 | 200 | * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys |
samux |
11:a26e7b7a1221 | 201 | * |
samux |
11:a26e7b7a1221 | 202 | * @returns if handle by subclass, return true |
samux |
11:a26e7b7a1221 | 203 | */ |
samux |
11:a26e7b7a1221 | 204 | virtual bool EP1_OUT_callback(); |
samux |
11:a26e7b7a1221 | 205 | |
samux |
11:a26e7b7a1221 | 206 | |
samux |
11:a26e7b7a1221 | 207 | private: |
samux |
11:a26e7b7a1221 | 208 | bool mouseWrite(int8_t x, int8_t y, uint8_t buttons, int8_t z); |
samux |
11:a26e7b7a1221 | 209 | MOUSE_TYPE mouse_type; |
samux |
11:a26e7b7a1221 | 210 | uint8_t button; |
samux |
11:a26e7b7a1221 | 211 | bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z); |
samux |
11:a26e7b7a1221 | 212 | |
samux |
11:a26e7b7a1221 | 213 | uint8_t lock_status; |
samux |
11:a26e7b7a1221 | 214 | |
samux |
11:a26e7b7a1221 | 215 | //dummy otherwise it doesn't compile (we must define all methods of an abstract class) |
samux |
11:a26e7b7a1221 | 216 | virtual int _getc() { return -1;} |
samux |
11:a26e7b7a1221 | 217 | }; |
samux |
11:a26e7b7a1221 | 218 | |
samux |
11:a26e7b7a1221 | 219 | #endif |