added missing files
[clinton/Smoothieware.git] / src / libs / USBDevice / USBHID / USBHID.h
CommitLineData
d9ebc974
AW
1/* Copyright (c) 2010-2011 mbed.org, MIT License\r
2*\r
3* Permission is hereby granted, free of charge, to any person obtaining a copy of this software\r
4* and associated documentation files (the "Software"), to deal in the Software without\r
5* restriction, including without limitation the rights to use, copy, modify, merge, publish,\r
6* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the\r
7* Software is furnished to do so, subject to the following conditions:\r
8*\r
9* The above copyright notice and this permission notice shall be included in all copies or\r
10* substantial portions of the Software.\r
11*\r
12* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING\r
13* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
14* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\r
15* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
16* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
17*/\r
18\r
19#ifndef USB_HID_H\r
20#define USB_HID_H\r
21\r
22/* These headers are included for child class. */\r
23#include "USBEndpoints.h"\r
24#include "USBDescriptor.h"\r
25#include "USBDevice_Types.h"\r
26\r
27#include "USBHID_Types.h"\r
28#include "USBDevice.h"\r
29\r
30\r
31/**\r
32 * USBHID example\r
33 * @code\r
34 * #include "mbed.h"\r
35 * #include "USBHID.h"\r
36 *\r
37 * USBHID hid;\r
38 * HID_REPORT recv;\r
39 * BusOut leds(LED1,LED2,LED3,LED4);\r
40 *\r
41 * int main(void) {\r
42 * while (1) {\r
43 * hid.read(&recv);\r
44 * leds = recv.data[0];\r
45 * }\r
46 * }\r
47 * @endcode\r
48 */\r
49\r
50class USBHID: public USBDevice {\r
51public:\r
52\r
53 /**\r
54 * Constructor\r
55 *\r
56 * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)\r
57 * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes)\r
58 * @param vendor_id Your vendor_id\r
59 * @param product_id Your product_id\r
60 * @param product_release Your preoduct_release\r
61 * @param connect Connect the device\r
62 */\r
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);\r
64\r
65\r
66 /**\r
67 * Send a Report. warning: blocking\r
68 *\r
69 * @param report Report which will be sent (a report is defined by all data and the length)\r
70 * @returns true if successful\r
71 */\r
72 bool send(HID_REPORT *report);\r
73 \r
74 \r
75 /**\r
76 * Send a Report. warning: non blocking\r
77 *\r
78 * @param report Report which will be sent (a report is defined by all data and the length)\r
79 * @returns true if successful\r
80 */\r
81 bool sendNB(HID_REPORT *report);\r
82 \r
83 /**\r
84 * Read a report: blocking\r
85 *\r
86 * @param report pointer to the report to fill\r
87 * @returns true if successful\r
88 */\r
89 bool read(HID_REPORT * report);\r
90 \r
91 /**\r
92 * Read a report: non blocking\r
93 *\r
94 * @param report pointer to the report to fill\r
95 * @returns true if successful\r
96 */\r
97 bool readNB(HID_REPORT * report);\r
98\r
99protected:\r
100 uint16_t reportLength;\r
101 \r
102 /*\r
103 * Get the Report descriptor\r
104 *\r
105 * @returns pointer to the report descriptor\r
106 */\r
107 virtual uint8_t * reportDesc();\r
108\r
109 /*\r
110 * Get the length of the report descriptor\r
111 *\r
112 * @returns the length of the report descriptor\r
113 */\r
114 virtual uint16_t reportDescLength();\r
115\r
116 /*\r
117 * Get string product descriptor\r
118 *\r
119 * @returns pointer to the string product descriptor\r
120 */\r
121 virtual uint8_t * stringIproductDesc();\r
122 \r
123 /*\r
124 * Get string interface descriptor\r
125 *\r
126 * @returns pointer to the string interface descriptor\r
127 */\r
128 virtual uint8_t * stringIinterfaceDesc();\r
129 \r
130 /*\r
131 * Get configuration descriptor\r
132 *\r
133 * @returns pointer to the configuration descriptor\r
134 */\r
135 virtual uint8_t * configurationDesc();\r
136\r
137\r
138 /*\r
139 * HID Report received by SET_REPORT request. Warning: Called in ISR context\r
140 * First byte of data will be the report ID\r
141 *\r
142 * @param report Data and length received\r
143 */\r
144 virtual void HID_callbackSetReport(HID_REPORT *report){};\r
145\r
146\r
147 /*\r
148 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context\r
149 * This is used to handle extensions to standard requests\r
150 * and class specific requests\r
151 *\r
152 * @returns true if class handles this request\r
153 */\r
154 virtual bool USBCallback_request();\r
155\r
156\r
157 /*\r
158 * Called by USBDevice layer. Set configuration of the device.\r
159 * For instance, you can add all endpoints that you need on this function.\r
160 *\r
161 * @param configuration Number of the configuration\r
162 * @returns true if class handles this request\r
163 */\r
164 virtual bool USBCallback_setConfiguration(uint8_t configuration);\r
165\r
166private:\r
167 HID_REPORT outputReport;\r
168 uint8_t output_length;\r
169 uint8_t input_length;\r
170};\r
171\r
172#endif\r