BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Committer:
gustavatmel
Date:
Tue May 01 15:47:08 2018 +0000
Revision:
1:9c5af431a1f1
sdf

Who changed what in which revision?

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