mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
RawSerial.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #ifndef MBED_RAW_SERIAL_H 00018 #define MBED_RAW_SERIAL_H 00019 00020 #include "platform/platform.h" 00021 00022 #if DEVICE_SERIAL || defined(DOXYGEN_ONLY) 00023 00024 #include "mbed_toolchain.h" 00025 #include "drivers/SerialBase.h" 00026 #include "hal/serial_api.h" 00027 #include "platform/NonCopyable.h" 00028 00029 namespace mbed { 00030 /** \addtogroup drivers */ 00031 00032 /** A serial port (UART) for communication with other serial devices 00033 * This is a variation of the Serial class that doesn't use streams, 00034 * thus making it safe to use in interrupt handlers with the RTOS. 00035 * 00036 * Can be used for Full Duplex communication, or Simplex by specifying 00037 * one pin as NC (Not Connected) 00038 * 00039 * @note Synchronization level: Not protected 00040 * 00041 * Example: 00042 * @code 00043 * // Send a char to the PC 00044 * 00045 * #include "mbed.h" 00046 * 00047 * RawSerial pc(USBTX, USBRX); 00048 * 00049 * int main() { 00050 * pc.putc('A'); 00051 * } 00052 * @endcode 00053 * @ingroup drivers 00054 */ 00055 class RawSerial: public SerialBase, private NonCopyable<RawSerial> { 00056 00057 public: 00058 /** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud. 00059 * 00060 * @param tx Transmit pin 00061 * @param rx Receive pin 00062 * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) 00063 * 00064 * @note 00065 * Either tx or rx may be specified as NC if unused 00066 */ 00067 RawSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); 00068 00069 /** Write a char to the serial port 00070 * 00071 * @param c The char to write 00072 * 00073 * @returns The written char or -1 if an error occurred 00074 */ 00075 int putc(int c); 00076 00077 /** Read a char from the serial port 00078 * 00079 * @returns The char read from the serial port 00080 */ 00081 int getc(); 00082 00083 /** Write a string to the serial port 00084 * 00085 * @param str The string to write 00086 * 00087 * @returns 0 if the write succeeds, EOF for error 00088 */ 00089 int puts(const char *str); 00090 00091 int printf(const char *format, ...) MBED_PRINTF_METHOD(1, 2); 00092 00093 #if !(DOXYGEN_ONLY) 00094 protected: 00095 00096 /* Acquire exclusive access to this serial port 00097 */ 00098 virtual void lock(void); 00099 00100 /* Release exclusive access to this serial port 00101 */ 00102 virtual void unlock(void); 00103 #endif 00104 }; 00105 00106 } // namespace mbed 00107 00108 #endif 00109 00110 #endif
Generated on Tue Jul 12 2022 20:41:15 by 1.7.2