MTS_SPI_Slave unfinished

Fork of MTS-Serial by MultiTech

Committer:
Leon Lindenfelser
Date:
Thu Mar 23 16:15:14 2017 -0500
Revision:
12:e12b79a4ab4f
Parent:
9:5b67a660292a
Update to match gitlab commit 90a9e07c8d77b31bb36e641b4361184ef2ac8558 Feb 2 2016.

Who changed what in which revision?

UserRevisionLine numberNew 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
Leon Lindenfelser 12:e12b79a4ab4f 34 /**
Leon Lindenfelser 12:e12b79a4ab4f 35 * Attach the internal serial object to provided pins
Leon Lindenfelser 12:e12b79a4ab4f 36 * @param TXD the transmit data pin on the desired mbed Serial interface.
Leon Lindenfelser 12:e12b79a4ab4f 37 * @param RXD the receive data pin on the desired mbed Serial interface.
Leon Lindenfelser 12:e12b79a4ab4f 38 */
Leon Lindenfelser 12:e12b79a4ab4f 39 void reattach(PinName TXD, PinName RXD);
Leon Lindenfelser 12:e12b79a4ab4f 40
Mike Fiore 1:d34b566d6f47 41 /** This method is used to the set the baud rate of the serial port.
Mike Fiore 1:d34b566d6f47 42 *
Mike Fiore 1:d34b566d6f47 43 * @param baudrate the baudrate in bps as an int. The default is 9600 bps.
Mike Fiore 1:d34b566d6f47 44 */
Mike Fiore 1:d34b566d6f47 45 void baud(int baudrate);
Mike Fiore 1:d34b566d6f47 46
Mike Fiore 1:d34b566d6f47 47 /** This method sets the transmission format used by the serial port.
Mike Fiore 1:d34b566d6f47 48 *
Mike Fiore 1:d34b566d6f47 49 * @param bits the number of bits in a word (5-8; default = 8)
Mike Fiore 1:d34b566d6f47 50 * @param parity the parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even,
Mike Fiore 1:d34b566d6f47 51 * SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
Mike Fiore 1:d34b566d6f47 52 * @param stop the number of stop bits (1 or 2; default = 1)
Mike Fiore 1:d34b566d6f47 53 */
Mike Fiore 1:d34b566d6f47 54 void format(int bits=8, SerialBase::Parity parity=mbed::SerialBase::None, int stop_bits=1);
Mike Fiore 1:d34b566d6f47 55
Leon Lindenfelser 12:e12b79a4ab4f 56 /** Generate a break condition on the serial line
Leon Lindenfelser 12:e12b79a4ab4f 57 */
Leon Lindenfelser 12:e12b79a4ab4f 58 void sendBreak();
Leon Lindenfelser 12:e12b79a4ab4f 59
Mike Fiore 1:d34b566d6f47 60 protected:
Leon Lindenfelser 12:e12b79a4ab4f 61 RawSerial* _serial; // Internal mbed Serial object
Leon Lindenfelser 12:e12b79a4ab4f 62 int _baudrate;
Leon Lindenfelser 12:e12b79a4ab4f 63 int _bits;
Leon Lindenfelser 12:e12b79a4ab4f 64 SerialBase::Parity _parity;
Leon Lindenfelser 12:e12b79a4ab4f 65 int _stop_bits;
Leon Lindenfelser 12:e12b79a4ab4f 66
Mike Fiore 1:d34b566d6f47 67
Mike Fiore 1:d34b566d6f47 68 private:
Mike Fiore 1:d34b566d6f47 69 virtual void handleWrite(); // Method for handling data to be written
Mike Fiore 1:d34b566d6f47 70 virtual void handleRead(); // Method for handling data to be read
Mike Fiore 1:d34b566d6f47 71 };
Mike Fiore 1:d34b566d6f47 72
Mike Fiore 1:d34b566d6f47 73 }
Mike Fiore 1:d34b566d6f47 74
Mike Fiore 1:d34b566d6f47 75 #endif /* MTSSERIAL_H */