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
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 189:f392fc9709a3 1 /* mbed Microcontroller Library
AnnaBridge 189:f392fc9709a3 2 * Copyright (c) 2006-2013 ARM Limited
AnnaBridge 189:f392fc9709a3 3 * SPDX-License-Identifier: Apache-2.0
AnnaBridge 189:f392fc9709a3 4 *
AnnaBridge 189:f392fc9709a3 5 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 189:f392fc9709a3 6 * you may not use this file except in compliance with the License.
AnnaBridge 189:f392fc9709a3 7 * You may obtain a copy of the License at
AnnaBridge 189:f392fc9709a3 8 *
AnnaBridge 189:f392fc9709a3 9 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 189:f392fc9709a3 10 *
AnnaBridge 189:f392fc9709a3 11 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 189:f392fc9709a3 12 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 189:f392fc9709a3 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 189:f392fc9709a3 14 * See the License for the specific language governing permissions and
AnnaBridge 189:f392fc9709a3 15 * limitations under the License.
AnnaBridge 189:f392fc9709a3 16 */
AnnaBridge 189:f392fc9709a3 17 #ifndef MBED_RAW_SERIAL_H
AnnaBridge 189:f392fc9709a3 18 #define MBED_RAW_SERIAL_H
AnnaBridge 189:f392fc9709a3 19
AnnaBridge 189:f392fc9709a3 20 #include "platform/platform.h"
AnnaBridge 189:f392fc9709a3 21
AnnaBridge 189:f392fc9709a3 22 #if DEVICE_SERIAL || defined(DOXYGEN_ONLY)
AnnaBridge 189:f392fc9709a3 23
AnnaBridge 189:f392fc9709a3 24 #include "mbed_toolchain.h"
AnnaBridge 189:f392fc9709a3 25 #include "drivers/SerialBase.h"
AnnaBridge 189:f392fc9709a3 26 #include "hal/serial_api.h"
AnnaBridge 189:f392fc9709a3 27 #include "platform/NonCopyable.h"
AnnaBridge 189:f392fc9709a3 28
AnnaBridge 189:f392fc9709a3 29 namespace mbed {
AnnaBridge 189:f392fc9709a3 30 /** \addtogroup drivers */
AnnaBridge 189:f392fc9709a3 31
AnnaBridge 189:f392fc9709a3 32 /** A serial port (UART) for communication with other serial devices
AnnaBridge 189:f392fc9709a3 33 * This is a variation of the Serial class that doesn't use streams,
AnnaBridge 189:f392fc9709a3 34 * thus making it safe to use in interrupt handlers with the RTOS.
AnnaBridge 189:f392fc9709a3 35 *
AnnaBridge 189:f392fc9709a3 36 * Can be used for Full Duplex communication, or Simplex by specifying
AnnaBridge 189:f392fc9709a3 37 * one pin as NC (Not Connected)
AnnaBridge 189:f392fc9709a3 38 *
AnnaBridge 189:f392fc9709a3 39 * @note Synchronization level: Not protected
AnnaBridge 189:f392fc9709a3 40 *
AnnaBridge 189:f392fc9709a3 41 * Example:
AnnaBridge 189:f392fc9709a3 42 * @code
AnnaBridge 189:f392fc9709a3 43 * // Send a char to the PC
AnnaBridge 189:f392fc9709a3 44 *
AnnaBridge 189:f392fc9709a3 45 * #include "mbed.h"
AnnaBridge 189:f392fc9709a3 46 *
AnnaBridge 189:f392fc9709a3 47 * RawSerial pc(USBTX, USBRX);
AnnaBridge 189:f392fc9709a3 48 *
AnnaBridge 189:f392fc9709a3 49 * int main() {
AnnaBridge 189:f392fc9709a3 50 * pc.putc('A');
AnnaBridge 189:f392fc9709a3 51 * }
AnnaBridge 189:f392fc9709a3 52 * @endcode
AnnaBridge 189:f392fc9709a3 53 * @ingroup drivers
AnnaBridge 189:f392fc9709a3 54 */
AnnaBridge 189:f392fc9709a3 55 class RawSerial: public SerialBase, private NonCopyable<RawSerial> {
AnnaBridge 189:f392fc9709a3 56
AnnaBridge 189:f392fc9709a3 57 public:
AnnaBridge 189:f392fc9709a3 58 /** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud.
AnnaBridge 189:f392fc9709a3 59 *
AnnaBridge 189:f392fc9709a3 60 * @param tx Transmit pin
AnnaBridge 189:f392fc9709a3 61 * @param rx Receive pin
AnnaBridge 189:f392fc9709a3 62 * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
AnnaBridge 189:f392fc9709a3 63 *
AnnaBridge 189:f392fc9709a3 64 * @note
AnnaBridge 189:f392fc9709a3 65 * Either tx or rx may be specified as NC if unused
AnnaBridge 189:f392fc9709a3 66 */
AnnaBridge 189:f392fc9709a3 67 RawSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
AnnaBridge 189:f392fc9709a3 68
AnnaBridge 189:f392fc9709a3 69 /** Write a char to the serial port
AnnaBridge 189:f392fc9709a3 70 *
AnnaBridge 189:f392fc9709a3 71 * @param c The char to write
AnnaBridge 189:f392fc9709a3 72 *
AnnaBridge 189:f392fc9709a3 73 * @returns The written char or -1 if an error occurred
AnnaBridge 189:f392fc9709a3 74 */
AnnaBridge 189:f392fc9709a3 75 int putc(int c);
AnnaBridge 189:f392fc9709a3 76
AnnaBridge 189:f392fc9709a3 77 /** Read a char from the serial port
AnnaBridge 189:f392fc9709a3 78 *
AnnaBridge 189:f392fc9709a3 79 * @returns The char read from the serial port
AnnaBridge 189:f392fc9709a3 80 */
AnnaBridge 189:f392fc9709a3 81 int getc();
AnnaBridge 189:f392fc9709a3 82
AnnaBridge 189:f392fc9709a3 83 /** Write a string to the serial port
AnnaBridge 189:f392fc9709a3 84 *
AnnaBridge 189:f392fc9709a3 85 * @param str The string to write
AnnaBridge 189:f392fc9709a3 86 *
AnnaBridge 189:f392fc9709a3 87 * @returns 0 if the write succeeds, EOF for error
AnnaBridge 189:f392fc9709a3 88 */
AnnaBridge 189:f392fc9709a3 89 int puts(const char *str);
AnnaBridge 189:f392fc9709a3 90
AnnaBridge 189:f392fc9709a3 91 int printf(const char *format, ...) MBED_PRINTF_METHOD(1, 2);
AnnaBridge 189:f392fc9709a3 92
AnnaBridge 189:f392fc9709a3 93 #if !(DOXYGEN_ONLY)
AnnaBridge 189:f392fc9709a3 94 protected:
AnnaBridge 189:f392fc9709a3 95
AnnaBridge 189:f392fc9709a3 96 /* Acquire exclusive access to this serial port
AnnaBridge 189:f392fc9709a3 97 */
AnnaBridge 189:f392fc9709a3 98 virtual void lock(void);
AnnaBridge 189:f392fc9709a3 99
AnnaBridge 189:f392fc9709a3 100 /* Release exclusive access to this serial port
AnnaBridge 189:f392fc9709a3 101 */
AnnaBridge 189:f392fc9709a3 102 virtual void unlock(void);
AnnaBridge 189:f392fc9709a3 103 #endif
AnnaBridge 189:f392fc9709a3 104 };
AnnaBridge 189:f392fc9709a3 105
AnnaBridge 189:f392fc9709a3 106 } // namespace mbed
AnnaBridge 189:f392fc9709a3 107
AnnaBridge 189:f392fc9709a3 108 #endif
AnnaBridge 189:f392fc9709a3 109
AnnaBridge 189:f392fc9709a3 110 #endif