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