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