USBMSD SD card Hello World for Mbed platforms

Dependencies:   mbed USBMSD_SD USBDevice

Committer:
samux
Date:
Fri Nov 11 15:22:53 2011 +0000
Revision:
2:27a7e7f8d399
we have 2MB with the sdcard!!

Who changed what in which revision?

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