Added general purpus HID report
Fork of USBDevice by
Embed:
(wiki syntax)
Show/hide line numbers
USBMouseKeyboard.h
00001 /* Copyright (c) 2010-2011 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #ifndef USBMOUSEKEYBOARD_H 00020 #define USBMOUSEKEYBOARD_H 00021 00022 #define REPORT_ID_KEYBOARD 1 00023 #define REPORT_ID_MOUSE 2 00024 #define REPORT_ID_VOLUME 3 00025 00026 #define REPORT_ID_UTILITY (4) 00027 #define REPORT_PAYLOAD_SIZE (63) 00028 00029 #include "USBMouse.h" 00030 #include "USBKeyboard.h" 00031 #include "Stream.h" 00032 #include "USBHID.h" 00033 00034 /** 00035 * USBMouseKeyboard example 00036 * @code 00037 * 00038 * #include "mbed.h" 00039 * #include "USBMouseKeyboard.h" 00040 * 00041 * USBMouseKeyboard key_mouse; 00042 * 00043 * int main(void) 00044 * { 00045 * while(1) 00046 * { 00047 * key_mouse.move(20, 0); 00048 * key_mouse.printf("Hello From MBED\r\n"); 00049 * wait(1); 00050 * } 00051 * } 00052 * @endcode 00053 * 00054 * 00055 * @code 00056 * 00057 * #include "mbed.h" 00058 * #include "USBMouseKeyboard.h" 00059 * 00060 * USBMouseKeyboard key_mouse(ABS_MOUSE); 00061 * 00062 * int main(void) 00063 * { 00064 * while(1) 00065 * { 00066 * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2); 00067 * key_mouse.printf("Hello from MBED\r\n"); 00068 * wait(1); 00069 * } 00070 * } 00071 * @endcode 00072 */ 00073 00074 00075 00076 class USBMouseKeyboard: public USBHID, public Stream 00077 { 00078 public: 00079 00080 /** 00081 * Constructor 00082 * 00083 * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE) 00084 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK 00085 * @param vendor_id Your vendor_id (default: 0x1234) 00086 * @param product_id Your product_id (default: 0x0001) 00087 * @param product_release Your preoduct_release (default: 0x0001) 00088 * 00089 */ 00090 USBMouseKeyboard(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x0021, uint16_t product_id = 0x0011, uint16_t product_release = 0x0001): 00091 USBHID(0, 0, vendor_id, product_id, product_release, false) 00092 { 00093 lock_status = 0; 00094 button = 0; 00095 this->mouse_type = mouse_type; 00096 connect(); 00097 }; 00098 00099 /** 00100 * Write a state of the mouse 00101 * 00102 * @param x x-axis position 00103 * @param y y-axis position 00104 * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE) 00105 * @param z wheel state (>0 to scroll down, <0 to scroll up) 00106 * @returns true if there is no error, false otherwise 00107 */ 00108 bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z); 00109 00110 00111 /** 00112 * Move the cursor to (x, y) 00113 * 00114 * @param x x-axis position 00115 * @param y y-axis position 00116 * @returns true if there is no error, false otherwise 00117 */ 00118 bool move(int16_t x, int16_t y); 00119 00120 /** 00121 * Press one or several buttons 00122 * 00123 * @param button button state (ex: press(MOUSE_LEFT)) 00124 * @returns true if there is no error, false otherwise 00125 */ 00126 bool press(uint8_t button); 00127 00128 /** 00129 * Release one or several buttons 00130 * 00131 * @param button button state (ex: release(MOUSE_LEFT)) 00132 * @returns true if there is no error, false otherwise 00133 */ 00134 bool release(uint8_t button); 00135 00136 /** 00137 * Double click (MOUSE_LEFT) 00138 * 00139 * @returns true if there is no error, false otherwise 00140 */ 00141 bool doubleClick(); 00142 00143 /** 00144 * Click 00145 * 00146 * @param button state of the buttons ( ex: clic(MOUSE_LEFT)) 00147 * @returns true if there is no error, false otherwise 00148 */ 00149 bool click(uint8_t button); 00150 00151 /** 00152 * Scrolling 00153 * 00154 * @param z value of the wheel (>0 to go down, <0 to go up) 00155 * @returns true if there is no error, false otherwise 00156 */ 00157 bool scroll(int8_t z); 00158 00159 /** 00160 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key 00161 * 00162 * @code 00163 * //To send CTRL + s (save) 00164 * keyboard.keyCode('s', KEY_CTRL); 00165 * @endcode 00166 * 00167 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0) 00168 * @param key character to send 00169 * @returns true if there is no error, false otherwise 00170 */ 00171 bool keyCode(uint8_t key, uint8_t modifier = 0); 00172 00173 /** 00174 * Send a character 00175 * 00176 * @param c character to be sent 00177 * @returns true if there is no error, false otherwise 00178 */ 00179 virtual int _putc(int c); 00180 00181 /** 00182 * Control media keys 00183 * 00184 * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN) 00185 * @returns true if there is no error, false otherwise 00186 */ 00187 bool mediaControl(MEDIA_KEY key); 00188 00189 /** 00190 * 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: 00191 * - First bit: NUM_LOCK 00192 * - Second bit: CAPS_LOCK 00193 * - Third bit: SCROLL_LOCK 00194 * 00195 * @returns status of lock keys 00196 */ 00197 uint8_t lockStatus(); 00198 00199 /* 00200 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. 00201 * 00202 * @returns pointer to the report descriptor 00203 */ 00204 virtual uint8_t * reportDesc(); 00205 00206 /* 00207 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys 00208 * 00209 * @returns if handle by subclass, return true 00210 */ 00211 virtual bool EP1_OUT_callback(); 00212 00213 00214 virtual void genericHidCallback(uint32_t length, uint8_t *buff); 00215 00216 private: 00217 bool mouseWrite(int8_t x, int8_t y, uint8_t buttons, int8_t z); 00218 MOUSE_TYPE mouse_type; 00219 uint8_t button; 00220 bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z); 00221 00222 uint8_t lock_status; 00223 00224 //dummy otherwise it doesn't compile (we must define all methods of an abstract class) 00225 virtual int _getc() { return -1;} 00226 }; 00227 00228 #endif
Generated on Thu Jul 14 2022 17:07:52 by 1.7.2