mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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