The prosthetic control(MIT)

Committer:
ganlikun
Date:
Thu Jun 23 05:23:34 2022 +0000
Revision:
0:20e0c61e0684
01

Who changed what in which revision?

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