mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
188:bcfe06ba3d64
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /* mbed Microcontroller Library
<> 149:156823d33999 2 * Copyright (c) 2006-2013 ARM Limited
AnnaBridge 189:f392fc9709a3 3 * SPDX-License-Identifier: Apache-2.0
<> 149:156823d33999 4 *
<> 149:156823d33999 5 * Licensed under the Apache License, Version 2.0 (the "License");
<> 149:156823d33999 6 * you may not use this file except in compliance with the License.
<> 149:156823d33999 7 * You may obtain a copy of the License at
<> 149:156823d33999 8 *
<> 149:156823d33999 9 * http://www.apache.org/licenses/LICENSE-2.0
<> 149:156823d33999 10 *
<> 149:156823d33999 11 * Unless required by applicable law or agreed to in writing, software
<> 149:156823d33999 12 * distributed under the License is distributed on an "AS IS" BASIS,
<> 149:156823d33999 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 149:156823d33999 14 * See the License for the specific language governing permissions and
<> 149:156823d33999 15 * limitations under the License.
<> 149:156823d33999 16 */
<> 149:156823d33999 17 #ifndef MBED_SERIAL_H
<> 149:156823d33999 18 #define MBED_SERIAL_H
<> 149:156823d33999 19
<> 149:156823d33999 20 #include "platform/platform.h"
<> 149:156823d33999 21
AnnaBridge 189:f392fc9709a3 22 #if DEVICE_SERIAL || defined(DOXYGEN_ONLY)
<> 149:156823d33999 23
AnnaBridge 188:bcfe06ba3d64 24 #include "platform/Stream.h"
<> 149:156823d33999 25 #include "SerialBase.h"
AnnaBridge 188:bcfe06ba3d64 26 #include "platform/PlatformMutex.h"
AnnaBridge 188:bcfe06ba3d64 27 #include "hal/serial_api.h"
AnnaBridge 168:9672193075cf 28 #include "platform/NonCopyable.h"
<> 149:156823d33999 29
<> 149:156823d33999 30 namespace mbed {
<> 149:156823d33999 31 /** \addtogroup drivers */
<> 149:156823d33999 32
<> 149:156823d33999 33 /** A serial port (UART) for communication with other serial devices
<> 149:156823d33999 34 *
<> 149:156823d33999 35 * Can be used for Full Duplex communication, or Simplex by specifying
<> 149:156823d33999 36 * one pin as NC (Not Connected)
<> 149:156823d33999 37 *
AnnaBridge 167:e84263d55307 38 * @note Synchronization level: Thread safe
<> 149:156823d33999 39 *
<> 149:156823d33999 40 * Example:
<> 149:156823d33999 41 * @code
<> 149:156823d33999 42 * // Print "Hello World" to the PC
<> 149:156823d33999 43 *
<> 149:156823d33999 44 * #include "mbed.h"
<> 149:156823d33999 45 *
<> 149:156823d33999 46 * Serial pc(USBTX, USBRX);
<> 149:156823d33999 47 *
<> 149:156823d33999 48 * int main() {
<> 149:156823d33999 49 * pc.printf("Hello World\n");
<> 149:156823d33999 50 * }
<> 149:156823d33999 51 * @endcode
AnnaBridge 167:e84263d55307 52 * @ingroup drivers
<> 149:156823d33999 53 */
AnnaBridge 168:9672193075cf 54 class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
<> 149:156823d33999 55
<> 149:156823d33999 56 public:
<> 149:156823d33999 57 #if DEVICE_SERIAL_ASYNCH
<> 149:156823d33999 58 using SerialBase::read;
<> 149:156823d33999 59 using SerialBase::write;
<> 149:156823d33999 60 #endif
<> 149:156823d33999 61
<> 149:156823d33999 62 /** Create a Serial port, connected to the specified transmit and receive pins
<> 149:156823d33999 63 *
<> 149:156823d33999 64 * @param tx Transmit pin
<> 149:156823d33999 65 * @param rx Receive pin
<> 149:156823d33999 66 * @param name The name of the stream associated with this serial port (optional)
AnnaBridge 188:bcfe06ba3d64 67 * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE or 9600)
<> 149:156823d33999 68 *
<> 149:156823d33999 69 * @note
AnnaBridge 188:bcfe06ba3d64 70 * Either tx or rx may be specified as NC (Not Connected) if unused
<> 149:156823d33999 71 */
AnnaBridge 187:0387e8f68319 72 Serial(PinName tx, PinName rx, const char *name = NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
<> 149:156823d33999 73
<> 149:156823d33999 74
<> 149:156823d33999 75 /** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
<> 149:156823d33999 76 *
<> 149:156823d33999 77 * @param tx Transmit pin
<> 149:156823d33999 78 * @param rx Receive pin
<> 149:156823d33999 79 * @param baud The baud rate of the serial port
<> 149:156823d33999 80 *
<> 149:156823d33999 81 * @note
AnnaBridge 188:bcfe06ba3d64 82 * Either tx or rx may be specified as NC (Not Connected) if unused
<> 149:156823d33999 83 */
<> 149:156823d33999 84 Serial(PinName tx, PinName rx, int baud);
<> 149:156823d33999 85
AnnaBridge 167:e84263d55307 86 /* Stream gives us a FileHandle with non-functional poll()/readable()/writable. Pass through
AnnaBridge 167:e84263d55307 87 * the calls from the SerialBase instead for backwards compatibility. This problem is
AnnaBridge 167:e84263d55307 88 * part of why Stream and Serial should be deprecated.
AnnaBridge 167:e84263d55307 89 */
AnnaBridge 167:e84263d55307 90 bool readable()
AnnaBridge 167:e84263d55307 91 {
AnnaBridge 167:e84263d55307 92 return SerialBase::readable();
AnnaBridge 167:e84263d55307 93 }
AnnaBridge 167:e84263d55307 94 bool writable()
AnnaBridge 167:e84263d55307 95 {
AnnaBridge 167:e84263d55307 96 return SerialBase::writeable();
AnnaBridge 167:e84263d55307 97 }
AnnaBridge 167:e84263d55307 98 bool writeable()
AnnaBridge 167:e84263d55307 99 {
AnnaBridge 167:e84263d55307 100 return SerialBase::writeable();
AnnaBridge 167:e84263d55307 101 }
AnnaBridge 167:e84263d55307 102
AnnaBridge 188:bcfe06ba3d64 103 #if !(DOXYGEN_ONLY)
<> 149:156823d33999 104 protected:
<> 149:156823d33999 105 virtual int _getc();
<> 149:156823d33999 106 virtual int _putc(int c);
<> 149:156823d33999 107 virtual void lock();
<> 149:156823d33999 108 virtual void unlock();
<> 149:156823d33999 109
<> 149:156823d33999 110 PlatformMutex _mutex;
AnnaBridge 188:bcfe06ba3d64 111 #endif
<> 149:156823d33999 112 };
<> 149:156823d33999 113
<> 149:156823d33999 114 } // namespace mbed
<> 149:156823d33999 115
<> 149:156823d33999 116 #endif
<> 149:156823d33999 117
<> 149:156823d33999 118 #endif