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/USBDevice/USBDevice.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 USBDEVICE_H |
samux |
11:a26e7b7a1221 | 20 | #define USBDEVICE_H |
samux |
11:a26e7b7a1221 | 21 | |
samux |
11:a26e7b7a1221 | 22 | #include "mbed.h" |
samux |
11:a26e7b7a1221 | 23 | #include "USBDevice_Types.h" |
samux |
11:a26e7b7a1221 | 24 | #include "USBBusInterface.h" |
samux |
11:a26e7b7a1221 | 25 | |
samux |
11:a26e7b7a1221 | 26 | |
samux |
11:a26e7b7a1221 | 27 | |
samux |
11:a26e7b7a1221 | 28 | class USBDevice: public USBHAL |
samux |
11:a26e7b7a1221 | 29 | { |
samux |
11:a26e7b7a1221 | 30 | public: |
samux |
11:a26e7b7a1221 | 31 | USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release); |
samux |
11:a26e7b7a1221 | 32 | |
samux |
11:a26e7b7a1221 | 33 | /* |
samux |
11:a26e7b7a1221 | 34 | * Check if the device is configured |
samux |
11:a26e7b7a1221 | 35 | * |
samux |
11:a26e7b7a1221 | 36 | * @returns true if configured, false otherwise |
samux |
11:a26e7b7a1221 | 37 | */ |
samux |
11:a26e7b7a1221 | 38 | bool configured(void); |
samux |
11:a26e7b7a1221 | 39 | |
samux |
11:a26e7b7a1221 | 40 | /* |
samux |
11:a26e7b7a1221 | 41 | * Connect a device |
samux |
11:a26e7b7a1221 | 42 | */ |
samux |
11:a26e7b7a1221 | 43 | void connect(void); |
samux |
11:a26e7b7a1221 | 44 | |
samux |
11:a26e7b7a1221 | 45 | /* |
samux |
11:a26e7b7a1221 | 46 | * Disconnect a device |
samux |
11:a26e7b7a1221 | 47 | */ |
samux |
11:a26e7b7a1221 | 48 | void disconnect(void); |
samux |
11:a26e7b7a1221 | 49 | |
samux |
11:a26e7b7a1221 | 50 | /* |
samux |
11:a26e7b7a1221 | 51 | * Add an endpoint |
samux |
11:a26e7b7a1221 | 52 | * |
samux |
11:a26e7b7a1221 | 53 | * @param endpoint endpoint which will be added |
samux |
11:a26e7b7a1221 | 54 | * @param maxPacket Maximum size of a packet which can be sent for this endpoint |
samux |
11:a26e7b7a1221 | 55 | * @returns true if successful, false otherwise |
samux |
11:a26e7b7a1221 | 56 | */ |
samux |
11:a26e7b7a1221 | 57 | bool addEndpoint(uint8_t endpoint, uint32_t maxPacket); |
samux |
11:a26e7b7a1221 | 58 | |
samux |
11:a26e7b7a1221 | 59 | /* |
samux |
11:a26e7b7a1221 | 60 | * Start a reading on a certain endpoint. |
samux |
11:a26e7b7a1221 | 61 | * You can access the result of the reading by USBDevice_read |
samux |
11:a26e7b7a1221 | 62 | * |
samux |
11:a26e7b7a1221 | 63 | * @param endpoint endpoint which will be read |
samux |
11:a26e7b7a1221 | 64 | * @param maxSize the maximum length that can be read |
samux |
11:a26e7b7a1221 | 65 | * @return true if successful |
samux |
11:a26e7b7a1221 | 66 | */ |
samux |
11:a26e7b7a1221 | 67 | bool readStart(uint8_t endpoint, uint16_t maxSize); |
samux |
11:a26e7b7a1221 | 68 | |
samux |
11:a26e7b7a1221 | 69 | /* |
samux |
11:a26e7b7a1221 | 70 | * Read a certain endpoint. Before calling this function, USBUSBDevice_readStart |
samux |
11:a26e7b7a1221 | 71 | * must be called. |
samux |
11:a26e7b7a1221 | 72 | * |
samux |
11:a26e7b7a1221 | 73 | * Warning: blocking |
samux |
11:a26e7b7a1221 | 74 | * |
samux |
11:a26e7b7a1221 | 75 | * @param endpoint endpoint which will be read |
samux |
11:a26e7b7a1221 | 76 | * @param buffer buffer will be filled with the data received |
samux |
11:a26e7b7a1221 | 77 | * @param size the number of bytes read will be stored in *size |
samux |
11:a26e7b7a1221 | 78 | * @param maxSize the maximum length that can be read |
samux |
11:a26e7b7a1221 | 79 | * @returns true if successful |
samux |
11:a26e7b7a1221 | 80 | */ |
samux |
11:a26e7b7a1221 | 81 | bool read(uint8_t endpoint, uint8_t * buffer, uint16_t * size, uint16_t maxSize); |
samux |
11:a26e7b7a1221 | 82 | |
samux |
11:a26e7b7a1221 | 83 | /* |
samux |
11:a26e7b7a1221 | 84 | * Read a certain endpoint. |
samux |
11:a26e7b7a1221 | 85 | * |
samux |
11:a26e7b7a1221 | 86 | * Warning: non blocking |
samux |
11:a26e7b7a1221 | 87 | * |
samux |
11:a26e7b7a1221 | 88 | * @param endpoint endpoint which will be read |
samux |
11:a26e7b7a1221 | 89 | * @param buffer buffer will be filled with the data received (if data are available) |
samux |
11:a26e7b7a1221 | 90 | * @param size the number of bytes read will be stored in *size |
samux |
11:a26e7b7a1221 | 91 | * @param maxSize the maximum length that can be read |
samux |
11:a26e7b7a1221 | 92 | * @returns true if successful |
samux |
11:a26e7b7a1221 | 93 | */ |
samux |
11:a26e7b7a1221 | 94 | bool readNB(uint8_t endpoint, uint8_t * buffer, uint16_t * size, uint16_t maxSize); |
samux |
11:a26e7b7a1221 | 95 | |
samux |
11:a26e7b7a1221 | 96 | /* |
samux |
11:a26e7b7a1221 | 97 | * Write a certain endpoint. |
samux |
11:a26e7b7a1221 | 98 | * |
samux |
11:a26e7b7a1221 | 99 | * Warning: blocking |
samux |
11:a26e7b7a1221 | 100 | * |
samux |
11:a26e7b7a1221 | 101 | * @param endpoint endpoint to write |
samux |
11:a26e7b7a1221 | 102 | * @param buffer data contained in buffer will be write |
samux |
11:a26e7b7a1221 | 103 | * @param size the number of bytes to write |
samux |
11:a26e7b7a1221 | 104 | * @param maxSize the maximum length that can be written on this endpoint |
samux |
11:a26e7b7a1221 | 105 | */ |
samux |
11:a26e7b7a1221 | 106 | bool write(uint8_t endpoint, uint8_t * buffer, uint16_t size, uint16_t maxSize); |
samux |
11:a26e7b7a1221 | 107 | bool writeNB(uint8_t endpoint, uint8_t * buffer, uint16_t size, uint16_t maxSize); |
samux |
11:a26e7b7a1221 | 108 | |
samux |
11:a26e7b7a1221 | 109 | |
samux |
11:a26e7b7a1221 | 110 | /* |
samux |
11:a26e7b7a1221 | 111 | * Called by USBDevice layer on bus reset. Warning: Called in ISR context |
samux |
11:a26e7b7a1221 | 112 | * |
samux |
11:a26e7b7a1221 | 113 | * May be used to reset state |
samux |
11:a26e7b7a1221 | 114 | */ |
samux |
11:a26e7b7a1221 | 115 | virtual void USBCallback_busReset(void) {}; |
samux |
11:a26e7b7a1221 | 116 | |
samux |
11:a26e7b7a1221 | 117 | /* |
samux |
11:a26e7b7a1221 | 118 | * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context |
samux |
11:a26e7b7a1221 | 119 | * This is used to handle extensions to standard requests |
samux |
11:a26e7b7a1221 | 120 | * and class specific requests |
samux |
11:a26e7b7a1221 | 121 | * |
samux |
11:a26e7b7a1221 | 122 | * @returns true if class handles this request |
samux |
11:a26e7b7a1221 | 123 | */ |
samux |
11:a26e7b7a1221 | 124 | virtual bool USBCallback_request() { return false; }; |
samux |
11:a26e7b7a1221 | 125 | |
samux |
11:a26e7b7a1221 | 126 | /* |
samux |
11:a26e7b7a1221 | 127 | * Called by USBDevice on Endpoint0 request completion |
samux |
11:a26e7b7a1221 | 128 | * if the 'notify' flag has been set to true. Warning: Called in ISR context |
samux |
11:a26e7b7a1221 | 129 | * |
samux |
11:a26e7b7a1221 | 130 | * In this case it is used to indicate that a HID report has |
samux |
11:a26e7b7a1221 | 131 | * been received from the host on endpoint 0 |
samux |
11:a26e7b7a1221 | 132 | */ |
samux |
11:a26e7b7a1221 | 133 | virtual void USBCallback_requestCompleted() {}; |
samux |
11:a26e7b7a1221 | 134 | |
samux |
11:a26e7b7a1221 | 135 | /* |
samux |
11:a26e7b7a1221 | 136 | * Called by USBDevice layer. Set configuration of the device. |
samux |
11:a26e7b7a1221 | 137 | * For instance, you can add all endpoints that you need on this function. |
samux |
11:a26e7b7a1221 | 138 | * |
samux |
11:a26e7b7a1221 | 139 | * @param configuration Number of the configuration |
samux |
11:a26e7b7a1221 | 140 | */ |
samux |
11:a26e7b7a1221 | 141 | virtual bool USBCallback_setConfiguration(uint8_t configuration) { return false; }; |
samux |
11:a26e7b7a1221 | 142 | |
samux |
11:a26e7b7a1221 | 143 | /* |
samux |
11:a26e7b7a1221 | 144 | * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
samux |
11:a26e7b7a1221 | 145 | * |
samux |
11:a26e7b7a1221 | 146 | * @returns pointer to the device descriptor |
samux |
11:a26e7b7a1221 | 147 | */ |
samux |
11:a26e7b7a1221 | 148 | virtual uint8_t * deviceDesc(); |
samux |
11:a26e7b7a1221 | 149 | |
samux |
11:a26e7b7a1221 | 150 | /* |
samux |
11:a26e7b7a1221 | 151 | * Get configuration descriptor |
samux |
11:a26e7b7a1221 | 152 | * |
samux |
11:a26e7b7a1221 | 153 | * @returns pointer to the configuration descriptor |
samux |
11:a26e7b7a1221 | 154 | */ |
samux |
11:a26e7b7a1221 | 155 | virtual uint8_t * configurationDesc(){return NULL;}; |
samux |
11:a26e7b7a1221 | 156 | |
samux |
11:a26e7b7a1221 | 157 | /* |
samux |
11:a26e7b7a1221 | 158 | * Get string lang id descriptor |
samux |
11:a26e7b7a1221 | 159 | * |
samux |
11:a26e7b7a1221 | 160 | * @return pointer to the string lang id descriptor |
samux |
11:a26e7b7a1221 | 161 | */ |
samux |
11:a26e7b7a1221 | 162 | virtual uint8_t * stringLangidDesc(); |
samux |
11:a26e7b7a1221 | 163 | |
samux |
11:a26e7b7a1221 | 164 | /* |
samux |
11:a26e7b7a1221 | 165 | * Get string manufacturer descriptor |
samux |
11:a26e7b7a1221 | 166 | * |
samux |
11:a26e7b7a1221 | 167 | * @returns pointer to the string manufacturer descriptor |
samux |
11:a26e7b7a1221 | 168 | */ |
samux |
11:a26e7b7a1221 | 169 | virtual uint8_t * stringImanufacturerDesc(); |
samux |
11:a26e7b7a1221 | 170 | |
samux |
11:a26e7b7a1221 | 171 | /* |
samux |
11:a26e7b7a1221 | 172 | * Get string product descriptor |
samux |
11:a26e7b7a1221 | 173 | * |
samux |
11:a26e7b7a1221 | 174 | * @returns pointer to the string product descriptor |
samux |
11:a26e7b7a1221 | 175 | */ |
samux |
11:a26e7b7a1221 | 176 | virtual uint8_t * stringIproductDesc(); |
samux |
11:a26e7b7a1221 | 177 | |
samux |
11:a26e7b7a1221 | 178 | /* |
samux |
11:a26e7b7a1221 | 179 | * Get string serial descriptor |
samux |
11:a26e7b7a1221 | 180 | * |
samux |
11:a26e7b7a1221 | 181 | * @returns pointer to the string serial descriptor |
samux |
11:a26e7b7a1221 | 182 | */ |
samux |
11:a26e7b7a1221 | 183 | virtual uint8_t * stringIserialDesc(); |
samux |
11:a26e7b7a1221 | 184 | |
samux |
11:a26e7b7a1221 | 185 | /* |
samux |
11:a26e7b7a1221 | 186 | * Get string configuration descriptor |
samux |
11:a26e7b7a1221 | 187 | * |
samux |
11:a26e7b7a1221 | 188 | * @returns pointer to the string configuration descriptor |
samux |
11:a26e7b7a1221 | 189 | */ |
samux |
11:a26e7b7a1221 | 190 | virtual uint8_t * stringIConfigurationDesc(); |
samux |
11:a26e7b7a1221 | 191 | |
samux |
11:a26e7b7a1221 | 192 | /* |
samux |
11:a26e7b7a1221 | 193 | * Get string interface descriptor |
samux |
11:a26e7b7a1221 | 194 | * |
samux |
11:a26e7b7a1221 | 195 | * @returns pointer to the string interface descriptor |
samux |
11:a26e7b7a1221 | 196 | */ |
samux |
11:a26e7b7a1221 | 197 | virtual uint8_t * stringIinterfaceDesc(); |
samux |
11:a26e7b7a1221 | 198 | |
samux |
11:a26e7b7a1221 | 199 | /* |
samux |
11:a26e7b7a1221 | 200 | * Get the length of the report descriptor |
samux |
11:a26e7b7a1221 | 201 | * |
samux |
11:a26e7b7a1221 | 202 | * @returns length of the report descriptor |
samux |
11:a26e7b7a1221 | 203 | */ |
samux |
11:a26e7b7a1221 | 204 | virtual uint16_t reportDescLength() { return 0; }; |
samux |
11:a26e7b7a1221 | 205 | |
samux |
11:a26e7b7a1221 | 206 | |
samux |
11:a26e7b7a1221 | 207 | |
samux |
11:a26e7b7a1221 | 208 | protected: |
samux |
11:a26e7b7a1221 | 209 | virtual void busReset(void); |
samux |
11:a26e7b7a1221 | 210 | virtual void EP0setupCallback(void); |
samux |
11:a26e7b7a1221 | 211 | virtual void EP0out(void); |
samux |
11:a26e7b7a1221 | 212 | virtual void EP0in(void); |
samux |
11:a26e7b7a1221 | 213 | virtual void SOF(int frameNumber); |
samux |
11:a26e7b7a1221 | 214 | virtual void connectStateChanged(unsigned int connected); |
samux |
11:a26e7b7a1221 | 215 | virtual void suspendStateChanged(unsigned int suspended); |
samux |
11:a26e7b7a1221 | 216 | uint8_t * findDescriptor(uint8_t descriptorType); |
samux |
11:a26e7b7a1221 | 217 | CONTROL_TRANSFER * getTransferPtr(void); |
samux |
11:a26e7b7a1221 | 218 | |
samux |
11:a26e7b7a1221 | 219 | uint16_t VENDOR_ID; |
samux |
11:a26e7b7a1221 | 220 | uint16_t PRODUCT_ID; |
samux |
11:a26e7b7a1221 | 221 | uint16_t PRODUCT_RELEASE; |
samux |
11:a26e7b7a1221 | 222 | |
samux |
11:a26e7b7a1221 | 223 | private: |
samux |
11:a26e7b7a1221 | 224 | bool addRateFeedbackEndpoint(uint8_t endpoint, uint32_t maxPacket); |
samux |
11:a26e7b7a1221 | 225 | bool requestGetDescriptor(void); |
samux |
11:a26e7b7a1221 | 226 | bool controlOut(void); |
samux |
11:a26e7b7a1221 | 227 | bool controlIn(void); |
samux |
11:a26e7b7a1221 | 228 | bool requestSetAddress(void); |
samux |
11:a26e7b7a1221 | 229 | bool requestSetConfiguration(void); |
samux |
11:a26e7b7a1221 | 230 | bool requestSetFeature(void); |
samux |
11:a26e7b7a1221 | 231 | bool requestClearFeature(void); |
samux |
11:a26e7b7a1221 | 232 | bool requestGetStatus(void); |
samux |
11:a26e7b7a1221 | 233 | bool requestSetup(void); |
samux |
11:a26e7b7a1221 | 234 | bool controlSetup(void); |
samux |
11:a26e7b7a1221 | 235 | void decodeSetupPacket(uint8_t *data, SETUP_PACKET *packet); |
samux |
11:a26e7b7a1221 | 236 | bool requestGetConfiguration(void); |
samux |
11:a26e7b7a1221 | 237 | bool requestGetInterface(void); |
samux |
11:a26e7b7a1221 | 238 | bool requestSetInterface(void); |
samux |
11:a26e7b7a1221 | 239 | |
samux |
11:a26e7b7a1221 | 240 | CONTROL_TRANSFER transfer; |
samux |
11:a26e7b7a1221 | 241 | USB_DEVICE device; |
samux |
11:a26e7b7a1221 | 242 | }; |
samux |
11:a26e7b7a1221 | 243 | |
samux |
11:a26e7b7a1221 | 244 | |
samux |
11:a26e7b7a1221 | 245 | #endif |