mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
drivers/RawSerial.h@167:e84263d55307, 2017-06-21 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Jun 21 17:46:44 2017 +0100
- Revision:
- 167:e84263d55307
- Parent:
- 149:156823d33999
- Child:
- 168:9672193075cf
This updates the lib to the mbed lib v 145
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_RAW_SERIAL_H |
<> | 149:156823d33999 | 17 | #define MBED_RAW_SERIAL_H |
<> | 149:156823d33999 | 18 | |
<> | 149:156823d33999 | 19 | #include "platform/platform.h" |
<> | 149:156823d33999 | 20 | |
AnnaBridge | 167:e84263d55307 | 21 | #if defined (DEVICE_SERIAL) || defined(DOXYGEN_ONLY) |
<> | 149:156823d33999 | 22 | |
<> | 149:156823d33999 | 23 | #include "drivers/SerialBase.h" |
<> | 149:156823d33999 | 24 | #include "hal/serial_api.h" |
<> | 149:156823d33999 | 25 | |
<> | 149:156823d33999 | 26 | namespace mbed { |
<> | 149:156823d33999 | 27 | /** \addtogroup drivers */ |
<> | 149:156823d33999 | 28 | |
<> | 149:156823d33999 | 29 | /** A serial port (UART) for communication with other serial devices |
<> | 149:156823d33999 | 30 | * This is a variation of the Serial class that doesn't use streams, |
<> | 149:156823d33999 | 31 | * thus making it safe to use in interrupt handlers with the RTOS. |
<> | 149:156823d33999 | 32 | * |
<> | 149:156823d33999 | 33 | * Can be used for Full Duplex communication, or Simplex by specifying |
<> | 149:156823d33999 | 34 | * one pin as NC (Not Connected) |
<> | 149:156823d33999 | 35 | * |
AnnaBridge | 167:e84263d55307 | 36 | * @note Synchronization level: Not protected |
<> | 149:156823d33999 | 37 | * |
<> | 149:156823d33999 | 38 | * Example: |
<> | 149:156823d33999 | 39 | * @code |
<> | 149:156823d33999 | 40 | * // Send a char to the PC |
<> | 149:156823d33999 | 41 | * |
<> | 149:156823d33999 | 42 | * #include "mbed.h" |
<> | 149:156823d33999 | 43 | * |
<> | 149:156823d33999 | 44 | * RawSerial pc(USBTX, USBRX); |
<> | 149:156823d33999 | 45 | * |
<> | 149:156823d33999 | 46 | * int main() { |
<> | 149:156823d33999 | 47 | * pc.putc('A'); |
<> | 149:156823d33999 | 48 | * } |
<> | 149:156823d33999 | 49 | * @endcode |
AnnaBridge | 167:e84263d55307 | 50 | * @ingroup drivers |
<> | 149:156823d33999 | 51 | */ |
<> | 149:156823d33999 | 52 | class RawSerial: public SerialBase { |
<> | 149:156823d33999 | 53 | |
<> | 149:156823d33999 | 54 | public: |
<> | 149:156823d33999 | 55 | /** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud. |
<> | 149:156823d33999 | 56 | * |
<> | 149:156823d33999 | 57 | * @param tx Transmit pin |
<> | 149:156823d33999 | 58 | * @param rx Receive pin |
<> | 149:156823d33999 | 59 | * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) |
<> | 149:156823d33999 | 60 | * |
<> | 149:156823d33999 | 61 | * @note |
<> | 149:156823d33999 | 62 | * Either tx or rx may be specified as NC if unused |
<> | 149:156823d33999 | 63 | */ |
<> | 149:156823d33999 | 64 | RawSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); |
<> | 149:156823d33999 | 65 | |
<> | 149:156823d33999 | 66 | /** Write a char to the serial port |
<> | 149:156823d33999 | 67 | * |
<> | 149:156823d33999 | 68 | * @param c The char to write |
<> | 149:156823d33999 | 69 | * |
<> | 149:156823d33999 | 70 | * @returns The written char or -1 if an error occured |
<> | 149:156823d33999 | 71 | */ |
<> | 149:156823d33999 | 72 | int putc(int c); |
<> | 149:156823d33999 | 73 | |
<> | 149:156823d33999 | 74 | /** Read a char from the serial port |
<> | 149:156823d33999 | 75 | * |
<> | 149:156823d33999 | 76 | * @returns The char read from the serial port |
<> | 149:156823d33999 | 77 | */ |
<> | 149:156823d33999 | 78 | int getc(); |
<> | 149:156823d33999 | 79 | |
<> | 149:156823d33999 | 80 | /** Write a string to the serial port |
<> | 149:156823d33999 | 81 | * |
<> | 149:156823d33999 | 82 | * @param str The string to write |
<> | 149:156823d33999 | 83 | * |
<> | 149:156823d33999 | 84 | * @returns 0 if the write succeeds, EOF for error |
<> | 149:156823d33999 | 85 | */ |
<> | 149:156823d33999 | 86 | int puts(const char *str); |
<> | 149:156823d33999 | 87 | |
<> | 149:156823d33999 | 88 | int printf(const char *format, ...); |
<> | 149:156823d33999 | 89 | |
<> | 149:156823d33999 | 90 | protected: |
<> | 149:156823d33999 | 91 | |
AnnaBridge | 167:e84263d55307 | 92 | /* Acquire exclusive access to this serial port |
<> | 149:156823d33999 | 93 | */ |
<> | 149:156823d33999 | 94 | virtual void lock(void); |
<> | 149:156823d33999 | 95 | |
AnnaBridge | 167:e84263d55307 | 96 | /* Release exclusive access to this serial port |
<> | 149:156823d33999 | 97 | */ |
<> | 149:156823d33999 | 98 | virtual void unlock(void); |
<> | 149:156823d33999 | 99 | }; |
<> | 149:156823d33999 | 100 | |
<> | 149:156823d33999 | 101 | } // namespace mbed |
<> | 149:156823d33999 | 102 | |
<> | 149:156823d33999 | 103 | #endif |
<> | 149:156823d33999 | 104 | |
<> | 149:156823d33999 | 105 | #endif |