Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
USBCDC.h
00001 /* Copyright (c) 2010-2011 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #ifndef USBCDC_H 00020 #define USBCDC_H 00021 00022 /* These headers are included for child class. */ 00023 #include "USBEndpoints.h" 00024 #include "USBDescriptor.h" 00025 #include "USBDevice_Types.h" 00026 00027 #include "USBDevice.h" 00028 00029 class USBCDC: public USBDevice { 00030 public: 00031 00032 /* 00033 * Constructor 00034 * 00035 * @param vendor_id Your vendor_id 00036 * @param product_id Your product_id 00037 * @param product_release Your preoduct_release 00038 * @param connect_blocking define if the connection must be blocked if USB not plugged in 00039 */ 00040 USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking); 00041 00042 protected: 00043 00044 /* 00045 * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength. 00046 * 00047 * @returns pointer to the device descriptor 00048 */ 00049 virtual const uint8_t * deviceDesc(); 00050 00051 /* 00052 * Get string product descriptor 00053 * 00054 * @returns pointer to the string product descriptor 00055 */ 00056 virtual const uint8_t * stringIproductDesc(); 00057 00058 /* 00059 * Get string interface descriptor 00060 * 00061 * @returns pointer to the string interface descriptor 00062 */ 00063 virtual const uint8_t * stringIinterfaceDesc(); 00064 00065 /* 00066 * Get configuration descriptor 00067 * 00068 * @returns pointer to the configuration descriptor 00069 */ 00070 virtual const uint8_t * configurationDesc(); 00071 00072 /* 00073 * Send a buffer. Warning: blocking 00074 * 00075 * @param endpoint endpoint which will be sent the buffer 00076 * @param buffer buffer to be sent 00077 * @param size length of the buffer 00078 * @returns true if successful 00079 */ 00080 bool send(uint8_t * buffer, uint32_t size); 00081 00082 /* 00083 * Send a buffer. Warning: non blocking 00084 * 00085 * @param endpoint endpoint which will be sent the buffer 00086 * @param buffer buffer to be sent 00087 * @param size length of the buffer 00088 * @returns true if successful 00089 */ 00090 bool send_NB(uint8_t * buffer, uint32_t size); 00091 00092 /* 00093 * Read a buffer from a certain endpoint. Warning: blocking 00094 * 00095 * @param endpoint endpoint to read 00096 * @param buffer buffer where will be stored bytes 00097 * @param size the number of bytes read will be stored in *size 00098 * @param maxSize the maximum length that can be read 00099 * @returns true if successful 00100 */ 00101 bool readEP(uint8_t * buffer, uint32_t * size); 00102 00103 /* 00104 * Read a buffer from a certain endpoint. Warning: non blocking 00105 * 00106 * @param endpoint endpoint to read 00107 * @param buffer buffer where will be stored bytes 00108 * @param size the number of bytes read will be stored in *size 00109 * @param maxSize the maximum length that can be read 00110 * @returns true if successful 00111 */ 00112 bool readEP_NB(uint8_t * buffer, uint32_t * size); 00113 00114 /* 00115 * Called by USBCallback_requestCompleted when CDC line coding is changed 00116 * Warning: Called in ISR 00117 * 00118 * @param baud The baud rate 00119 * @param bits The number of bits in a word (5-8) 00120 * @param parity The parity 00121 * @param stop The number of stop bits (1 or 2) 00122 */ 00123 virtual void lineCodingChanged(int baud, int bits, int parity, int stop) {}; 00124 00125 protected: 00126 virtual bool USBCallback_request(); 00127 virtual void USBCallback_requestCompleted(uint8_t *buf, uint32_t length); 00128 virtual bool USBCallback_setConfiguration(uint8_t configuration); 00129 virtual void USBCallback_busReset(void); 00130 volatile bool terminal_connected; 00131 00132 }; 00133 00134 #endif
Generated on Tue Jul 12 2022 12:46:10 by
1.7.2