]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/USBDevice/USBHID/USBHID.h
remove experimental return, cleanup slash_question key
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / USBDevice / USBHID / USBHID.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 USB_HID_H
20 #define USB_HID_H
21
22 /* These headers are included for child class. */
23 #include "USBEndpoints.h"
24 #include "USBDescriptor.h"
25 #include "USBDevice_Types.h"
26
27 #include "USBHID_Types.h"
28 #include "USBDevice.h"
29
30
31 /**
32 * USBHID example
33 * @code
34 * #include "mbed.h"
35 * #include "USBHID.h"
36 *
37 * USBHID hid;
38 * HID_REPORT recv;
39 * BusOut leds(LED1,LED2,LED3,LED4);
40 *
41 * int main(void) {
42 * while (1) {
43 * hid.read(&recv);
44 * leds = recv.data[0];
45 * }
46 * }
47 * @endcode
48 */
49
50 class USBHID: public USBDevice {
51 public:
52
53 /**
54 * Constructor
55 *
56 * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
57 * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
58 * @param vendor_id Your vendor_id
59 * @param product_id Your product_id
60 * @param product_release Your preoduct_release
61 * @param connect Connect the device
62 */
63 USBHID(uint8_t output_report_length = 64, uint8_t input_report_length = 64, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0006, uint16_t product_release = 0x0001, bool connect = true);
64
65
66 /**
67 * Send a Report. warning: blocking
68 *
69 * @param report Report which will be sent (a report is defined by all data and the length)
70 * @returns true if successful
71 */
72 bool send(HID_REPORT *report);
73
74
75 /**
76 * Send a Report. warning: non blocking
77 *
78 * @param report Report which will be sent (a report is defined by all data and the length)
79 * @returns true if successful
80 */
81 bool sendNB(HID_REPORT *report);
82
83 /**
84 * Read a report: blocking
85 *
86 * @param report pointer to the report to fill
87 * @returns true if successful
88 */
89 bool read(HID_REPORT * report);
90
91 /**
92 * Read a report: non blocking
93 *
94 * @param report pointer to the report to fill
95 * @returns true if successful
96 */
97 bool readNB(HID_REPORT * report);
98
99 protected:
100 uint16_t reportLength;
101
102 /*
103 * Get the Report descriptor
104 *
105 * @returns pointer to the report descriptor
106 */
107 virtual uint8_t * reportDesc();
108
109 /*
110 * Get the length of the report descriptor
111 *
112 * @returns the length of the report descriptor
113 */
114 virtual uint16_t reportDescLength();
115
116 /*
117 * Get string product descriptor
118 *
119 * @returns pointer to the string product descriptor
120 */
121 virtual uint8_t * stringIproductDesc();
122
123 /*
124 * Get string interface descriptor
125 *
126 * @returns pointer to the string interface descriptor
127 */
128 virtual uint8_t * stringIinterfaceDesc();
129
130 /*
131 * Get configuration descriptor
132 *
133 * @returns pointer to the configuration descriptor
134 */
135 virtual uint8_t * configurationDesc();
136
137
138 /*
139 * HID Report received by SET_REPORT request. Warning: Called in ISR context
140 * First byte of data will be the report ID
141 *
142 * @param report Data and length received
143 */
144 virtual void HID_callbackSetReport(HID_REPORT *report){};
145
146
147 /*
148 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
149 * This is used to handle extensions to standard requests
150 * and class specific requests
151 *
152 * @returns true if class handles this request
153 */
154 virtual bool USBCallback_request();
155
156
157 /*
158 * Called by USBDevice layer. Set configuration of the device.
159 * For instance, you can add all endpoints that you need on this function.
160 *
161 * @param configuration Number of the configuration
162 * @returns true if class handles this request
163 */
164 virtual bool USBCallback_setConfiguration(uint8_t configuration);
165
166 private:
167 HID_REPORT outputReport;
168 uint8_t output_length;
169 uint8_t input_length;
170 };
171
172 #endif
Imprint / Impressum