init
Embed:
(wiki syntax)
Show/hide line numbers
USBHID.h
00001 /* Copyright (c) 2010-2011 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #ifndef USB_HID_H 00020 #define USB_HID_H 00021 00022 /* These headers are included for child class. */ 00023 #include "USBEndpoints.h" 00024 #include "USBDescriptor.h" 00025 #include "USBDevice_Types.h" 00026 00027 #include "USBHID_Types.h" 00028 #include "USBDevice.h" 00029 00030 00031 /** 00032 * USBHID example 00033 * @code 00034 * #include "mbed.h" 00035 * #include "USBHID.h" 00036 * 00037 * USBHID hid; 00038 * HID_REPORT recv; 00039 * BusOut leds(LED1,LED2,LED3,LED4); 00040 * 00041 * int main(void) { 00042 * while (1) { 00043 * hid.read(&recv); 00044 * leds = recv.data[0]; 00045 * } 00046 * } 00047 * @endcode 00048 */ 00049 00050 class USBHID: public USBDevice { 00051 public: 00052 00053 /** 00054 * Constructor 00055 * 00056 * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes) 00057 * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes) 00058 * @param vendor_id Your vendor_id 00059 * @param product_id Your product_id 00060 * @param product_release Your preoduct_release 00061 * @param connect Connect the device 00062 */ 00063 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); 00064 00065 00066 /** 00067 * Send a Report. warning: blocking 00068 * 00069 * @param report Report which will be sent (a report is defined by all data and the length) 00070 * @returns true if successful 00071 */ 00072 bool send(HID_REPORT *report); 00073 00074 00075 /** 00076 * Send a Report. warning: non blocking 00077 * 00078 * @param report Report which will be sent (a report is defined by all data and the length) 00079 * @returns true if successful 00080 */ 00081 bool sendNB(HID_REPORT *report); 00082 00083 /** 00084 * Read a report: blocking 00085 * 00086 * @param report pointer to the report to fill 00087 * @returns true if successful 00088 */ 00089 bool read(HID_REPORT * report); 00090 00091 /** 00092 * Read a report: non blocking 00093 * 00094 * @param report pointer to the report to fill 00095 * @returns true if successful 00096 */ 00097 bool readNB(HID_REPORT * report); 00098 00099 protected: 00100 uint16_t reportLength; 00101 uint8_t reportDescriptor[27]; 00102 00103 /* 00104 * Get the Report descriptor 00105 * 00106 * @returns pointer to the report descriptor 00107 */ 00108 virtual const uint8_t * reportDesc(); 00109 00110 /* 00111 * Get the length of the report descriptor 00112 * 00113 * @returns the length of the report descriptor 00114 */ 00115 virtual uint16_t reportDescLength(); 00116 00117 /* 00118 * Get string product descriptor 00119 * 00120 * @returns pointer to the string product descriptor 00121 */ 00122 virtual const uint8_t * stringIproductDesc(); 00123 00124 /* 00125 * Get string interface descriptor 00126 * 00127 * @returns pointer to the string interface descriptor 00128 */ 00129 virtual const uint8_t * stringIinterfaceDesc(); 00130 00131 /* 00132 * Get configuration descriptor 00133 * 00134 * @returns pointer to the configuration descriptor 00135 */ 00136 virtual const uint8_t * configurationDesc(); 00137 00138 00139 /* 00140 * HID Report received by SET_REPORT request. Warning: Called in ISR context 00141 * First byte of data will be the report ID 00142 * 00143 * @param report Data and length received 00144 */ 00145 virtual void HID_callbackSetReport(HID_REPORT *report){}; 00146 00147 00148 /* 00149 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context 00150 * This is used to handle extensions to standard requests 00151 * and class specific requests 00152 * 00153 * @returns true if class handles this request 00154 */ 00155 virtual bool USBCallback_request(); 00156 00157 00158 /* 00159 * Called by USBDevice layer. Set configuration of the device. 00160 * For instance, you can add all endpoints that you need on this function. 00161 * 00162 * @param configuration Number of the configuration 00163 * @returns true if class handles this request 00164 */ 00165 virtual bool USBCallback_setConfiguration(uint8_t configuration); 00166 00167 private: 00168 uint8_t configurationDescriptor[41]; 00169 HID_REPORT outputReport; 00170 uint8_t output_length; 00171 uint8_t input_length; 00172 }; 00173 00174 #endif
Generated on Tue Jul 12 2022 13:25:19 by
1.7.2