Bonjour/Zerconf library

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UsbSerial.h Source File

UsbSerial.h

00001 
00002 /*
00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 
00024 #ifndef USB_SERIAL_H
00025 #define USB_SERIAL_H
00026 
00027 //DG 2010
00028 //Essentially a clone of Serial if
00029 #include "Stream.h"
00030 #include "mbed.h"
00031 
00032 namespace mbed {
00033 
00034 class UsbSerial : public Stream {
00035 
00036 public:
00037 
00038     UsbSerial(int usbDev, int usbIf, const char *name = NULL);
00039     virtual ~UsbSerial();
00040     //Apart from the ctor/dtor, exactly the same protos as Serial
00041 
00042 
00043     void baud(int baudrate);
00044 
00045     enum Parity {
00046         None = 0,
00047         Odd = 1,
00048         Even = 2,
00049         Forced1 = 3,
00050         Forced0 = 4
00051     };
00052 
00053     void format(int bits, int parity, int stop); 
00054 
00055     
00056 #if 0 // Inhereted from Stream, for documentation only
00057 
00058     /* Function: putc
00059      *  Write a character
00060      *
00061      * Variables:
00062      *  c - The character to write to the serial port
00063      */
00064     int putc(int c);
00065 
00066     /* Function: getc
00067      *  Read a character
00068      *
00069      * Variables:
00070      *  returns - The character read from the serial port
00071      */
00072     int getc();
00073         
00074     /* Function: printf
00075      *  Write a formated string
00076      *
00077      * Variables:
00078      *  format - A printf-style format string, followed by the 
00079      *      variables to use in formating the string.
00080      */
00081     int printf(const char* format, ...);
00082 
00083     /* Function: scanf
00084      *  Read a formated string 
00085      *
00086      * Variables:
00087      *  format - A scanf-style format string,
00088      *      followed by the pointers to variables to store the results. 
00089      */
00090     int scanf(const char* format, ...);
00091          
00092 #endif
00093                
00094     /* Function: readable
00095      *  Determine if there is a character available to read
00096      *
00097      * Variables:
00098      *  returns - 1 if there is a character available to read, else 0
00099      */
00100     int readable();
00101 
00102     /* Function: writeable
00103      *  Determine if there is space available to write a character
00104      * 
00105      * Variables:
00106      *  returns - 1 if there is space to write a character, else 0
00107      */
00108     int writeable();    
00109 
00110     virtual const struct rpc_method *get_rpc_methods();
00111     static struct rpc_class *get_rpc_class();
00112     
00113 protected:
00114 
00115     virtual int _getc();    
00116     virtual int _putc(int c);
00117     
00118 private:
00119 
00120     void startTx();
00121     void startRx();
00122     
00123     Timeout m_txTimeout;
00124 
00125     volatile char* m_inBufEven;    
00126     volatile char* m_inBufOdd;
00127     volatile char* m_inBufUsr;
00128     volatile char* m_inBufTrmt;
00129     
00130     volatile char* m_outBufEven;
00131     volatile char* m_outBufOdd;
00132     volatile char* m_outBufUsr;
00133     volatile char* m_outBufTrmt;
00134     
00135     volatile int m_inBufLen;
00136     volatile int m_outBufLen;
00137     
00138     volatile char* m_pInBufPos;
00139     volatile char* m_pOutBufPos;
00140     
00141     
00142     
00143 };
00144 
00145 }
00146 
00147 
00148 
00149 #endif