USB CDC (serial) and USB MSC (strage) Composite Device. http://mbed.org/users/okini3939/notebook/USB_Device/

Dependencies:   ChaNFSSD mbed ChaNFS

Committer:
okini3939
Date:
Fri Dec 23 16:37:58 2011 +0000
Revision:
2:5db90410bb90
Parent:
0:9b1d17d54055

        

Who changed what in which revision?

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