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: ton_demo ton_template
USBTon.h
00001 #ifndef USBTON_H 00002 #define USBTON_H 00003 00004 #include "Stream.h" 00005 #include "usb_user.h" 00006 #include "USBCDC.h" 00007 00008 /** 00009 * USBTon example 00010 * 00011 * @code 00012 * #include "mbed.h" 00013 * #include "USBTon.h" 00014 * 00015 * //Virtual serial port over USB 00016 * USBTon usb; 00017 * 00018 * int main(void) { 00019 * 00020 * while(1) 00021 * { 00022 * usb.printf("I am a virtual serial port\n"); 00023 * wait(1); 00024 * } 00025 * } 00026 * @endcode 00027 */ 00028 class USBTon: public Stream { 00029 public: 00030 00031 /** 00032 * Constructor 00033 * 00034 * @param vendor_id Your vendor_id (default: 0x1f00) 00035 * @param product_id Your product_id (default: 0x2012) 00036 * @param product_release Your preoduct_release (default: 0x0001) 00037 * @param connect_blocking define if the connection must be blocked if USB not plugged in 00038 * 00039 */ 00040 USBTon(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001, bool connect_blocking = true) { 00041 00042 }; 00043 00044 00045 /** 00046 * Send a character. You can use puts, printf. 00047 * 00048 * @param c character to be sent 00049 * @returns true if there is no error, false otherwise 00050 */ 00051 virtual int _putc(int c); 00052 00053 /** 00054 * Read a character: blocking 00055 * 00056 * @returns character read 00057 */ 00058 virtual int _getc(); 00059 00060 /** 00061 * Check the number of bytes available. 00062 * 00063 * @returns the number of bytes available 00064 */ 00065 uint8_t available(); 00066 00067 /** Determine if there is a character available to read 00068 * 00069 * @returns 00070 * 1 if there is a character available to read, 00071 * 0 otherwise 00072 */ 00073 int readable() { return available() ? 1 : 0; } 00074 00075 /** Determine if there is space available to write a character 00076 * 00077 * @returns 00078 * 1 if there is space to write a character, 00079 * 0 otherwise 00080 */ 00081 int writeable() { return 1; } // always return 1, for write operation is blocking 00082 00083 }; 00084 00085 #endif
Generated on Tue Jul 12 2022 20:52:33 by
1.7.2