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