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