USB device stack - modified
Fork of USBDevice by
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 "USBDevice/USBDevice/USBEndpoints.h" 00024 #include "USBDevice/USBDevice/USBDescriptor.h" 00025 #include "USBDevice/USBDevice/USBDevice_Types.h" 00026 00027 #include "USBHID_Types.h" 00028 #include "USBDevice/USBDevice/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 { 00052 public: 00053 00054 /** 00055 * Constructor 00056 * 00057 * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes) 00058 * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes) 00059 * @param vendor_id Your vendor_id 00060 * @param product_id Your product_id 00061 * @param product_release Your preoduct_release 00062 * @param connect Connect the device 00063 */ 00064 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 ); 00065 00066 00067 /** 00068 * Send a Report. warning: blocking 00069 * 00070 * @param report Report which will be sent (a report is defined by all data and the length) 00071 * @returns true if successful 00072 */ 00073 bool send( HID_REPORT *report ); 00074 00075 00076 /** 00077 * Send a Report. warning: non blocking 00078 * 00079 * @param report Report which will be sent (a report is defined by all data and the length) 00080 * @returns true if successful 00081 */ 00082 bool sendNB( HID_REPORT *report ); 00083 00084 /** 00085 * Read a report: blocking 00086 * 00087 * @param report pointer to the report to fill 00088 * @returns true if successful 00089 */ 00090 bool read( HID_REPORT *report ); 00091 00092 /** 00093 * Read a report: non blocking 00094 * 00095 * @param report pointer to the report to fill 00096 * @returns true if successful 00097 */ 00098 bool readNB( HID_REPORT *report ); 00099 00100 protected: 00101 uint16_t reportLength; 00102 00103 /* 00104 * Get the Report descriptor 00105 * 00106 * @returns pointer to the report descriptor 00107 */ 00108 virtual 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 uint8_t *stringIproductDesc(); 00123 00124 /* 00125 * Get string interface descriptor 00126 * 00127 * @returns pointer to the string interface descriptor 00128 */ 00129 virtual uint8_t *stringIinterfaceDesc(); 00130 00131 /* 00132 * Get configuration descriptor 00133 * 00134 * @returns pointer to the configuration descriptor 00135 */ 00136 virtual 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 HID_REPORT outputReport; 00169 uint8_t output_length; 00170 uint8_t input_length; 00171 }; 00172 00173 #endif 00174
Generated on Sat Jul 16 2022 03:17:41 by 1.7.2