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

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.