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