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