NetTribute library with debug turned on in FShandler Donatien Garner -> Segundo Equipo -> this version
drv/serial/usb/UsbSerial.h@0:281d6ff68967, 2010-11-19 (annotated)
- Committer:
- hexley
- Date:
- Fri Nov 19 01:54:45 2010 +0000
- Revision:
- 0:281d6ff68967
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hexley | 0:281d6ff68967 | 1 | |
hexley | 0:281d6ff68967 | 2 | /* |
hexley | 0:281d6ff68967 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
hexley | 0:281d6ff68967 | 4 | |
hexley | 0:281d6ff68967 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
hexley | 0:281d6ff68967 | 6 | of this software and associated documentation files (the "Software"), to deal |
hexley | 0:281d6ff68967 | 7 | in the Software without restriction, including without limitation the rights |
hexley | 0:281d6ff68967 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
hexley | 0:281d6ff68967 | 9 | copies of the Software, and to permit persons to whom the Software is |
hexley | 0:281d6ff68967 | 10 | furnished to do so, subject to the following conditions: |
hexley | 0:281d6ff68967 | 11 | |
hexley | 0:281d6ff68967 | 12 | The above copyright notice and this permission notice shall be included in |
hexley | 0:281d6ff68967 | 13 | all copies or substantial portions of the Software. |
hexley | 0:281d6ff68967 | 14 | |
hexley | 0:281d6ff68967 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
hexley | 0:281d6ff68967 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
hexley | 0:281d6ff68967 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
hexley | 0:281d6ff68967 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
hexley | 0:281d6ff68967 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
hexley | 0:281d6ff68967 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
hexley | 0:281d6ff68967 | 21 | THE SOFTWARE. |
hexley | 0:281d6ff68967 | 22 | */ |
hexley | 0:281d6ff68967 | 23 | |
hexley | 0:281d6ff68967 | 24 | #ifndef USB_SERIAL_H |
hexley | 0:281d6ff68967 | 25 | #define USB_SERIAL_H |
hexley | 0:281d6ff68967 | 26 | |
hexley | 0:281d6ff68967 | 27 | //DG 2010 |
hexley | 0:281d6ff68967 | 28 | //Essentially a clone of Serial if |
hexley | 0:281d6ff68967 | 29 | #include "Stream.h" |
hexley | 0:281d6ff68967 | 30 | #include "mbed.h" |
hexley | 0:281d6ff68967 | 31 | |
hexley | 0:281d6ff68967 | 32 | #include "drv/usb/UsbDevice.h" |
hexley | 0:281d6ff68967 | 33 | #include "drv/usb/UsbEndpoint.h" |
hexley | 0:281d6ff68967 | 34 | |
hexley | 0:281d6ff68967 | 35 | namespace mbed { |
hexley | 0:281d6ff68967 | 36 | |
hexley | 0:281d6ff68967 | 37 | class UsbSerial : public Stream { |
hexley | 0:281d6ff68967 | 38 | |
hexley | 0:281d6ff68967 | 39 | public: |
hexley | 0:281d6ff68967 | 40 | |
hexley | 0:281d6ff68967 | 41 | UsbSerial(UsbDevice* pDevice, int epIn, int epOut, const char* name = NULL); |
hexley | 0:281d6ff68967 | 42 | virtual ~UsbSerial(); |
hexley | 0:281d6ff68967 | 43 | //Apart from the ctor/dtor, exactly the same protos as Serial |
hexley | 0:281d6ff68967 | 44 | |
hexley | 0:281d6ff68967 | 45 | void baud(int baudrate); |
hexley | 0:281d6ff68967 | 46 | |
hexley | 0:281d6ff68967 | 47 | enum Parity { |
hexley | 0:281d6ff68967 | 48 | None = 0, |
hexley | 0:281d6ff68967 | 49 | Odd = 1, |
hexley | 0:281d6ff68967 | 50 | Even = 2, |
hexley | 0:281d6ff68967 | 51 | Forced1 = 3, |
hexley | 0:281d6ff68967 | 52 | Forced0 = 4 |
hexley | 0:281d6ff68967 | 53 | }; |
hexley | 0:281d6ff68967 | 54 | |
hexley | 0:281d6ff68967 | 55 | enum IrqType { |
hexley | 0:281d6ff68967 | 56 | RxIrq = 0 |
hexley | 0:281d6ff68967 | 57 | , TxIrq |
hexley | 0:281d6ff68967 | 58 | }; |
hexley | 0:281d6ff68967 | 59 | |
hexley | 0:281d6ff68967 | 60 | void format(int bits, int parity, int stop); |
hexley | 0:281d6ff68967 | 61 | |
hexley | 0:281d6ff68967 | 62 | class CDummy; |
hexley | 0:281d6ff68967 | 63 | template <class T> |
hexley | 0:281d6ff68967 | 64 | void attach(T* pCbItem, void (T::*pCbMeth)(), IrqType type = RxIrq) |
hexley | 0:281d6ff68967 | 65 | { |
hexley | 0:281d6ff68967 | 66 | if(type == RxIrq) |
hexley | 0:281d6ff68967 | 67 | { |
hexley | 0:281d6ff68967 | 68 | m_pInCbItem = (CDummy*) pCbItem; |
hexley | 0:281d6ff68967 | 69 | m_pInCbMeth = (void (CDummy::*)()) pCbMeth; |
hexley | 0:281d6ff68967 | 70 | } |
hexley | 0:281d6ff68967 | 71 | else |
hexley | 0:281d6ff68967 | 72 | { |
hexley | 0:281d6ff68967 | 73 | m_pOutCbItem = (CDummy*) pCbItem; |
hexley | 0:281d6ff68967 | 74 | m_pOutCbMeth = (void (CDummy::*)()) pCbMeth; |
hexley | 0:281d6ff68967 | 75 | } |
hexley | 0:281d6ff68967 | 76 | } |
hexley | 0:281d6ff68967 | 77 | |
hexley | 0:281d6ff68967 | 78 | #if 0 // Inhereted from Stream, for documentation only |
hexley | 0:281d6ff68967 | 79 | |
hexley | 0:281d6ff68967 | 80 | /* Function: putc |
hexley | 0:281d6ff68967 | 81 | * Write a character |
hexley | 0:281d6ff68967 | 82 | * |
hexley | 0:281d6ff68967 | 83 | * Variables: |
hexley | 0:281d6ff68967 | 84 | * c - The character to write to the serial port |
hexley | 0:281d6ff68967 | 85 | */ |
hexley | 0:281d6ff68967 | 86 | int putc(int c); |
hexley | 0:281d6ff68967 | 87 | |
hexley | 0:281d6ff68967 | 88 | /* Function: getc |
hexley | 0:281d6ff68967 | 89 | * Read a character |
hexley | 0:281d6ff68967 | 90 | * |
hexley | 0:281d6ff68967 | 91 | * Variables: |
hexley | 0:281d6ff68967 | 92 | * returns - The character read from the serial port |
hexley | 0:281d6ff68967 | 93 | */ |
hexley | 0:281d6ff68967 | 94 | int getc(); |
hexley | 0:281d6ff68967 | 95 | |
hexley | 0:281d6ff68967 | 96 | /* Function: printf |
hexley | 0:281d6ff68967 | 97 | * Write a formated string |
hexley | 0:281d6ff68967 | 98 | * |
hexley | 0:281d6ff68967 | 99 | * Variables: |
hexley | 0:281d6ff68967 | 100 | * format - A printf-style format string, followed by the |
hexley | 0:281d6ff68967 | 101 | * variables to use in formating the string. |
hexley | 0:281d6ff68967 | 102 | */ |
hexley | 0:281d6ff68967 | 103 | int printf(const char* format, ...); |
hexley | 0:281d6ff68967 | 104 | |
hexley | 0:281d6ff68967 | 105 | /* Function: scanf |
hexley | 0:281d6ff68967 | 106 | * Read a formated string |
hexley | 0:281d6ff68967 | 107 | * |
hexley | 0:281d6ff68967 | 108 | * Variables: |
hexley | 0:281d6ff68967 | 109 | * format - A scanf-style format string, |
hexley | 0:281d6ff68967 | 110 | * followed by the pointers to variables to store the results. |
hexley | 0:281d6ff68967 | 111 | */ |
hexley | 0:281d6ff68967 | 112 | int scanf(const char* format, ...); |
hexley | 0:281d6ff68967 | 113 | |
hexley | 0:281d6ff68967 | 114 | #endif |
hexley | 0:281d6ff68967 | 115 | |
hexley | 0:281d6ff68967 | 116 | /* Function: readable |
hexley | 0:281d6ff68967 | 117 | * Determine if there is a character available to read |
hexley | 0:281d6ff68967 | 118 | * |
hexley | 0:281d6ff68967 | 119 | * Variables: |
hexley | 0:281d6ff68967 | 120 | * returns - 1 if there is a character available to read, else 0 |
hexley | 0:281d6ff68967 | 121 | */ |
hexley | 0:281d6ff68967 | 122 | int readable(); |
hexley | 0:281d6ff68967 | 123 | |
hexley | 0:281d6ff68967 | 124 | /* Function: writeable |
hexley | 0:281d6ff68967 | 125 | * Determine if there is space available to write a character |
hexley | 0:281d6ff68967 | 126 | * |
hexley | 0:281d6ff68967 | 127 | * Variables: |
hexley | 0:281d6ff68967 | 128 | * returns - 1 if there is space to write a character, else 0 |
hexley | 0:281d6ff68967 | 129 | */ |
hexley | 0:281d6ff68967 | 130 | int writeable(); |
hexley | 0:281d6ff68967 | 131 | |
hexley | 0:281d6ff68967 | 132 | #ifdef MBED_RPC |
hexley | 0:281d6ff68967 | 133 | virtual const struct rpc_method *get_rpc_methods(); |
hexley | 0:281d6ff68967 | 134 | static struct rpc_class *get_rpc_class(); |
hexley | 0:281d6ff68967 | 135 | #endif |
hexley | 0:281d6ff68967 | 136 | |
hexley | 0:281d6ff68967 | 137 | protected: |
hexley | 0:281d6ff68967 | 138 | |
hexley | 0:281d6ff68967 | 139 | virtual int _getc(); |
hexley | 0:281d6ff68967 | 140 | virtual int _putc(int c); |
hexley | 0:281d6ff68967 | 141 | |
hexley | 0:281d6ff68967 | 142 | void onReadable(); |
hexley | 0:281d6ff68967 | 143 | void onWriteable(); |
hexley | 0:281d6ff68967 | 144 | |
hexley | 0:281d6ff68967 | 145 | void onEpInTransfer(); |
hexley | 0:281d6ff68967 | 146 | void onEpOutTransfer(); |
hexley | 0:281d6ff68967 | 147 | |
hexley | 0:281d6ff68967 | 148 | private: |
hexley | 0:281d6ff68967 | 149 | |
hexley | 0:281d6ff68967 | 150 | UsbEndpoint m_epIn; |
hexley | 0:281d6ff68967 | 151 | UsbEndpoint m_epOut; |
hexley | 0:281d6ff68967 | 152 | |
hexley | 0:281d6ff68967 | 153 | CDummy* m_pInCbItem; |
hexley | 0:281d6ff68967 | 154 | void (CDummy::*m_pInCbMeth)(); |
hexley | 0:281d6ff68967 | 155 | |
hexley | 0:281d6ff68967 | 156 | CDummy* m_pOutCbItem; |
hexley | 0:281d6ff68967 | 157 | void (CDummy::*m_pOutCbMeth)(); |
hexley | 0:281d6ff68967 | 158 | |
hexley | 0:281d6ff68967 | 159 | void startTx(); |
hexley | 0:281d6ff68967 | 160 | void startRx(); |
hexley | 0:281d6ff68967 | 161 | |
hexley | 0:281d6ff68967 | 162 | Timeout m_txTimeout; |
hexley | 0:281d6ff68967 | 163 | volatile bool m_timeout; |
hexley | 0:281d6ff68967 | 164 | |
hexley | 0:281d6ff68967 | 165 | volatile char* m_inBufEven; |
hexley | 0:281d6ff68967 | 166 | volatile char* m_inBufOdd; |
hexley | 0:281d6ff68967 | 167 | volatile char* m_inBufUsr; |
hexley | 0:281d6ff68967 | 168 | volatile char* m_inBufTrmt; |
hexley | 0:281d6ff68967 | 169 | |
hexley | 0:281d6ff68967 | 170 | volatile char* m_outBufEven; |
hexley | 0:281d6ff68967 | 171 | volatile char* m_outBufOdd; |
hexley | 0:281d6ff68967 | 172 | volatile char* m_outBufUsr; |
hexley | 0:281d6ff68967 | 173 | volatile char* m_outBufTrmt; |
hexley | 0:281d6ff68967 | 174 | |
hexley | 0:281d6ff68967 | 175 | volatile int m_inBufLen; |
hexley | 0:281d6ff68967 | 176 | volatile int m_outBufLen; |
hexley | 0:281d6ff68967 | 177 | |
hexley | 0:281d6ff68967 | 178 | volatile char* m_pInBufPos; |
hexley | 0:281d6ff68967 | 179 | volatile char* m_pOutBufPos; |
hexley | 0:281d6ff68967 | 180 | |
hexley | 0:281d6ff68967 | 181 | |
hexley | 0:281d6ff68967 | 182 | |
hexley | 0:281d6ff68967 | 183 | }; |
hexley | 0:281d6ff68967 | 184 | |
hexley | 0:281d6ff68967 | 185 | } |
hexley | 0:281d6ff68967 | 186 | |
hexley | 0:281d6ff68967 | 187 | |
hexley | 0:281d6ff68967 | 188 | |
hexley | 0:281d6ff68967 | 189 | #endif |