mbed-os
Fork of mbed-os by
features/unsupported/USBDevice/USBSerial/USBCDC.h@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
elessair | 0:f269e3021894 | 2 | * |
elessair | 0:f269e3021894 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
elessair | 0:f269e3021894 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
elessair | 0:f269e3021894 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
elessair | 0:f269e3021894 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
elessair | 0:f269e3021894 | 7 | * Software is furnished to do so, subject to the following conditions: |
elessair | 0:f269e3021894 | 8 | * |
elessair | 0:f269e3021894 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
elessair | 0:f269e3021894 | 10 | * substantial portions of the Software. |
elessair | 0:f269e3021894 | 11 | * |
elessair | 0:f269e3021894 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
elessair | 0:f269e3021894 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
elessair | 0:f269e3021894 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
elessair | 0:f269e3021894 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
elessair | 0:f269e3021894 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
elessair | 0:f269e3021894 | 17 | */ |
elessair | 0:f269e3021894 | 18 | |
elessair | 0:f269e3021894 | 19 | #ifndef USBCDC_H |
elessair | 0:f269e3021894 | 20 | #define USBCDC_H |
elessair | 0:f269e3021894 | 21 | |
elessair | 0:f269e3021894 | 22 | /* These headers are included for child class. */ |
elessair | 0:f269e3021894 | 23 | #include "USBEndpoints.h" |
elessair | 0:f269e3021894 | 24 | #include "USBDescriptor.h" |
elessair | 0:f269e3021894 | 25 | #include "USBDevice_Types.h" |
elessair | 0:f269e3021894 | 26 | |
elessair | 0:f269e3021894 | 27 | #include "USBDevice.h" |
elessair | 0:f269e3021894 | 28 | |
elessair | 0:f269e3021894 | 29 | class USBCDC: public USBDevice { |
elessair | 0:f269e3021894 | 30 | public: |
elessair | 0:f269e3021894 | 31 | |
elessair | 0:f269e3021894 | 32 | /* |
elessair | 0:f269e3021894 | 33 | * Constructor |
elessair | 0:f269e3021894 | 34 | * |
elessair | 0:f269e3021894 | 35 | * @param vendor_id Your vendor_id |
elessair | 0:f269e3021894 | 36 | * @param product_id Your product_id |
elessair | 0:f269e3021894 | 37 | * @param product_release Your preoduct_release |
elessair | 0:f269e3021894 | 38 | * @param connect_blocking define if the connection must be blocked if USB not plugged in |
elessair | 0:f269e3021894 | 39 | */ |
elessair | 0:f269e3021894 | 40 | USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking); |
elessair | 0:f269e3021894 | 41 | |
elessair | 0:f269e3021894 | 42 | protected: |
elessair | 0:f269e3021894 | 43 | |
elessair | 0:f269e3021894 | 44 | /* |
elessair | 0:f269e3021894 | 45 | * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
elessair | 0:f269e3021894 | 46 | * |
elessair | 0:f269e3021894 | 47 | * @returns pointer to the device descriptor |
elessair | 0:f269e3021894 | 48 | */ |
elessair | 0:f269e3021894 | 49 | virtual uint8_t * deviceDesc(); |
elessair | 0:f269e3021894 | 50 | |
elessair | 0:f269e3021894 | 51 | /* |
elessair | 0:f269e3021894 | 52 | * Get string product descriptor |
elessair | 0:f269e3021894 | 53 | * |
elessair | 0:f269e3021894 | 54 | * @returns pointer to the string product descriptor |
elessair | 0:f269e3021894 | 55 | */ |
elessair | 0:f269e3021894 | 56 | virtual uint8_t * stringIproductDesc(); |
elessair | 0:f269e3021894 | 57 | |
elessair | 0:f269e3021894 | 58 | /* |
elessair | 0:f269e3021894 | 59 | * Get string interface descriptor |
elessair | 0:f269e3021894 | 60 | * |
elessair | 0:f269e3021894 | 61 | * @returns pointer to the string interface descriptor |
elessair | 0:f269e3021894 | 62 | */ |
elessair | 0:f269e3021894 | 63 | virtual uint8_t * stringIinterfaceDesc(); |
elessair | 0:f269e3021894 | 64 | |
elessair | 0:f269e3021894 | 65 | /* |
elessair | 0:f269e3021894 | 66 | * Get configuration descriptor |
elessair | 0:f269e3021894 | 67 | * |
elessair | 0:f269e3021894 | 68 | * @returns pointer to the configuration descriptor |
elessair | 0:f269e3021894 | 69 | */ |
elessair | 0:f269e3021894 | 70 | virtual uint8_t * configurationDesc(); |
elessair | 0:f269e3021894 | 71 | |
elessair | 0:f269e3021894 | 72 | /* |
elessair | 0:f269e3021894 | 73 | * Send a buffer |
elessair | 0:f269e3021894 | 74 | * |
elessair | 0:f269e3021894 | 75 | * @param endpoint endpoint which will be sent the buffer |
elessair | 0:f269e3021894 | 76 | * @param buffer buffer to be sent |
elessair | 0:f269e3021894 | 77 | * @param size length of the buffer |
elessair | 0:f269e3021894 | 78 | * @returns true if successful |
elessair | 0:f269e3021894 | 79 | */ |
elessair | 0:f269e3021894 | 80 | bool send(uint8_t * buffer, uint32_t size); |
elessair | 0:f269e3021894 | 81 | |
elessair | 0:f269e3021894 | 82 | /* |
elessair | 0:f269e3021894 | 83 | * Read a buffer from a certain endpoint. Warning: blocking |
elessair | 0:f269e3021894 | 84 | * |
elessair | 0:f269e3021894 | 85 | * @param endpoint endpoint to read |
elessair | 0:f269e3021894 | 86 | * @param buffer buffer where will be stored bytes |
elessair | 0:f269e3021894 | 87 | * @param size the number of bytes read will be stored in *size |
elessair | 0:f269e3021894 | 88 | * @param maxSize the maximum length that can be read |
elessair | 0:f269e3021894 | 89 | * @returns true if successful |
elessair | 0:f269e3021894 | 90 | */ |
elessair | 0:f269e3021894 | 91 | bool readEP(uint8_t * buffer, uint32_t * size); |
elessair | 0:f269e3021894 | 92 | |
elessair | 0:f269e3021894 | 93 | /* |
elessair | 0:f269e3021894 | 94 | * Read a buffer from a certain endpoint. Warning: non blocking |
elessair | 0:f269e3021894 | 95 | * |
elessair | 0:f269e3021894 | 96 | * @param endpoint endpoint to read |
elessair | 0:f269e3021894 | 97 | * @param buffer buffer where will be stored bytes |
elessair | 0:f269e3021894 | 98 | * @param size the number of bytes read will be stored in *size |
elessair | 0:f269e3021894 | 99 | * @param maxSize the maximum length that can be read |
elessair | 0:f269e3021894 | 100 | * @returns true if successful |
elessair | 0:f269e3021894 | 101 | */ |
elessair | 0:f269e3021894 | 102 | bool readEP_NB(uint8_t * buffer, uint32_t * size); |
elessair | 0:f269e3021894 | 103 | |
elessair | 0:f269e3021894 | 104 | /* |
elessair | 0:f269e3021894 | 105 | * Called by USBCallback_requestCompleted when CDC line coding is changed |
elessair | 0:f269e3021894 | 106 | * Warning: Called in ISR |
elessair | 0:f269e3021894 | 107 | * |
elessair | 0:f269e3021894 | 108 | * @param baud The baud rate |
elessair | 0:f269e3021894 | 109 | * @param bits The number of bits in a word (5-8) |
elessair | 0:f269e3021894 | 110 | * @param parity The parity |
elessair | 0:f269e3021894 | 111 | * @param stop The number of stop bits (1 or 2) |
elessair | 0:f269e3021894 | 112 | */ |
elessair | 0:f269e3021894 | 113 | virtual void lineCodingChanged(int baud, int bits, int parity, int stop) {}; |
elessair | 0:f269e3021894 | 114 | |
elessair | 0:f269e3021894 | 115 | protected: |
elessair | 0:f269e3021894 | 116 | virtual bool USBCallback_request(); |
elessair | 0:f269e3021894 | 117 | virtual void USBCallback_requestCompleted(uint8_t *buf, uint32_t length); |
elessair | 0:f269e3021894 | 118 | virtual bool USBCallback_setConfiguration(uint8_t configuration); |
elessair | 0:f269e3021894 | 119 | volatile bool terminal_connected; |
elessair | 0:f269e3021894 | 120 | |
elessair | 0:f269e3021894 | 121 | }; |
elessair | 0:f269e3021894 | 122 | |
elessair | 0:f269e3021894 | 123 | #endif |