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