From Ben Katz mbed-dev library. Removed unnecessary target files to reduce the overall size by a factor of 10 to make it easier to import into the online IDE.
Dependents: motor_driver motor_driver_screaming_fix
drivers/Serial.h@0:083111ae2a11, 2020-11-26 (annotated)
- Committer:
- saloutos
- Date:
- Thu Nov 26 04:08:56 2020 +0000
- Revision:
- 0:083111ae2a11
first commit of leaned mbed dev lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
saloutos | 0:083111ae2a11 | 1 | /* mbed Microcontroller Library |
saloutos | 0:083111ae2a11 | 2 | * Copyright (c) 2006-2013 ARM Limited |
saloutos | 0:083111ae2a11 | 3 | * |
saloutos | 0:083111ae2a11 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
saloutos | 0:083111ae2a11 | 5 | * you may not use this file except in compliance with the License. |
saloutos | 0:083111ae2a11 | 6 | * You may obtain a copy of the License at |
saloutos | 0:083111ae2a11 | 7 | * |
saloutos | 0:083111ae2a11 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
saloutos | 0:083111ae2a11 | 9 | * |
saloutos | 0:083111ae2a11 | 10 | * Unless required by applicable law or agreed to in writing, software |
saloutos | 0:083111ae2a11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
saloutos | 0:083111ae2a11 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
saloutos | 0:083111ae2a11 | 13 | * See the License for the specific language governing permissions and |
saloutos | 0:083111ae2a11 | 14 | * limitations under the License. |
saloutos | 0:083111ae2a11 | 15 | */ |
saloutos | 0:083111ae2a11 | 16 | #ifndef MBED_SERIAL_H |
saloutos | 0:083111ae2a11 | 17 | #define MBED_SERIAL_H |
saloutos | 0:083111ae2a11 | 18 | |
saloutos | 0:083111ae2a11 | 19 | #include "platform/platform.h" |
saloutos | 0:083111ae2a11 | 20 | |
saloutos | 0:083111ae2a11 | 21 | #if defined (DEVICE_SERIAL) || defined(DOXYGEN_ONLY) |
saloutos | 0:083111ae2a11 | 22 | |
saloutos | 0:083111ae2a11 | 23 | #include "Stream.h" |
saloutos | 0:083111ae2a11 | 24 | #include "SerialBase.h" |
saloutos | 0:083111ae2a11 | 25 | #include "PlatformMutex.h" |
saloutos | 0:083111ae2a11 | 26 | #include "serial_api.h" |
saloutos | 0:083111ae2a11 | 27 | #include "platform/NonCopyable.h" |
saloutos | 0:083111ae2a11 | 28 | |
saloutos | 0:083111ae2a11 | 29 | namespace mbed { |
saloutos | 0:083111ae2a11 | 30 | /** \addtogroup drivers */ |
saloutos | 0:083111ae2a11 | 31 | |
saloutos | 0:083111ae2a11 | 32 | /** A serial port (UART) for communication with other serial devices |
saloutos | 0:083111ae2a11 | 33 | * |
saloutos | 0:083111ae2a11 | 34 | * Can be used for Full Duplex communication, or Simplex by specifying |
saloutos | 0:083111ae2a11 | 35 | * one pin as NC (Not Connected) |
saloutos | 0:083111ae2a11 | 36 | * |
saloutos | 0:083111ae2a11 | 37 | * @note Synchronization level: Thread safe |
saloutos | 0:083111ae2a11 | 38 | * |
saloutos | 0:083111ae2a11 | 39 | * Example: |
saloutos | 0:083111ae2a11 | 40 | * @code |
saloutos | 0:083111ae2a11 | 41 | * // Print "Hello World" to the PC |
saloutos | 0:083111ae2a11 | 42 | * |
saloutos | 0:083111ae2a11 | 43 | * #include "mbed.h" |
saloutos | 0:083111ae2a11 | 44 | * |
saloutos | 0:083111ae2a11 | 45 | * Serial pc(USBTX, USBRX); |
saloutos | 0:083111ae2a11 | 46 | * |
saloutos | 0:083111ae2a11 | 47 | * int main() { |
saloutos | 0:083111ae2a11 | 48 | * pc.printf("Hello World\n"); |
saloutos | 0:083111ae2a11 | 49 | * } |
saloutos | 0:083111ae2a11 | 50 | * @endcode |
saloutos | 0:083111ae2a11 | 51 | * @ingroup drivers |
saloutos | 0:083111ae2a11 | 52 | */ |
saloutos | 0:083111ae2a11 | 53 | class Serial : public SerialBase, public Stream, private NonCopyable<Serial> { |
saloutos | 0:083111ae2a11 | 54 | |
saloutos | 0:083111ae2a11 | 55 | public: |
saloutos | 0:083111ae2a11 | 56 | #if DEVICE_SERIAL_ASYNCH |
saloutos | 0:083111ae2a11 | 57 | using SerialBase::read; |
saloutos | 0:083111ae2a11 | 58 | using SerialBase::write; |
saloutos | 0:083111ae2a11 | 59 | #endif |
saloutos | 0:083111ae2a11 | 60 | |
saloutos | 0:083111ae2a11 | 61 | /** Create a Serial port, connected to the specified transmit and receive pins |
saloutos | 0:083111ae2a11 | 62 | * |
saloutos | 0:083111ae2a11 | 63 | * @param tx Transmit pin |
saloutos | 0:083111ae2a11 | 64 | * @param rx Receive pin |
saloutos | 0:083111ae2a11 | 65 | * @param name The name of the stream associated with this serial port (optional) |
saloutos | 0:083111ae2a11 | 66 | * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) |
saloutos | 0:083111ae2a11 | 67 | * |
saloutos | 0:083111ae2a11 | 68 | * @note |
saloutos | 0:083111ae2a11 | 69 | * Either tx or rx may be specified as NC if unused |
saloutos | 0:083111ae2a11 | 70 | */ |
saloutos | 0:083111ae2a11 | 71 | Serial(PinName tx, PinName rx, const char *name=NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); |
saloutos | 0:083111ae2a11 | 72 | |
saloutos | 0:083111ae2a11 | 73 | |
saloutos | 0:083111ae2a11 | 74 | /** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud |
saloutos | 0:083111ae2a11 | 75 | * |
saloutos | 0:083111ae2a11 | 76 | * @param tx Transmit pin |
saloutos | 0:083111ae2a11 | 77 | * @param rx Receive pin |
saloutos | 0:083111ae2a11 | 78 | * @param baud The baud rate of the serial port |
saloutos | 0:083111ae2a11 | 79 | * |
saloutos | 0:083111ae2a11 | 80 | * @note |
saloutos | 0:083111ae2a11 | 81 | * Either tx or rx may be specified as NC if unused |
saloutos | 0:083111ae2a11 | 82 | */ |
saloutos | 0:083111ae2a11 | 83 | Serial(PinName tx, PinName rx, int baud); |
saloutos | 0:083111ae2a11 | 84 | |
saloutos | 0:083111ae2a11 | 85 | /* Stream gives us a FileHandle with non-functional poll()/readable()/writable. Pass through |
saloutos | 0:083111ae2a11 | 86 | * the calls from the SerialBase instead for backwards compatibility. This problem is |
saloutos | 0:083111ae2a11 | 87 | * part of why Stream and Serial should be deprecated. |
saloutos | 0:083111ae2a11 | 88 | */ |
saloutos | 0:083111ae2a11 | 89 | bool readable() |
saloutos | 0:083111ae2a11 | 90 | { |
saloutos | 0:083111ae2a11 | 91 | return SerialBase::readable(); |
saloutos | 0:083111ae2a11 | 92 | } |
saloutos | 0:083111ae2a11 | 93 | bool writable() |
saloutos | 0:083111ae2a11 | 94 | { |
saloutos | 0:083111ae2a11 | 95 | return SerialBase::writeable(); |
saloutos | 0:083111ae2a11 | 96 | } |
saloutos | 0:083111ae2a11 | 97 | bool writeable() |
saloutos | 0:083111ae2a11 | 98 | { |
saloutos | 0:083111ae2a11 | 99 | return SerialBase::writeable(); |
saloutos | 0:083111ae2a11 | 100 | } |
saloutos | 0:083111ae2a11 | 101 | |
saloutos | 0:083111ae2a11 | 102 | protected: |
saloutos | 0:083111ae2a11 | 103 | virtual int _getc(); |
saloutos | 0:083111ae2a11 | 104 | virtual int _putc(int c); |
saloutos | 0:083111ae2a11 | 105 | virtual void lock(); |
saloutos | 0:083111ae2a11 | 106 | virtual void unlock(); |
saloutos | 0:083111ae2a11 | 107 | |
saloutos | 0:083111ae2a11 | 108 | PlatformMutex _mutex; |
saloutos | 0:083111ae2a11 | 109 | }; |
saloutos | 0:083111ae2a11 | 110 | |
saloutos | 0:083111ae2a11 | 111 | } // namespace mbed |
saloutos | 0:083111ae2a11 | 112 | |
saloutos | 0:083111ae2a11 | 113 | #endif |
saloutos | 0:083111ae2a11 | 114 | |
saloutos | 0:083111ae2a11 | 115 | #endif |