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.
Dependents: KL46Z-lpc81isp lpcterm2
USB_CDC.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 #pragma once 00020 00021 #include "USBDevice.h" 00022 #include "CircBuffer.h" 00023 00024 #if defined(TARGET_LPC1768)||defined(TARGET_LPC4088) 00025 #define CDC_EPINT_IN EP1IN 00026 #define CDC_EPBULK_IN EP5IN 00027 #define CDC_EPBULK_OUT EP5OUT 00028 #elif defined(TARGET_LPC1347)||defined(TARGET_LPC11U24)||defined(TARGET_LPC11U35_401)||defined(TARGET_LPC11U35_501)||defined(TARGET_LPC1549)||defined(TARGET_LPC11U68) 00029 #define CDC_EPINT_IN EP1IN 00030 #define CDC_EPBULK_IN EP3IN 00031 #define CDC_EPBULK_OUT EP3OUT 00032 #elif defined(TARGET_KL25Z)||defined(TARGET_KL46Z) 00033 #define CDC_EPINT_IN EP1IN 00034 #define CDC_EPBULK_IN EP5IN 00035 #define CDC_EPBULK_OUT EP5OUT 00036 #else 00037 #error "target type error" 00038 #endif 00039 00040 class USB_CDC { 00041 public: 00042 USB_CDC(USBDevice* device); 00043 00044 /** target to virtual COM 00045 */ 00046 void putc(int c); 00047 00048 /** virtial COM to target 00049 */ 00050 int getc(); 00051 00052 int readable(); 00053 00054 int writeable(); 00055 00056 /* 00057 * Send a buffer 00058 * 00059 * @param endpoint endpoint which will be sent the buffer 00060 * @param buffer buffer to be sent 00061 * @param size length of the buffer 00062 * @returns true if successful 00063 */ 00064 bool send(uint8_t * buffer, uint32_t size); 00065 00066 /* 00067 * Read a buffer from a certain endpoint. Warning: blocking 00068 * 00069 * @param endpoint endpoint to read 00070 * @param buffer buffer where will be stored bytes 00071 * @param size the number of bytes read will be stored in *size 00072 * @param maxSize the maximum length that can be read 00073 * @returns true if successful 00074 */ 00075 bool readEP(uint8_t * buffer, uint32_t * size); 00076 00077 /* 00078 * Read a buffer from a certain endpoint. Warning: non blocking 00079 * 00080 * @param endpoint endpoint to read 00081 * @param buffer buffer where will be stored bytes 00082 * @param size the number of bytes read will be stored in *size 00083 * @param maxSize the maximum length that can be read 00084 * @returns true if successful 00085 */ 00086 bool readEP_NB(uint8_t * buffer, uint32_t * size); 00087 00088 bool Request_callback(CONTROL_TRANSFER* transfer); 00089 bool RequestCompleted_callback(CONTROL_TRANSFER* transfer, uint8_t* buf, int length); 00090 bool EPBULK_OUT_callback(); 00091 00092 /** 00093 * Attach a callback to call when serial's settings are changed. 00094 * 00095 * @param fptr function pointer 00096 */ 00097 void attach(void (*fptr)(int baud, int bits, int parity, int stop)) { 00098 settingsChangedCallback = fptr; 00099 } 00100 00101 void attachControlLineStateChanged(void (*fptr)(int rts, int dtr)) { 00102 controlLineStateChangedCallback = fptr; 00103 } 00104 00105 void attachSendBreak(void (*fptr)(uint16_t duration)) { 00106 sendBreakCallback = fptr; 00107 } 00108 00109 protected: 00110 void lineCodingChanged(int baud, int bits, int parity, int stop); 00111 void controlLineStateChanged(int rts, int dtr); 00112 void sendBreak(uint16_t duration); 00113 00114 private: 00115 USBDevice* _device; 00116 CircBuffer<uint8_t> _rx_buf; 00117 void (*settingsChangedCallback)(int baud, int bits, int parity, int stop); 00118 void (*controlLineStateChangedCallback)(int rts, int dtr); 00119 void (*sendBreakCallback)(uint16_t duration); 00120 volatile bool terminal_connected; 00121 }; 00122
Generated on Tue Jul 12 2022 19:39:32 by
1.7.2