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