MTS_SPI_Slave unfinished
Fork of MTS-Serial by
MTSSerial.h@9:5b67a660292a, 2014-08-11 (annotated)
- Committer:
- Vanger
- Date:
- Mon Aug 11 15:44:14 2014 +0000
- Revision:
- 9:5b67a660292a
- Parent:
- 4:d348d001283b
- Child:
- 12:e12b79a4ab4f
Changed Serial serial; to RawSerial serial; in MTSSerial.h for performance fix.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 0:6585b7c8cd41 | 1 | #ifndef MTSSERIAL_H |
mfiore | 0:6585b7c8cd41 | 2 | #define MTSSERIAL_H |
mfiore | 0:6585b7c8cd41 | 3 | |
Mike Fiore |
1:d34b566d6f47 | 4 | #include "MTSBufferedIO.h" |
Mike Fiore |
1:d34b566d6f47 | 5 | |
Mike Fiore |
1:d34b566d6f47 | 6 | namespace mts |
Mike Fiore |
1:d34b566d6f47 | 7 | { |
Mike Fiore |
1:d34b566d6f47 | 8 | |
Mike Fiore |
1:d34b566d6f47 | 9 | /** This class derives from MTSBufferedIO and provides a buffered wrapper to the |
Mike Fiore |
1:d34b566d6f47 | 10 | * standard mbed Serial class. Since it depends only on the mbed Serial class for |
Mike Fiore |
1:d34b566d6f47 | 11 | * accessing serial data, this class is inherently portable accross different mbed |
Mike Fiore |
1:d34b566d6f47 | 12 | * platforms. |
Mike Fiore |
1:d34b566d6f47 | 13 | */ |
Mike Fiore |
1:d34b566d6f47 | 14 | class MTSSerial : public MTSBufferedIO |
Mike Fiore |
1:d34b566d6f47 | 15 | { |
Mike Fiore |
1:d34b566d6f47 | 16 | public: |
Mike Fiore |
1:d34b566d6f47 | 17 | /** Creates a new MTSSerial object that can be used to talk to an mbed serial port |
Mike Fiore |
1:d34b566d6f47 | 18 | * through internal SW buffers. |
Mike Fiore |
1:d34b566d6f47 | 19 | * |
Mike Fiore |
1:d34b566d6f47 | 20 | * @param TXD the transmit data pin on the desired mbed Serial interface. |
Mike Fiore |
1:d34b566d6f47 | 21 | * @param RXD the receive data pin on the desired mbed Serial interface. |
Mike Fiore |
1:d34b566d6f47 | 22 | * @param txBufferSize the size in bytes of the internal SW transmit buffer. The |
Mike Fiore |
1:d34b566d6f47 | 23 | * default is 256 bytes. |
Mike Fiore |
1:d34b566d6f47 | 24 | * @param rxBufferSize the size in bytes of the internal SW receive buffer. The |
Mike Fiore |
1:d34b566d6f47 | 25 | * default is 256 bytes. |
Mike Fiore |
1:d34b566d6f47 | 26 | */ |
Mike Fiore |
1:d34b566d6f47 | 27 | MTSSerial(PinName TXD, PinName RXD, int txBufferSize = 256, int rxBufferSize = 256); |
Mike Fiore |
1:d34b566d6f47 | 28 | |
Mike Fiore |
1:d34b566d6f47 | 29 | /** Destructs an MTSSerial object and frees all related resources, including |
Mike Fiore |
1:d34b566d6f47 | 30 | * internal buffers. |
Mike Fiore |
1:d34b566d6f47 | 31 | */ |
Mike Fiore |
1:d34b566d6f47 | 32 | ~MTSSerial(); |
Mike Fiore |
1:d34b566d6f47 | 33 | |
Mike Fiore |
1:d34b566d6f47 | 34 | /** This method is used to the set the baud rate of the serial port. |
Mike Fiore |
1:d34b566d6f47 | 35 | * |
Mike Fiore |
1:d34b566d6f47 | 36 | * @param baudrate the baudrate in bps as an int. The default is 9600 bps. |
Mike Fiore |
1:d34b566d6f47 | 37 | */ |
Mike Fiore |
1:d34b566d6f47 | 38 | void baud(int baudrate); |
Mike Fiore |
1:d34b566d6f47 | 39 | |
Mike Fiore |
1:d34b566d6f47 | 40 | /** This method sets the transmission format used by the serial port. |
Mike Fiore |
1:d34b566d6f47 | 41 | * |
Mike Fiore |
1:d34b566d6f47 | 42 | * @param bits the number of bits in a word (5-8; default = 8) |
Mike Fiore |
1:d34b566d6f47 | 43 | * @param parity the parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, |
Mike Fiore |
1:d34b566d6f47 | 44 | * SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None) |
Mike Fiore |
1:d34b566d6f47 | 45 | * @param stop the number of stop bits (1 or 2; default = 1) |
Mike Fiore |
1:d34b566d6f47 | 46 | */ |
Mike Fiore |
1:d34b566d6f47 | 47 | void format(int bits=8, SerialBase::Parity parity=mbed::SerialBase::None, int stop_bits=1); |
Mike Fiore |
1:d34b566d6f47 | 48 | |
Mike Fiore |
1:d34b566d6f47 | 49 | protected: |
Vanger | 9:5b67a660292a | 50 | RawSerial serial; // Internal mbed Serial object |
Mike Fiore |
1:d34b566d6f47 | 51 | |
Mike Fiore |
1:d34b566d6f47 | 52 | private: |
Mike Fiore |
1:d34b566d6f47 | 53 | virtual void handleWrite(); // Method for handling data to be written |
Mike Fiore |
1:d34b566d6f47 | 54 | virtual void handleRead(); // Method for handling data to be read |
Mike Fiore |
1:d34b566d6f47 | 55 | }; |
Mike Fiore |
1:d34b566d6f47 | 56 | |
Mike Fiore |
1:d34b566d6f47 | 57 | } |
Mike Fiore |
1:d34b566d6f47 | 58 | |
Mike Fiore |
1:d34b566d6f47 | 59 | #endif /* MTSSERIAL_H */ |