USB composite device example program, drag-and-drop flash writer.
Dependencies: SWD USBDevice mbed BaseDAP
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 /* These headers are included for child class. */ 00022 #include "USBEndpoints.h" 00023 #include "USBDescriptor.h" 00024 #include "USBDevice_Types.h" 00025 00026 #include "USBDevice.h" 00027 #include "CircBuffer.h" 00028 00029 #define CDC_EPINT_IN EP1IN 00030 #define CDC_EPBULK_IN EP5IN 00031 #define CDC_EPBULK_OUT EP5OUT 00032 00033 class USB_CDC { 00034 public: 00035 USB_CDC(USBDevice* device); 00036 00037 /** target to virtual COM 00038 */ 00039 void putc(int c); 00040 00041 /** virtial COM to target 00042 */ 00043 int getc(); 00044 00045 int readable(); 00046 00047 int writeable(); 00048 00049 void baud_callback(int baudrate); 00050 void send_break_callback(uint16_t duration); 00051 void control_line_callback(int rts, int dtr); 00052 00053 /* 00054 * Send a buffer 00055 * 00056 * @param endpoint endpoint which will be sent the buffer 00057 * @param buffer buffer to be sent 00058 * @param size length of the buffer 00059 * @returns true if successful 00060 */ 00061 bool send(uint8_t * buffer, uint32_t size); 00062 00063 /* 00064 * Read a buffer from a certain endpoint. Warning: blocking 00065 * 00066 * @param endpoint endpoint to read 00067 * @param buffer buffer where will be stored bytes 00068 * @param size the number of bytes read will be stored in *size 00069 * @param maxSize the maximum length that can be read 00070 * @returns true if successful 00071 */ 00072 bool readEP(uint8_t * buffer, uint32_t * size); 00073 00074 /* 00075 * Read a buffer from a certain endpoint. Warning: non blocking 00076 * 00077 * @param endpoint endpoint to read 00078 * @param buffer buffer where will be stored bytes 00079 * @param size the number of bytes read will be stored in *size 00080 * @param maxSize the maximum length that can be read 00081 * @returns true if successful 00082 */ 00083 bool readEP_NB(uint8_t * buffer, uint32_t * size); 00084 00085 bool Request_callback(CONTROL_TRANSFER* transfer); 00086 bool RequestCompleted_callback(CONTROL_TRANSFER* transfer, uint8_t* buf, int length); 00087 bool EPBULK_OUT_callback(); 00088 00089 protected: 00090 USBDevice* _device; 00091 CircBuffer<uint8_t> _rx_buf; 00092 volatile bool terminal_connected; 00093 };
Generated on Wed Jul 13 2022 08:08:25 by 1.7.2