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