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