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