MoJo / ER2_Robot_gnuarmeclipse_lpc1768-V2

Dependencies:   mbed

Committer:
joehatier
Date:
Fri May 24 10:57:58 2019 +0000
Revision:
1:96ef3513d0d5
Parent:
0:1a801a2a7b4b
Ligne;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joehatier 0:1a801a2a7b4b 1 /* mbed Microcontroller Library
joehatier 0:1a801a2a7b4b 2 * Copyright (c) 2006-2013 ARM Limited
joehatier 0:1a801a2a7b4b 3 *
joehatier 0:1a801a2a7b4b 4 * Licensed under the Apache License, Version 2.0 (the "License");
joehatier 0:1a801a2a7b4b 5 * you may not use this file except in compliance with the License.
joehatier 0:1a801a2a7b4b 6 * You may obtain a copy of the License at
joehatier 0:1a801a2a7b4b 7 *
joehatier 0:1a801a2a7b4b 8 * http://www.apache.org/licenses/LICENSE-2.0
joehatier 0:1a801a2a7b4b 9 *
joehatier 0:1a801a2a7b4b 10 * Unless required by applicable law or agreed to in writing, software
joehatier 0:1a801a2a7b4b 11 * distributed under the License is distributed on an "AS IS" BASIS,
joehatier 0:1a801a2a7b4b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
joehatier 0:1a801a2a7b4b 13 * See the License for the specific language governing permissions and
joehatier 0:1a801a2a7b4b 14 * limitations under the License.
joehatier 0:1a801a2a7b4b 15 */
joehatier 0:1a801a2a7b4b 16 #ifndef MBED_RAW_SERIAL_H
joehatier 0:1a801a2a7b4b 17 #define MBED_RAW_SERIAL_H
joehatier 0:1a801a2a7b4b 18
joehatier 0:1a801a2a7b4b 19 #include "platform/platform.h"
joehatier 0:1a801a2a7b4b 20
joehatier 0:1a801a2a7b4b 21 #if defined (DEVICE_SERIAL) || defined(DOXYGEN_ONLY)
joehatier 0:1a801a2a7b4b 22
joehatier 0:1a801a2a7b4b 23 #include "drivers/SerialBase.h"
joehatier 0:1a801a2a7b4b 24 #include "hal/serial_api.h"
joehatier 0:1a801a2a7b4b 25 #include "platform/NonCopyable.h"
joehatier 0:1a801a2a7b4b 26
joehatier 0:1a801a2a7b4b 27 namespace mbed {
joehatier 0:1a801a2a7b4b 28 /** \addtogroup drivers */
joehatier 0:1a801a2a7b4b 29
joehatier 0:1a801a2a7b4b 30 /** A serial port (UART) for communication with other serial devices
joehatier 0:1a801a2a7b4b 31 * This is a variation of the Serial class that doesn't use streams,
joehatier 0:1a801a2a7b4b 32 * thus making it safe to use in interrupt handlers with the RTOS.
joehatier 0:1a801a2a7b4b 33 *
joehatier 0:1a801a2a7b4b 34 * Can be used for Full Duplex communication, or Simplex by specifying
joehatier 0:1a801a2a7b4b 35 * one pin as NC (Not Connected)
joehatier 0:1a801a2a7b4b 36 *
joehatier 0:1a801a2a7b4b 37 * @note Synchronization level: Not protected
joehatier 0:1a801a2a7b4b 38 *
joehatier 0:1a801a2a7b4b 39 * Example:
joehatier 0:1a801a2a7b4b 40 * @code
joehatier 0:1a801a2a7b4b 41 * // Send a char to the PC
joehatier 0:1a801a2a7b4b 42 *
joehatier 0:1a801a2a7b4b 43 * #include "mbed.h"
joehatier 0:1a801a2a7b4b 44 *
joehatier 0:1a801a2a7b4b 45 * RawSerial pc(USBTX, USBRX);
joehatier 0:1a801a2a7b4b 46 *
joehatier 0:1a801a2a7b4b 47 * int main() {
joehatier 0:1a801a2a7b4b 48 * pc.putc('A');
joehatier 0:1a801a2a7b4b 49 * }
joehatier 0:1a801a2a7b4b 50 * @endcode
joehatier 0:1a801a2a7b4b 51 * @ingroup drivers
joehatier 0:1a801a2a7b4b 52 */
joehatier 0:1a801a2a7b4b 53 class RawSerial: public SerialBase, private NonCopyable<RawSerial> {
joehatier 0:1a801a2a7b4b 54
joehatier 0:1a801a2a7b4b 55 public:
joehatier 0:1a801a2a7b4b 56 /** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud.
joehatier 0:1a801a2a7b4b 57 *
joehatier 0:1a801a2a7b4b 58 * @param tx Transmit pin
joehatier 0:1a801a2a7b4b 59 * @param rx Receive pin
joehatier 0:1a801a2a7b4b 60 * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
joehatier 0:1a801a2a7b4b 61 *
joehatier 0:1a801a2a7b4b 62 * @note
joehatier 0:1a801a2a7b4b 63 * Either tx or rx may be specified as NC if unused
joehatier 0:1a801a2a7b4b 64 */
joehatier 0:1a801a2a7b4b 65 RawSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
joehatier 0:1a801a2a7b4b 66
joehatier 0:1a801a2a7b4b 67 /** Write a char to the serial port
joehatier 0:1a801a2a7b4b 68 *
joehatier 0:1a801a2a7b4b 69 * @param c The char to write
joehatier 0:1a801a2a7b4b 70 *
joehatier 0:1a801a2a7b4b 71 * @returns The written char or -1 if an error occurred
joehatier 0:1a801a2a7b4b 72 */
joehatier 0:1a801a2a7b4b 73 int putc(int c);
joehatier 0:1a801a2a7b4b 74
joehatier 0:1a801a2a7b4b 75 /** Read a char from the serial port
joehatier 0:1a801a2a7b4b 76 *
joehatier 0:1a801a2a7b4b 77 * @returns The char read from the serial port
joehatier 0:1a801a2a7b4b 78 */
joehatier 0:1a801a2a7b4b 79 int getc();
joehatier 0:1a801a2a7b4b 80
joehatier 0:1a801a2a7b4b 81 /** Write a string to the serial port
joehatier 0:1a801a2a7b4b 82 *
joehatier 0:1a801a2a7b4b 83 * @param str The string to write
joehatier 0:1a801a2a7b4b 84 *
joehatier 0:1a801a2a7b4b 85 * @returns 0 if the write succeeds, EOF for error
joehatier 0:1a801a2a7b4b 86 */
joehatier 0:1a801a2a7b4b 87 int puts(const char *str);
joehatier 0:1a801a2a7b4b 88
joehatier 0:1a801a2a7b4b 89 int printf(const char *format, ...);
joehatier 0:1a801a2a7b4b 90
joehatier 0:1a801a2a7b4b 91 #if !(DOXYGEN_ONLY)
joehatier 0:1a801a2a7b4b 92 protected:
joehatier 0:1a801a2a7b4b 93
joehatier 0:1a801a2a7b4b 94 /* Acquire exclusive access to this serial port
joehatier 0:1a801a2a7b4b 95 */
joehatier 0:1a801a2a7b4b 96 virtual void lock(void);
joehatier 0:1a801a2a7b4b 97
joehatier 0:1a801a2a7b4b 98 /* Release exclusive access to this serial port
joehatier 0:1a801a2a7b4b 99 */
joehatier 0:1a801a2a7b4b 100 virtual void unlock(void);
joehatier 0:1a801a2a7b4b 101 #endif
joehatier 0:1a801a2a7b4b 102 };
joehatier 0:1a801a2a7b4b 103
joehatier 0:1a801a2a7b4b 104 } // namespace mbed
joehatier 0:1a801a2a7b4b 105
joehatier 0:1a801a2a7b4b 106 #endif
joehatier 0:1a801a2a7b4b 107
joehatier 0:1a801a2a7b4b 108 #endif