USB CDC (serial) and USB MSC (strage) Composite Device. http://mbed.org/users/okini3939/notebook/USB_Device/
Dependencies: ChaNFSSD mbed ChaNFS
USBDevice/USBSERIAL/USBCDC.h@2:5db90410bb90, 2011-12-23 (annotated)
- Committer:
- okini3939
- Date:
- Fri Dec 23 16:37:58 2011 +0000
- Revision:
- 2:5db90410bb90
- Parent:
- 0:9b1d17d54055
Who changed what in which revision?
User | Revision | Line number | New 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 USBCDC_H |
okini3939 | 0:9b1d17d54055 | 20 | #define USBCDC_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 "USBDevice.h" |
okini3939 | 0:9b1d17d54055 | 28 | |
okini3939 | 0:9b1d17d54055 | 29 | |
okini3939 | 0:9b1d17d54055 | 30 | |
okini3939 | 0:9b1d17d54055 | 31 | class USBCDC: public USBDevice { |
okini3939 | 0:9b1d17d54055 | 32 | public: |
okini3939 | 0:9b1d17d54055 | 33 | |
okini3939 | 0:9b1d17d54055 | 34 | /* |
okini3939 | 0:9b1d17d54055 | 35 | * Constructor |
okini3939 | 0:9b1d17d54055 | 36 | * |
okini3939 | 0:9b1d17d54055 | 37 | * @param vendor_id Your vendor_id |
okini3939 | 0:9b1d17d54055 | 38 | * @param product_id Your product_id |
okini3939 | 0:9b1d17d54055 | 39 | * @param product_release Your preoduct_release |
okini3939 | 0:9b1d17d54055 | 40 | */ |
okini3939 | 0:9b1d17d54055 | 41 | USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release); |
okini3939 | 0:9b1d17d54055 | 42 | |
okini3939 | 0:9b1d17d54055 | 43 | protected: |
okini3939 | 0:9b1d17d54055 | 44 | |
okini3939 | 0:9b1d17d54055 | 45 | /* |
okini3939 | 0:9b1d17d54055 | 46 | * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
okini3939 | 0:9b1d17d54055 | 47 | * |
okini3939 | 0:9b1d17d54055 | 48 | * @returns pointer to the device descriptor |
okini3939 | 0:9b1d17d54055 | 49 | */ |
okini3939 | 0:9b1d17d54055 | 50 | virtual uint8_t * deviceDesc(); |
okini3939 | 0:9b1d17d54055 | 51 | |
okini3939 | 0:9b1d17d54055 | 52 | /* |
okini3939 | 0:9b1d17d54055 | 53 | * Get string product descriptor |
okini3939 | 0:9b1d17d54055 | 54 | * |
okini3939 | 0:9b1d17d54055 | 55 | * @returns pointer to the string product descriptor |
okini3939 | 0:9b1d17d54055 | 56 | */ |
okini3939 | 0:9b1d17d54055 | 57 | virtual uint8_t * stringIproductDesc(); |
okini3939 | 0:9b1d17d54055 | 58 | |
okini3939 | 0:9b1d17d54055 | 59 | /* |
okini3939 | 0:9b1d17d54055 | 60 | * Get string interface descriptor |
okini3939 | 0:9b1d17d54055 | 61 | * |
okini3939 | 0:9b1d17d54055 | 62 | * @returns pointer to the string interface descriptor |
okini3939 | 0:9b1d17d54055 | 63 | */ |
okini3939 | 0:9b1d17d54055 | 64 | virtual uint8_t * stringIinterfaceDesc(); |
okini3939 | 0:9b1d17d54055 | 65 | |
okini3939 | 0:9b1d17d54055 | 66 | /* |
okini3939 | 0:9b1d17d54055 | 67 | * Get configuration descriptor |
okini3939 | 0:9b1d17d54055 | 68 | * |
okini3939 | 0:9b1d17d54055 | 69 | * @returns pointer to the configuration descriptor |
okini3939 | 0:9b1d17d54055 | 70 | */ |
okini3939 | 0:9b1d17d54055 | 71 | virtual uint8_t * configurationDesc(); |
okini3939 | 0:9b1d17d54055 | 72 | |
okini3939 | 0:9b1d17d54055 | 73 | /* |
okini3939 | 0:9b1d17d54055 | 74 | * Send a buffer |
okini3939 | 0:9b1d17d54055 | 75 | * |
okini3939 | 0:9b1d17d54055 | 76 | * @param endpoint endpoint which will be sent the buffer |
okini3939 | 0:9b1d17d54055 | 77 | * @param buffer buffer to be sent |
okini3939 | 0:9b1d17d54055 | 78 | * @param size length of the buffer |
okini3939 | 0:9b1d17d54055 | 79 | * @returns true if successful |
okini3939 | 0:9b1d17d54055 | 80 | */ |
okini3939 | 0:9b1d17d54055 | 81 | bool send(uint8_t * buffer, uint16_t size); |
okini3939 | 0:9b1d17d54055 | 82 | |
okini3939 | 0:9b1d17d54055 | 83 | /* |
okini3939 | 0:9b1d17d54055 | 84 | * Read a buffer from a certain endpoint. Warning: blocking |
okini3939 | 0:9b1d17d54055 | 85 | * |
okini3939 | 0:9b1d17d54055 | 86 | * @param endpoint endpoint to read |
okini3939 | 0:9b1d17d54055 | 87 | * @param buffer buffer where will be stored bytes |
okini3939 | 0:9b1d17d54055 | 88 | * @param size the number of bytes read will be stored in *size |
okini3939 | 0:9b1d17d54055 | 89 | * @param maxSize the maximum length that can be read |
okini3939 | 0:9b1d17d54055 | 90 | * @returns true if successful |
okini3939 | 0:9b1d17d54055 | 91 | */ |
okini3939 | 0:9b1d17d54055 | 92 | bool readEP(uint8_t * buffer, uint16_t * size); |
okini3939 | 0:9b1d17d54055 | 93 | |
okini3939 | 0:9b1d17d54055 | 94 | /* |
okini3939 | 0:9b1d17d54055 | 95 | * Read a buffer from a certain endpoint. Warning: non blocking |
okini3939 | 0:9b1d17d54055 | 96 | * |
okini3939 | 0:9b1d17d54055 | 97 | * @param endpoint endpoint to read |
okini3939 | 0:9b1d17d54055 | 98 | * @param buffer buffer where will be stored bytes |
okini3939 | 0:9b1d17d54055 | 99 | * @param size the number of bytes read will be stored in *size |
okini3939 | 0:9b1d17d54055 | 100 | * @param maxSize the maximum length that can be read |
okini3939 | 0:9b1d17d54055 | 101 | * @returns true if successful |
okini3939 | 0:9b1d17d54055 | 102 | */ |
okini3939 | 0:9b1d17d54055 | 103 | bool readEP_NB(uint8_t * buffer, uint16_t * size); |
okini3939 | 0:9b1d17d54055 | 104 | |
okini3939 | 0:9b1d17d54055 | 105 | virtual bool USBCallback_request(); |
okini3939 | 0:9b1d17d54055 | 106 | virtual bool USBCallback_setConfiguration(uint8_t configuration); |
okini3939 | 0:9b1d17d54055 | 107 | |
okini3939 | 0:9b1d17d54055 | 108 | }; |
okini3939 | 0:9b1d17d54055 | 109 | |
okini3939 | 0:9b1d17d54055 | 110 | #endif |