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