,,

Fork of Application by Daniel Sygut

Committer:
Zaitsev
Date:
Tue Jan 10 20:42:26 2017 +0000
Revision:
10:41552d038a69
USB Serial bi-directional bridge

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Zaitsev 10:41552d038a69 1 /* mbed Microcontroller Library
Zaitsev 10:41552d038a69 2 * Copyright (c) 2006-2013 ARM Limited
Zaitsev 10:41552d038a69 3 *
Zaitsev 10:41552d038a69 4 * Licensed under the Apache License, Version 2.0 (the "License");
Zaitsev 10:41552d038a69 5 * you may not use this file except in compliance with the License.
Zaitsev 10:41552d038a69 6 * You may obtain a copy of the License at
Zaitsev 10:41552d038a69 7 *
Zaitsev 10:41552d038a69 8 * http://www.apache.org/licenses/LICENSE-2.0
Zaitsev 10:41552d038a69 9 *
Zaitsev 10:41552d038a69 10 * Unless required by applicable law or agreed to in writing, software
Zaitsev 10:41552d038a69 11 * distributed under the License is distributed on an "AS IS" BASIS,
Zaitsev 10:41552d038a69 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Zaitsev 10:41552d038a69 13 * See the License for the specific language governing permissions and
Zaitsev 10:41552d038a69 14 * limitations under the License.
Zaitsev 10:41552d038a69 15 */
Zaitsev 10:41552d038a69 16 #ifndef MBED_SERIAL_H
Zaitsev 10:41552d038a69 17 #define MBED_SERIAL_H
Zaitsev 10:41552d038a69 18
Zaitsev 10:41552d038a69 19 #include "platform/platform.h"
Zaitsev 10:41552d038a69 20
Zaitsev 10:41552d038a69 21 #if DEVICE_SERIAL
Zaitsev 10:41552d038a69 22
Zaitsev 10:41552d038a69 23 #include "Stream.h"
Zaitsev 10:41552d038a69 24 #include "SerialBase.h"
Zaitsev 10:41552d038a69 25 #include "PlatformMutex.h"
Zaitsev 10:41552d038a69 26 #include "serial_api.h"
Zaitsev 10:41552d038a69 27
Zaitsev 10:41552d038a69 28 namespace mbed {
Zaitsev 10:41552d038a69 29 /** \addtogroup drivers */
Zaitsev 10:41552d038a69 30 /** @{*/
Zaitsev 10:41552d038a69 31
Zaitsev 10:41552d038a69 32 /** A serial port (UART) for communication with other serial devices
Zaitsev 10:41552d038a69 33 *
Zaitsev 10:41552d038a69 34 * Can be used for Full Duplex communication, or Simplex by specifying
Zaitsev 10:41552d038a69 35 * one pin as NC (Not Connected)
Zaitsev 10:41552d038a69 36 *
Zaitsev 10:41552d038a69 37 * @Note Synchronization level: Thread safe
Zaitsev 10:41552d038a69 38 *
Zaitsev 10:41552d038a69 39 * Example:
Zaitsev 10:41552d038a69 40 * @code
Zaitsev 10:41552d038a69 41 * // Print "Hello World" to the PC
Zaitsev 10:41552d038a69 42 *
Zaitsev 10:41552d038a69 43 * #include "mbed.h"
Zaitsev 10:41552d038a69 44 *
Zaitsev 10:41552d038a69 45 * Serial pc(USBTX, USBRX);
Zaitsev 10:41552d038a69 46 *
Zaitsev 10:41552d038a69 47 * int main() {
Zaitsev 10:41552d038a69 48 * pc.printf("Hello World\n");
Zaitsev 10:41552d038a69 49 * }
Zaitsev 10:41552d038a69 50 * @endcode
Zaitsev 10:41552d038a69 51 */
Zaitsev 10:41552d038a69 52 class Serial : public SerialBase, public Stream {
Zaitsev 10:41552d038a69 53
Zaitsev 10:41552d038a69 54 public:
Zaitsev 10:41552d038a69 55 #if DEVICE_SERIAL_ASYNCH
Zaitsev 10:41552d038a69 56 using SerialBase::read;
Zaitsev 10:41552d038a69 57 using SerialBase::write;
Zaitsev 10:41552d038a69 58 #endif
Zaitsev 10:41552d038a69 59
Zaitsev 10:41552d038a69 60 /** Create a Serial port, connected to the specified transmit and receive pins
Zaitsev 10:41552d038a69 61 *
Zaitsev 10:41552d038a69 62 * @param tx Transmit pin
Zaitsev 10:41552d038a69 63 * @param rx Receive pin
Zaitsev 10:41552d038a69 64 * @param name The name of the stream associated with this serial port (optional)
Zaitsev 10:41552d038a69 65 * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
Zaitsev 10:41552d038a69 66 *
Zaitsev 10:41552d038a69 67 * @note
Zaitsev 10:41552d038a69 68 * Either tx or rx may be specified as NC if unused
Zaitsev 10:41552d038a69 69 */
Zaitsev 10:41552d038a69 70 Serial(PinName tx, PinName rx, const char *name=NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
Zaitsev 10:41552d038a69 71
Zaitsev 10:41552d038a69 72
Zaitsev 10:41552d038a69 73 /** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
Zaitsev 10:41552d038a69 74 *
Zaitsev 10:41552d038a69 75 * @param tx Transmit pin
Zaitsev 10:41552d038a69 76 * @param rx Receive pin
Zaitsev 10:41552d038a69 77 * @param baud The baud rate of the serial port
Zaitsev 10:41552d038a69 78 *
Zaitsev 10:41552d038a69 79 * @note
Zaitsev 10:41552d038a69 80 * Either tx or rx may be specified as NC if unused
Zaitsev 10:41552d038a69 81 */
Zaitsev 10:41552d038a69 82 Serial(PinName tx, PinName rx, int baud);
Zaitsev 10:41552d038a69 83
Zaitsev 10:41552d038a69 84 protected:
Zaitsev 10:41552d038a69 85 virtual int _getc();
Zaitsev 10:41552d038a69 86 virtual int _putc(int c);
Zaitsev 10:41552d038a69 87 virtual void lock();
Zaitsev 10:41552d038a69 88 virtual void unlock();
Zaitsev 10:41552d038a69 89
Zaitsev 10:41552d038a69 90 PlatformMutex _mutex;
Zaitsev 10:41552d038a69 91 };
Zaitsev 10:41552d038a69 92
Zaitsev 10:41552d038a69 93 } // namespace mbed
Zaitsev 10:41552d038a69 94
Zaitsev 10:41552d038a69 95 #endif
Zaitsev 10:41552d038a69 96
Zaitsev 10:41552d038a69 97 #endif
Zaitsev 10:41552d038a69 98
Zaitsev 10:41552d038a69 99 /** @}*/