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