2013-02-18 15:32:11 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2006-2013 ARM Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#ifndef MBED_SERIAL_H
|
|
|
|
#define MBED_SERIAL_H
|
|
|
|
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "platform/platform.h"
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2017-04-12 14:01:29 +00:00
|
|
|
#if defined (DEVICE_SERIAL) || defined(DOXYGEN_ONLY)
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2018-08-27 18:47:19 +00:00
|
|
|
#include "platform/Stream.h"
|
2013-10-23 12:49:07 +00:00
|
|
|
#include "SerialBase.h"
|
2018-08-27 18:47:19 +00:00
|
|
|
#include "platform/PlatformMutex.h"
|
|
|
|
#include "hal/serial_api.h"
|
drivers: Mark non identity types as non copyable with the NonCopyable traits.
Classes changed: CAN, Ethernet, FlashIAP, I2C, InterruptIn, LowPowerTicker, LowPowerTimeout, LowPowerTimer, RawSerial, Serial, SerialBase, SPI, SPISlave, Ticker, Timeout, Timer, TimerEvent and UARTSerial.
2017-06-20 13:26:29 +00:00
|
|
|
#include "platform/NonCopyable.h"
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
namespace mbed {
|
2016-10-04 20:02:44 +00:00
|
|
|
/** \addtogroup drivers */
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
/** A serial port (UART) for communication with other serial devices
|
|
|
|
*
|
|
|
|
* Can be used for Full Duplex communication, or Simplex by specifying
|
|
|
|
* one pin as NC (Not Connected)
|
|
|
|
*
|
2017-04-04 17:40:09 +00:00
|
|
|
* @note Synchronization level: Thread safe
|
2016-06-08 12:52:14 +00:00
|
|
|
*
|
2013-02-18 15:32:11 +00:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* // Print "Hello World" to the PC
|
|
|
|
*
|
|
|
|
* #include "mbed.h"
|
|
|
|
*
|
|
|
|
* Serial pc(USBTX, USBRX);
|
|
|
|
*
|
|
|
|
* int main() {
|
|
|
|
* pc.printf("Hello World\n");
|
|
|
|
* }
|
|
|
|
* @endcode
|
2017-04-04 19:21:53 +00:00
|
|
|
* @ingroup drivers
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
drivers: Mark non identity types as non copyable with the NonCopyable traits.
Classes changed: CAN, Ethernet, FlashIAP, I2C, InterruptIn, LowPowerTicker, LowPowerTimeout, LowPowerTimer, RawSerial, Serial, SerialBase, SPI, SPISlave, Ticker, Timeout, Timer, TimerEvent and UARTSerial.
2017-06-20 13:26:29 +00:00
|
|
|
class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
public:
|
2015-04-23 13:56:34 +00:00
|
|
|
#if DEVICE_SERIAL_ASYNCH
|
|
|
|
using SerialBase::read;
|
|
|
|
using SerialBase::write;
|
|
|
|
#endif
|
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
/** Create a Serial port, connected to the specified transmit and receive pins
|
|
|
|
*
|
|
|
|
* @param tx Transmit pin
|
|
|
|
* @param rx Receive pin
|
2016-08-11 10:01:33 +00:00
|
|
|
* @param name The name of the stream associated with this serial port (optional)
|
2018-10-12 18:40:23 +00:00
|
|
|
* @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE or 9600)
|
2013-02-18 15:32:11 +00:00
|
|
|
*
|
|
|
|
* @note
|
2018-10-12 18:22:14 +00:00
|
|
|
* Either tx or rx may be specified as NC (Not Connected) if unused
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
2018-05-24 15:58:14 +00:00
|
|
|
Serial(PinName tx, PinName rx, const char *name = NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
|
2016-08-11 10:01:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
|
|
|
|
*
|
|
|
|
* @param tx Transmit pin
|
|
|
|
* @param rx Receive pin
|
|
|
|
* @param baud The baud rate of the serial port
|
|
|
|
*
|
|
|
|
* @note
|
2018-10-12 18:22:14 +00:00
|
|
|
* Either tx or rx may be specified as NC (Not Connected) if unused
|
2016-08-11 10:01:33 +00:00
|
|
|
*/
|
|
|
|
Serial(PinName tx, PinName rx, int baud);
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2017-02-15 23:21:50 +00:00
|
|
|
bool readable()
|
|
|
|
{
|
|
|
|
return SerialBase::readable();
|
|
|
|
}
|
|
|
|
bool writable()
|
|
|
|
{
|
|
|
|
return SerialBase::writeable();
|
|
|
|
}
|
|
|
|
bool writeable()
|
|
|
|
{
|
|
|
|
return SerialBase::writeable();
|
|
|
|
}
|
|
|
|
|
2018-10-12 18:20:02 +00:00
|
|
|
#if !(DOXYGEN_ONLY)
|
2013-02-18 15:32:11 +00:00
|
|
|
protected:
|
|
|
|
virtual int _getc();
|
2014-05-26 17:04:46 +00:00
|
|
|
virtual int _putc(int c);
|
2016-05-31 22:57:41 +00:00
|
|
|
virtual void lock();
|
|
|
|
virtual void unlock();
|
|
|
|
|
|
|
|
PlatformMutex _mutex;
|
2018-10-12 18:20:02 +00:00
|
|
|
#endif
|
2013-02-18 15:32:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mbed
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|