Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: STM32F031_Blink_Aug17
Fork of mbed-STM32F030F4 by
api/RawSerial.h@0:38ccae254a29, 2014-10-18 (annotated)
- Committer:
- mega64
- Date:
- Sat Oct 18 02:40:17 2014 +0000
- Revision:
- 0:38ccae254a29
only for STM32F030F4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mega64 | 0:38ccae254a29 | 1 | /* mbed Microcontroller Library |
mega64 | 0:38ccae254a29 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mega64 | 0:38ccae254a29 | 3 | * |
mega64 | 0:38ccae254a29 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mega64 | 0:38ccae254a29 | 5 | * you may not use this file except in compliance with the License. |
mega64 | 0:38ccae254a29 | 6 | * You may obtain a copy of the License at |
mega64 | 0:38ccae254a29 | 7 | * |
mega64 | 0:38ccae254a29 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mega64 | 0:38ccae254a29 | 9 | * |
mega64 | 0:38ccae254a29 | 10 | * Unless required by applicable law or agreed to in writing, software |
mega64 | 0:38ccae254a29 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mega64 | 0:38ccae254a29 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mega64 | 0:38ccae254a29 | 13 | * See the License for the specific language governing permissions and |
mega64 | 0:38ccae254a29 | 14 | * limitations under the License. |
mega64 | 0:38ccae254a29 | 15 | */ |
mega64 | 0:38ccae254a29 | 16 | #ifndef MBED_RAW_SERIAL_H |
mega64 | 0:38ccae254a29 | 17 | #define MBED_RAW_SERIAL_H |
mega64 | 0:38ccae254a29 | 18 | |
mega64 | 0:38ccae254a29 | 19 | #include "platform.h" |
mega64 | 0:38ccae254a29 | 20 | |
mega64 | 0:38ccae254a29 | 21 | #if DEVICE_SERIAL |
mega64 | 0:38ccae254a29 | 22 | |
mega64 | 0:38ccae254a29 | 23 | #include "SerialBase.h" |
mega64 | 0:38ccae254a29 | 24 | #include "serial_api.h" |
mega64 | 0:38ccae254a29 | 25 | |
mega64 | 0:38ccae254a29 | 26 | namespace mbed { |
mega64 | 0:38ccae254a29 | 27 | |
mega64 | 0:38ccae254a29 | 28 | /** A serial port (UART) for communication with other serial devices |
mega64 | 0:38ccae254a29 | 29 | * This is a variation of the Serial class that doesn't use streams, |
mega64 | 0:38ccae254a29 | 30 | * thus making it safe to use in interrupt handlers with the RTOS. |
mega64 | 0:38ccae254a29 | 31 | * |
mega64 | 0:38ccae254a29 | 32 | * Can be used for Full Duplex communication, or Simplex by specifying |
mega64 | 0:38ccae254a29 | 33 | * one pin as NC (Not Connected) |
mega64 | 0:38ccae254a29 | 34 | * |
mega64 | 0:38ccae254a29 | 35 | * Example: |
mega64 | 0:38ccae254a29 | 36 | * @code |
mega64 | 0:38ccae254a29 | 37 | * // Send a char to the PC |
mega64 | 0:38ccae254a29 | 38 | * |
mega64 | 0:38ccae254a29 | 39 | * #include "mbed.h" |
mega64 | 0:38ccae254a29 | 40 | * |
mega64 | 0:38ccae254a29 | 41 | * RawSerial pc(USBTX, USBRX); |
mega64 | 0:38ccae254a29 | 42 | * |
mega64 | 0:38ccae254a29 | 43 | * int main() { |
mega64 | 0:38ccae254a29 | 44 | * pc.putc('A'); |
mega64 | 0:38ccae254a29 | 45 | * } |
mega64 | 0:38ccae254a29 | 46 | * @endcode |
mega64 | 0:38ccae254a29 | 47 | */ |
mega64 | 0:38ccae254a29 | 48 | class RawSerial: public SerialBase { |
mega64 | 0:38ccae254a29 | 49 | |
mega64 | 0:38ccae254a29 | 50 | public: |
mega64 | 0:38ccae254a29 | 51 | /** Create a RawSerial port, connected to the specified transmit and receive pins |
mega64 | 0:38ccae254a29 | 52 | * |
mega64 | 0:38ccae254a29 | 53 | * @param tx Transmit pin |
mega64 | 0:38ccae254a29 | 54 | * @param rx Receive pin |
mega64 | 0:38ccae254a29 | 55 | * |
mega64 | 0:38ccae254a29 | 56 | * @note |
mega64 | 0:38ccae254a29 | 57 | * Either tx or rx may be specified as NC if unused |
mega64 | 0:38ccae254a29 | 58 | */ |
mega64 | 0:38ccae254a29 | 59 | RawSerial(PinName tx, PinName rx); |
mega64 | 0:38ccae254a29 | 60 | |
mega64 | 0:38ccae254a29 | 61 | /** Write a char to the serial port |
mega64 | 0:38ccae254a29 | 62 | * |
mega64 | 0:38ccae254a29 | 63 | * @param c The char to write |
mega64 | 0:38ccae254a29 | 64 | * |
mega64 | 0:38ccae254a29 | 65 | * @returns The written char or -1 if an error occured |
mega64 | 0:38ccae254a29 | 66 | */ |
mega64 | 0:38ccae254a29 | 67 | int putc(int c); |
mega64 | 0:38ccae254a29 | 68 | |
mega64 | 0:38ccae254a29 | 69 | /** Read a char from the serial port |
mega64 | 0:38ccae254a29 | 70 | * |
mega64 | 0:38ccae254a29 | 71 | * @returns The char read from the serial port |
mega64 | 0:38ccae254a29 | 72 | */ |
mega64 | 0:38ccae254a29 | 73 | int getc(); |
mega64 | 0:38ccae254a29 | 74 | |
mega64 | 0:38ccae254a29 | 75 | /** Write a string to the serial port |
mega64 | 0:38ccae254a29 | 76 | * |
mega64 | 0:38ccae254a29 | 77 | * @param str The string to write |
mega64 | 0:38ccae254a29 | 78 | * |
mega64 | 0:38ccae254a29 | 79 | * @returns 0 if the write succeeds, EOF for error |
mega64 | 0:38ccae254a29 | 80 | */ |
mega64 | 0:38ccae254a29 | 81 | int puts(const char *str); |
mega64 | 0:38ccae254a29 | 82 | |
mega64 | 0:38ccae254a29 | 83 | int printf(const char *format, ...); |
mega64 | 0:38ccae254a29 | 84 | }; |
mega64 | 0:38ccae254a29 | 85 | |
mega64 | 0:38ccae254a29 | 86 | } // namespace mbed |
mega64 | 0:38ccae254a29 | 87 | |
mega64 | 0:38ccae254a29 | 88 | #endif |
mega64 | 0:38ccae254a29 | 89 | |
mega64 | 0:38ccae254a29 | 90 | #endif |