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_RAW_SERIAL_H
<> 149:156823d33999 18 #define MBED_RAW_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 189:f392fc9709a3 24 #include "mbed_toolchain.h"
<> 149:156823d33999 25 #include "drivers/SerialBase.h"
<> 149:156823d33999 26 #include "hal/serial_api.h"
AnnaBridge 168:9672193075cf 27 #include "platform/NonCopyable.h"
<> 149:156823d33999 28
<> 149:156823d33999 29 namespace mbed {
<> 149:156823d33999 30 /** \addtogroup drivers */
<> 149:156823d33999 31
<> 149:156823d33999 32 /** A serial port (UART) for communication with other serial devices
<> 149:156823d33999 33 * This is a variation of the Serial class that doesn't use streams,
<> 149:156823d33999 34 * thus making it safe to use in interrupt handlers with the RTOS.
<> 149:156823d33999 35 *
<> 149:156823d33999 36 * Can be used for Full Duplex communication, or Simplex by specifying
<> 149:156823d33999 37 * one pin as NC (Not Connected)
<> 149:156823d33999 38 *
AnnaBridge 167:e84263d55307 39 * @note Synchronization level: Not protected
<> 149:156823d33999 40 *
<> 149:156823d33999 41 * Example:
<> 149:156823d33999 42 * @code
<> 149:156823d33999 43 * // Send a char to the PC
<> 149:156823d33999 44 *
<> 149:156823d33999 45 * #include "mbed.h"
<> 149:156823d33999 46 *
<> 149:156823d33999 47 * RawSerial pc(USBTX, USBRX);
<> 149:156823d33999 48 *
<> 149:156823d33999 49 * int main() {
<> 149:156823d33999 50 * pc.putc('A');
<> 149:156823d33999 51 * }
<> 149:156823d33999 52 * @endcode
AnnaBridge 167:e84263d55307 53 * @ingroup drivers
<> 149:156823d33999 54 */
AnnaBridge 168:9672193075cf 55 class RawSerial: public SerialBase, private NonCopyable<RawSerial> {
<> 149:156823d33999 56
<> 149:156823d33999 57 public:
<> 149:156823d33999 58 /** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud.
<> 149:156823d33999 59 *
<> 149:156823d33999 60 * @param tx Transmit pin
<> 149:156823d33999 61 * @param rx Receive pin
<> 149:156823d33999 62 * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
<> 149:156823d33999 63 *
<> 149:156823d33999 64 * @note
<> 149:156823d33999 65 * Either tx or rx may be specified as NC if unused
<> 149:156823d33999 66 */
<> 149:156823d33999 67 RawSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
<> 149:156823d33999 68
<> 149:156823d33999 69 /** Write a char to the serial port
<> 149:156823d33999 70 *
<> 149:156823d33999 71 * @param c The char to write
<> 149:156823d33999 72 *
AnnaBridge 184:08ed48f1de7f 73 * @returns The written char or -1 if an error occurred
<> 149:156823d33999 74 */
<> 149:156823d33999 75 int putc(int c);
<> 149:156823d33999 76
<> 149:156823d33999 77 /** Read a char from the serial port
<> 149:156823d33999 78 *
<> 149:156823d33999 79 * @returns The char read from the serial port
<> 149:156823d33999 80 */
<> 149:156823d33999 81 int getc();
<> 149:156823d33999 82
<> 149:156823d33999 83 /** Write a string to the serial port
<> 149:156823d33999 84 *
<> 149:156823d33999 85 * @param str The string to write
<> 149:156823d33999 86 *
<> 149:156823d33999 87 * @returns 0 if the write succeeds, EOF for error
<> 149:156823d33999 88 */
<> 149:156823d33999 89 int puts(const char *str);
<> 149:156823d33999 90
AnnaBridge 189:f392fc9709a3 91 int printf(const char *format, ...) MBED_PRINTF_METHOD(1, 2);
<> 149:156823d33999 92
AnnaBridge 188:bcfe06ba3d64 93 #if !(DOXYGEN_ONLY)
<> 149:156823d33999 94 protected:
<> 149:156823d33999 95
AnnaBridge 167:e84263d55307 96 /* Acquire exclusive access to this serial port
<> 149:156823d33999 97 */
<> 149:156823d33999 98 virtual void lock(void);
<> 149:156823d33999 99
AnnaBridge 167:e84263d55307 100 /* Release exclusive access to this serial port
<> 149:156823d33999 101 */
<> 149:156823d33999 102 virtual void unlock(void);
AnnaBridge 188:bcfe06ba3d64 103 #endif
<> 149:156823d33999 104 };
<> 149:156823d33999 105
<> 149:156823d33999 106 } // namespace mbed
<> 149:156823d33999 107
<> 149:156823d33999 108 #endif
<> 149:156823d33999 109
<> 149:156823d33999 110 #endif