CDC/ECM driver for mbed, based on USBDevice by mbed-official. Uses PicoTCP to access Ethernet USB device. License: GPLv2

Dependents:   USBEthernet_TEST

Fork of USB_Ethernet by Daniele Lacamera

Committer:
daniele
Date:
Sat Aug 03 13:16:14 2013 +0000
Revision:
2:540f6e142d59
Moved to single package

Who changed what in which revision?

UserRevisionLine numberNew contents of line
daniele 2:540f6e142d59 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
daniele 2:540f6e142d59 2 *
daniele 2:540f6e142d59 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
daniele 2:540f6e142d59 4 * and associated documentation files (the "Software"), to deal in the Software without
daniele 2:540f6e142d59 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
daniele 2:540f6e142d59 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
daniele 2:540f6e142d59 7 * Software is furnished to do so, subject to the following conditions:
daniele 2:540f6e142d59 8 *
daniele 2:540f6e142d59 9 * The above copyright notice and this permission notice shall be included in all copies or
daniele 2:540f6e142d59 10 * substantial portions of the Software.
daniele 2:540f6e142d59 11 *
daniele 2:540f6e142d59 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
daniele 2:540f6e142d59 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
daniele 2:540f6e142d59 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
daniele 2:540f6e142d59 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
daniele 2:540f6e142d59 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
daniele 2:540f6e142d59 17 */
daniele 2:540f6e142d59 18
daniele 2:540f6e142d59 19 #ifndef USBDEVICE_H
daniele 2:540f6e142d59 20 #define USBDEVICE_H
daniele 2:540f6e142d59 21
daniele 2:540f6e142d59 22 #include "mbed.h"
daniele 2:540f6e142d59 23 #include "USBDevice_Types.h"
daniele 2:540f6e142d59 24 #include "USBHAL.h"
daniele 2:540f6e142d59 25
daniele 2:540f6e142d59 26 class USBDevice: public USBHAL
daniele 2:540f6e142d59 27 {
daniele 2:540f6e142d59 28 public:
daniele 2:540f6e142d59 29 USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
daniele 2:540f6e142d59 30
daniele 2:540f6e142d59 31 /*
daniele 2:540f6e142d59 32 * Check if the device is configured
daniele 2:540f6e142d59 33 *
daniele 2:540f6e142d59 34 * @returns true if configured, false otherwise
daniele 2:540f6e142d59 35 */
daniele 2:540f6e142d59 36 bool configured(void);
daniele 2:540f6e142d59 37
daniele 2:540f6e142d59 38 /*
daniele 2:540f6e142d59 39 * Connect a device
daniele 2:540f6e142d59 40 */
daniele 2:540f6e142d59 41 void connect(void);
daniele 2:540f6e142d59 42
daniele 2:540f6e142d59 43 /*
daniele 2:540f6e142d59 44 * Disconnect a device
daniele 2:540f6e142d59 45 */
daniele 2:540f6e142d59 46 void disconnect(void);
daniele 2:540f6e142d59 47
daniele 2:540f6e142d59 48 /*
daniele 2:540f6e142d59 49 * Add an endpoint
daniele 2:540f6e142d59 50 *
daniele 2:540f6e142d59 51 * @param endpoint endpoint which will be added
daniele 2:540f6e142d59 52 * @param maxPacket Maximum size of a packet which can be sent for this endpoint
daniele 2:540f6e142d59 53 * @returns true if successful, false otherwise
daniele 2:540f6e142d59 54 */
daniele 2:540f6e142d59 55 bool addEndpoint(uint8_t endpoint, uint32_t maxPacket);
daniele 2:540f6e142d59 56
daniele 2:540f6e142d59 57 /*
daniele 2:540f6e142d59 58 * Start a reading on a certain endpoint.
daniele 2:540f6e142d59 59 * You can access the result of the reading by USBDevice_read
daniele 2:540f6e142d59 60 *
daniele 2:540f6e142d59 61 * @param endpoint endpoint which will be read
daniele 2:540f6e142d59 62 * @param maxSize the maximum length that can be read
daniele 2:540f6e142d59 63 * @return true if successful
daniele 2:540f6e142d59 64 */
daniele 2:540f6e142d59 65 bool readStart(uint8_t endpoint, uint32_t maxSize);
daniele 2:540f6e142d59 66
daniele 2:540f6e142d59 67 /*
daniele 2:540f6e142d59 68 * Read a certain endpoint. Before calling this function, USBUSBDevice_readStart
daniele 2:540f6e142d59 69 * must be called.
daniele 2:540f6e142d59 70 *
daniele 2:540f6e142d59 71 * Warning: blocking
daniele 2:540f6e142d59 72 *
daniele 2:540f6e142d59 73 * @param endpoint endpoint which will be read
daniele 2:540f6e142d59 74 * @param buffer buffer will be filled with the data received
daniele 2:540f6e142d59 75 * @param size the number of bytes read will be stored in *size
daniele 2:540f6e142d59 76 * @param maxSize the maximum length that can be read
daniele 2:540f6e142d59 77 * @returns true if successful
daniele 2:540f6e142d59 78 */
daniele 2:540f6e142d59 79 bool readEP(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
daniele 2:540f6e142d59 80
daniele 2:540f6e142d59 81 /*
daniele 2:540f6e142d59 82 * Read a certain endpoint.
daniele 2:540f6e142d59 83 *
daniele 2:540f6e142d59 84 * Warning: non blocking
daniele 2:540f6e142d59 85 *
daniele 2:540f6e142d59 86 * @param endpoint endpoint which will be read
daniele 2:540f6e142d59 87 * @param buffer buffer will be filled with the data received (if data are available)
daniele 2:540f6e142d59 88 * @param size the number of bytes read will be stored in *size
daniele 2:540f6e142d59 89 * @param maxSize the maximum length that can be read
daniele 2:540f6e142d59 90 * @returns true if successful
daniele 2:540f6e142d59 91 */
daniele 2:540f6e142d59 92 bool readEP_NB(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
daniele 2:540f6e142d59 93
daniele 2:540f6e142d59 94 /*
daniele 2:540f6e142d59 95 * Write a certain endpoint.
daniele 2:540f6e142d59 96 *
daniele 2:540f6e142d59 97 * Warning: blocking
daniele 2:540f6e142d59 98 *
daniele 2:540f6e142d59 99 * @param endpoint endpoint to write
daniele 2:540f6e142d59 100 * @param buffer data contained in buffer will be write
daniele 2:540f6e142d59 101 * @param size the number of bytes to write
daniele 2:540f6e142d59 102 * @param maxSize the maximum length that can be written on this endpoint
daniele 2:540f6e142d59 103 */
daniele 2:540f6e142d59 104 bool write(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
daniele 2:540f6e142d59 105
daniele 2:540f6e142d59 106
daniele 2:540f6e142d59 107 /*
daniele 2:540f6e142d59 108 * Write a certain endpoint.
daniele 2:540f6e142d59 109 *
daniele 2:540f6e142d59 110 * Warning: non blocking
daniele 2:540f6e142d59 111 *
daniele 2:540f6e142d59 112 * @param endpoint endpoint to write
daniele 2:540f6e142d59 113 * @param buffer data contained in buffer will be write
daniele 2:540f6e142d59 114 * @param size the number of bytes to write
daniele 2:540f6e142d59 115 * @param maxSize the maximum length that can be written on this endpoint
daniele 2:540f6e142d59 116 */
daniele 2:540f6e142d59 117 bool writeNB(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
daniele 2:540f6e142d59 118
daniele 2:540f6e142d59 119
daniele 2:540f6e142d59 120 /*
daniele 2:540f6e142d59 121 * Called by USBDevice layer on bus reset. Warning: Called in ISR context
daniele 2:540f6e142d59 122 *
daniele 2:540f6e142d59 123 * May be used to reset state
daniele 2:540f6e142d59 124 */
daniele 2:540f6e142d59 125 virtual void USBCallback_busReset(void) {};
daniele 2:540f6e142d59 126
daniele 2:540f6e142d59 127 /*
daniele 2:540f6e142d59 128 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
daniele 2:540f6e142d59 129 * This is used to handle extensions to standard requests
daniele 2:540f6e142d59 130 * and class specific requests
daniele 2:540f6e142d59 131 *
daniele 2:540f6e142d59 132 * @returns true if class handles this request
daniele 2:540f6e142d59 133 */
daniele 2:540f6e142d59 134 virtual bool USBCallback_request() { return false; };
daniele 2:540f6e142d59 135
daniele 2:540f6e142d59 136 /*
daniele 2:540f6e142d59 137 * Called by USBDevice on Endpoint0 request completion
daniele 2:540f6e142d59 138 * if the 'notify' flag has been set to true. Warning: Called in ISR context
daniele 2:540f6e142d59 139 *
daniele 2:540f6e142d59 140 * In this case it is used to indicate that a HID report has
daniele 2:540f6e142d59 141 * been received from the host on endpoint 0
daniele 2:540f6e142d59 142 *
daniele 2:540f6e142d59 143 * @param buf buffer received on endpoint 0
daniele 2:540f6e142d59 144 * @param length length of this buffer
daniele 2:540f6e142d59 145 */
daniele 2:540f6e142d59 146 virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length) {};
daniele 2:540f6e142d59 147
daniele 2:540f6e142d59 148 /*
daniele 2:540f6e142d59 149 * Called by USBDevice layer. Set configuration of the device.
daniele 2:540f6e142d59 150 * For instance, you can add all endpoints that you need on this function.
daniele 2:540f6e142d59 151 *
daniele 2:540f6e142d59 152 * @param configuration Number of the configuration
daniele 2:540f6e142d59 153 */
daniele 2:540f6e142d59 154 virtual bool USBCallback_setConfiguration(uint8_t configuration) { return false; };
daniele 2:540f6e142d59 155
daniele 2:540f6e142d59 156 /*
daniele 2:540f6e142d59 157 * Called by USBDevice layer. Set interface/alternate of the device.
daniele 2:540f6e142d59 158 *
daniele 2:540f6e142d59 159 * @param interface Number of the interface to be configured
daniele 2:540f6e142d59 160 * @param alternate Number of the alternate to be configured
daniele 2:540f6e142d59 161 * @returns true if class handles this request
daniele 2:540f6e142d59 162 */
daniele 2:540f6e142d59 163 virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate) { return false; };
daniele 2:540f6e142d59 164
daniele 2:540f6e142d59 165 /*
daniele 2:540f6e142d59 166 * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
daniele 2:540f6e142d59 167 *
daniele 2:540f6e142d59 168 * @returns pointer to the device descriptor
daniele 2:540f6e142d59 169 */
daniele 2:540f6e142d59 170 virtual uint8_t * deviceDesc();
daniele 2:540f6e142d59 171
daniele 2:540f6e142d59 172 /*
daniele 2:540f6e142d59 173 * Get configuration descriptor
daniele 2:540f6e142d59 174 *
daniele 2:540f6e142d59 175 * @returns pointer to the configuration descriptor
daniele 2:540f6e142d59 176 */
daniele 2:540f6e142d59 177 virtual uint8_t * configurationDesc(){return NULL;};
daniele 2:540f6e142d59 178
daniele 2:540f6e142d59 179 /*
daniele 2:540f6e142d59 180 * Get string lang id descriptor
daniele 2:540f6e142d59 181 *
daniele 2:540f6e142d59 182 * @return pointer to the string lang id descriptor
daniele 2:540f6e142d59 183 */
daniele 2:540f6e142d59 184 virtual uint8_t * stringLangidDesc();
daniele 2:540f6e142d59 185
daniele 2:540f6e142d59 186 /*
daniele 2:540f6e142d59 187 * Get string manufacturer descriptor
daniele 2:540f6e142d59 188 *
daniele 2:540f6e142d59 189 * @returns pointer to the string manufacturer descriptor
daniele 2:540f6e142d59 190 */
daniele 2:540f6e142d59 191 virtual uint8_t * stringImanufacturerDesc();
daniele 2:540f6e142d59 192
daniele 2:540f6e142d59 193 /*
daniele 2:540f6e142d59 194 * Get string product descriptor
daniele 2:540f6e142d59 195 *
daniele 2:540f6e142d59 196 * @returns pointer to the string product descriptor
daniele 2:540f6e142d59 197 */
daniele 2:540f6e142d59 198 virtual uint8_t * stringIproductDesc();
daniele 2:540f6e142d59 199
daniele 2:540f6e142d59 200 /*
daniele 2:540f6e142d59 201 * Get string serial descriptor
daniele 2:540f6e142d59 202 *
daniele 2:540f6e142d59 203 * @returns pointer to the string serial descriptor
daniele 2:540f6e142d59 204 */
daniele 2:540f6e142d59 205 virtual uint8_t * stringIserialDesc();
daniele 2:540f6e142d59 206
daniele 2:540f6e142d59 207 /*
daniele 2:540f6e142d59 208 * Get string configuration descriptor
daniele 2:540f6e142d59 209 *
daniele 2:540f6e142d59 210 * @returns pointer to the string configuration descriptor
daniele 2:540f6e142d59 211 */
daniele 2:540f6e142d59 212 virtual uint8_t * stringIConfigurationDesc();
daniele 2:540f6e142d59 213
daniele 2:540f6e142d59 214 /*
daniele 2:540f6e142d59 215 * Get string interface descriptor
daniele 2:540f6e142d59 216 *
daniele 2:540f6e142d59 217 * @returns pointer to the string interface descriptor
daniele 2:540f6e142d59 218 */
daniele 2:540f6e142d59 219 virtual uint8_t * stringIinterfaceDesc();
daniele 2:540f6e142d59 220
daniele 2:540f6e142d59 221 /*
daniele 2:540f6e142d59 222 * Get the length of the report descriptor
daniele 2:540f6e142d59 223 *
daniele 2:540f6e142d59 224 * @returns length of the report descriptor
daniele 2:540f6e142d59 225 */
daniele 2:540f6e142d59 226 virtual uint16_t reportDescLength() { return 0; };
daniele 2:540f6e142d59 227
daniele 2:540f6e142d59 228
daniele 2:540f6e142d59 229
daniele 2:540f6e142d59 230 protected:
daniele 2:540f6e142d59 231 virtual void busReset(void);
daniele 2:540f6e142d59 232 virtual void EP0setupCallback(void);
daniele 2:540f6e142d59 233 virtual void EP0out(void);
daniele 2:540f6e142d59 234 virtual void EP0in(void);
daniele 2:540f6e142d59 235 virtual void connectStateChanged(unsigned int connected);
daniele 2:540f6e142d59 236 virtual void suspendStateChanged(unsigned int suspended);
daniele 2:540f6e142d59 237 uint8_t * findDescriptor(uint8_t descriptorType);
daniele 2:540f6e142d59 238 CONTROL_TRANSFER * getTransferPtr(void);
daniele 2:540f6e142d59 239
daniele 2:540f6e142d59 240 uint16_t VENDOR_ID;
daniele 2:540f6e142d59 241 uint16_t PRODUCT_ID;
daniele 2:540f6e142d59 242 uint16_t PRODUCT_RELEASE;
daniele 2:540f6e142d59 243
daniele 2:540f6e142d59 244 private:
daniele 2:540f6e142d59 245 bool addRateFeedbackEndpoint(uint8_t endpoint, uint32_t maxPacket);
daniele 2:540f6e142d59 246 bool requestGetDescriptor(void);
daniele 2:540f6e142d59 247 bool controlOut(void);
daniele 2:540f6e142d59 248 bool controlIn(void);
daniele 2:540f6e142d59 249 bool requestSetAddress(void);
daniele 2:540f6e142d59 250 bool requestSetConfiguration(void);
daniele 2:540f6e142d59 251 bool requestSetFeature(void);
daniele 2:540f6e142d59 252 bool requestClearFeature(void);
daniele 2:540f6e142d59 253 bool requestGetStatus(void);
daniele 2:540f6e142d59 254 bool requestSetup(void);
daniele 2:540f6e142d59 255 bool controlSetup(void);
daniele 2:540f6e142d59 256 void decodeSetupPacket(uint8_t *data, SETUP_PACKET *packet);
daniele 2:540f6e142d59 257 bool requestGetConfiguration(void);
daniele 2:540f6e142d59 258 bool requestGetInterface(void);
daniele 2:540f6e142d59 259 bool requestSetInterface(void);
daniele 2:540f6e142d59 260
daniele 2:540f6e142d59 261 CONTROL_TRANSFER transfer;
daniele 2:540f6e142d59 262 USB_DEVICE device;
daniele 2:540f6e142d59 263
daniele 2:540f6e142d59 264 uint16_t currentInterface;
daniele 2:540f6e142d59 265 uint8_t currentAlternate;
daniele 2:540f6e142d59 266 };
daniele 2:540f6e142d59 267
daniele 2:540f6e142d59 268
daniele 2:540f6e142d59 269 #endif