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.
Fork of Smoothie by
USBSerial.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 USBSERIAL_H 00020 #define USBSERIAL_H 00021 00022 #include "USBCDC.h" 00023 // #include "Stream.h" 00024 #include "CircBuffer.h" 00025 00026 #include "Module.h" 00027 #include "StreamOutput.h" 00028 00029 class USBSerial_Receiver { 00030 protected: 00031 virtual bool SerialEvent_RX(void) = 0; 00032 }; 00033 00034 class USBSerial: public USBCDC, public USBSerial_Receiver, public Module, public StreamOutput { 00035 public: 00036 USBSerial(USB *); 00037 00038 int _putc(int c); 00039 int _getc(); 00040 int puts(const char *); 00041 00042 uint8_t available(); 00043 00044 uint16_t writeBlock(const uint8_t * buf, uint16_t size); 00045 00046 CircBuffer<uint8_t> rxbuf; 00047 CircBuffer<uint8_t> txbuf; 00048 00049 void on_module_loaded(void); 00050 void on_main_loop(void *); 00051 00052 protected: 00053 // virtual bool EpCallback(uint8_t, uint8_t); 00054 virtual bool USBEvent_EPIn(uint8_t, uint8_t); 00055 virtual bool USBEvent_EPOut(uint8_t, uint8_t); 00056 00057 virtual bool SerialEvent_RX(void){return false;}; 00058 00059 virtual void on_attach(void); 00060 virtual void on_detach(void); 00061 00062 void ensure_tx_space(int); 00063 00064 volatile bool attach; 00065 bool attached; 00066 00067 // keep track of number of newlines in the buffer 00068 // this makes it trivial to detect if there's a new line available 00069 volatile int nl_in_rx; 00070 00071 // if we receive a line that's longer than the buffer, to avoid a deadlock 00072 // we must flush the buffer. 00073 // then to avoid delivering the tail of a line to Smoothie we must keep 00074 // flushing until we find a newline. 00075 // this flag asserts when we are doing this 00076 bool flush_to_nl; 00077 private: 00078 USB *usb; 00079 // mbed::FunctionPointer rx; 00080 }; 00081 00082 #endif
Generated on Tue Jul 12 2022 20:09:03 by
1.7.2
