Mac addr added ICRS

Dependencies:   mbed

Fork of Email2Screen by Oliver Mattos

Committer:
Hello1024
Date:
Mon Nov 21 18:25:34 2011 +0000
Revision:
0:1619a6b826d7

        

Who changed what in which revision?

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