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