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