CDY version that shares functionality with Counter

Dependencies:   SDFileSystem_HelloWorld mbed FATFileSystem

Committer:
Charles David Young
Date:
Mon Nov 05 09:52:17 2018 -0700
Revision:
3:c547dba5d39b
Parent:
0:aa13e1c335cd
debug

Who changed what in which revision?

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