1 /* Copyright (c) 2010-2011 mbed.org, MIT License
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:
9 * The above copyright notice and this permission notice shall be included in all copies or
10 * substantial portions of the Software.
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.
22 /* These headers are included for child class. */
23 #include "USBEndpoints.h"
24 #include "USBDescriptor.h"
25 #include "USBDevice_Types.h"
27 #include "USBHID_Types.h"
28 #include "USBDevice.h"
39 * BusOut leds(LED1,LED2,LED3,LED4);
44 * leds = recv.data[0];
50 class USBHID: public USBDevice {
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
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);
67 * Send a Report. warning: blocking
69 * @param report Report which will be sent (a report is defined by all data and the length)
70 * @returns true if successful
72 bool send(HID_REPORT *report);
76 * Send a Report. warning: non blocking
78 * @param report Report which will be sent (a report is defined by all data and the length)
79 * @returns true if successful
81 bool sendNB(HID_REPORT *report);
84 * Read a report: blocking
86 * @param report pointer to the report to fill
87 * @returns true if successful
89 bool read(HID_REPORT * report);
92 * Read a report: non blocking
94 * @param report pointer to the report to fill
95 * @returns true if successful
97 bool readNB(HID_REPORT * report);
100 uint16_t reportLength;
103 * Get the Report descriptor
105 * @returns pointer to the report descriptor
107 virtual uint8_t * reportDesc();
110 * Get the length of the report descriptor
112 * @returns the length of the report descriptor
114 virtual uint16_t reportDescLength();
117 * Get string product descriptor
119 * @returns pointer to the string product descriptor
121 virtual uint8_t * stringIproductDesc();
124 * Get string interface descriptor
126 * @returns pointer to the string interface descriptor
128 virtual uint8_t * stringIinterfaceDesc();
131 * Get configuration descriptor
133 * @returns pointer to the configuration descriptor
135 virtual uint8_t * configurationDesc();
139 * HID Report received by SET_REPORT request. Warning: Called in ISR context
140 * First byte of data will be the report ID
142 * @param report Data and length received
144 virtual void HID_callbackSetReport(HID_REPORT *report){};
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
152 * @returns true if class handles this request
154 virtual bool USBCallback_request();
158 * Called by USBDevice layer. Set configuration of the device.
159 * For instance, you can add all endpoints that you need on this function.
161 * @param configuration Number of the configuration
162 * @returns true if class handles this request
164 virtual bool USBCallback_setConfiguration(uint8_t configuration);
167 HID_REPORT outputReport;
168 uint8_t output_length;
169 uint8_t input_length;