]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/USBDevice/USBHID/USBKeyboard.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / USBDevice / USBHID / USBKeyboard.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 USBKEYBOARD_H
20 #define USBKEYBOARD_H
21
22 #include "USBHID.h"
23 #include "Stream.h"
24
25 /* Modifiers */
26 enum MODIFIER_KEY {
27 KEY_CTRL = 1,
28 KEY_SHIFT = 2,
29 KEY_ALT = 4,
30 };
31
32
33 enum MEDIA_KEY {
34 KEY_NEXT_TRACK, /*!< next Track Button */
35 KEY_PREVIOUS_TRACK, /*!< Previous track Button */
36 KEY_STOP, /*!< Stop Button */
37 KEY_PLAY_PAUSE, /*!< Play/Pause Button */
38 KEY_MUTE, /*!< Mute Button */
39 KEY_VOLUME_UP, /*!< Volume Up Button */
40 KEY_VOLUME_DOWN, /*!< Volume Down Button */
41 };
42
43 enum FUNCTION_KEY {
44 KEY_F1 = 128, /* F1 key */
45 KEY_F2, /* F2 key */
46 KEY_F3, /* F3 key */
47 KEY_F4, /* F4 key */
48 KEY_F5, /* F5 key */
49 KEY_F6, /* F6 key */
50 KEY_F7, /* F7 key */
51 KEY_F8, /* F8 key */
52 KEY_F9, /* F9 key */
53 KEY_F10, /* F10 key */
54 KEY_F11, /* F11 key */
55 KEY_F12, /* F12 key */
56
57 KEY_PRINT_SCREEN, /* Print Screen key */
58 KEY_SCROLL_LOCK, /* Scroll lock */
59 KEY_CAPS_LOCK, /* caps lock */
60 KEY_NUM_LOCK, /* num lock */
61 KEY_INSERT, /* Insert key */
62 KEY_HOME, /* Home key */
63 KEY_PAGE_UP, /* Page Up key */
64 KEY_PAGE_DOWN, /* Page Down key */
65
66 RIGHT_ARROW, /* Right arrow */
67 LEFT_ARROW, /* Left arrow */
68 DOWN_ARROW, /* Down arrow */
69 UP_ARROW, /* Up arrow */
70 };
71
72 /**
73 * USBKeyboard example
74 * @code
75 *
76 * #include "mbed.h"
77 * #include "USBKeyboard.h"
78 *
79 * USBKeyboard key;
80 *
81 * int main(void)
82 * {
83 * while (1)
84 * {
85 * key.printf("Hello World\r\n");
86 * wait(1);
87 * }
88 * }
89 *
90 * @endcode
91 */
92 class USBKeyboard: public USBHID, public Stream {
93 public:
94
95 /**
96 * Constructor
97 *
98 *
99 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
100 * @param vendor_id Your vendor_id (default: 0x1235)
101 * @param product_id Your product_id (default: 0x0050)
102 * @param product_release Your preoduct_release (default: 0x0001)
103 *
104 */
105 USBKeyboard(uint16_t vendor_id = 0x1235, uint16_t product_id = 0x0050, uint16_t product_release = 0x0001):
106 USBHID(0, 0, vendor_id, product_id, product_release, false) {
107 lock_status = 0;
108 connect();
109 };
110
111 /**
112 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
113 *
114 * @code
115 * //To send CTRL + s (save)
116 * keyboard.keyCode('s', KEY_CTRL);
117 * @endcode
118 *
119 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
120 * @param key character to send
121 * @returns true if there is no error, false otherwise
122 */
123 bool keyCode(uint8_t key, uint8_t modifier = 0);
124
125 /**
126 * Send a character
127 *
128 * @param c character to be sent
129 * @returns true if there is no error, false otherwise
130 */
131 virtual int _putc(int c);
132
133 /**
134 * Control media keys
135 *
136 * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN)
137 * @returns true if there is no error, false otherwise
138 */
139 bool mediaControl(MEDIA_KEY key);
140
141 /*
142 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
143 *
144 * @returns pointer to the report descriptor
145 */
146 virtual uint8_t * reportDesc();
147
148 /*
149 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
150 *
151 * @returns if handle by subclass, return true
152 */
153 virtual bool EPINT_OUT_callback();
154
155 /**
156 * 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:
157 * - First bit: NUM_LOCK
158 * - Second bit: CAPS_LOCK
159 * - Third bit: SCROLL_LOCK
160 *
161 * @returns status of lock keys
162 */
163 uint8_t lockStatus();
164
165 protected:
166 /*
167 * Get configuration descriptor
168 *
169 * @returns pointer to the configuration descriptor
170 */
171 virtual uint8_t * configurationDesc();
172
173 private:
174 //dummy otherwise it doesn,t compile (we must define all methods of an abstract class)
175 virtual int _getc() {
176 return -1;
177 };
178
179 uint8_t lock_status;
180
181 };
182
183 #endif
Imprint / Impressum