Arduino Serial + Serial base = less flash usage

Committer:
eveolution
Date:
Mon Aug 25 19:04:02 2014 +0000
Revision:
0:7b9f0f2e2724
Serial base + Arduino Serial code = less flash usage

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eveolution 0:7b9f0f2e2724 1 /* mbed Microcontroller Library
eveolution 0:7b9f0f2e2724 2 * Copyright (c) 2006-2013 ARM Limited
eveolution 0:7b9f0f2e2724 3 *
eveolution 0:7b9f0f2e2724 4 * Licensed under the Apache License, Version 2.0 (the "License");
eveolution 0:7b9f0f2e2724 5 * you may not use this file except in compliance with the License.
eveolution 0:7b9f0f2e2724 6 * You may obtain a copy of the License at
eveolution 0:7b9f0f2e2724 7 *
eveolution 0:7b9f0f2e2724 8 * http://www.apache.org/licenses/LICENSE-2.0
eveolution 0:7b9f0f2e2724 9 *
eveolution 0:7b9f0f2e2724 10 * Unless required by applicable law or agreed to in writing, software
eveolution 0:7b9f0f2e2724 11 * distributed under the License is distributed on an "AS IS" BASIS,
eveolution 0:7b9f0f2e2724 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
eveolution 0:7b9f0f2e2724 13 * See the License for the specific language governing permissions and
eveolution 0:7b9f0f2e2724 14 * limitations under the License.
eveolution 0:7b9f0f2e2724 15 */
eveolution 0:7b9f0f2e2724 16
eveolution 0:7b9f0f2e2724 17 /*
eveolution 0:7b9f0f2e2724 18 Print.cpp - Base class that provides print() and println()
eveolution 0:7b9f0f2e2724 19 Copyright (c) 2008 David A. Mellis. All right reserved.
eveolution 0:7b9f0f2e2724 20
eveolution 0:7b9f0f2e2724 21 This library is free software; you can redistribute it and/or
eveolution 0:7b9f0f2e2724 22 modify it under the terms of the GNU Lesser General Public
eveolution 0:7b9f0f2e2724 23 License as published by the Free Software Foundation; either
eveolution 0:7b9f0f2e2724 24 version 2.1 of the License, or (at your option) any later version.
eveolution 0:7b9f0f2e2724 25
eveolution 0:7b9f0f2e2724 26 This library is distributed in the hope that it will be useful,
eveolution 0:7b9f0f2e2724 27 but WITHOUT ANY WARRANTY; without even the implied warranty of
eveolution 0:7b9f0f2e2724 28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
eveolution 0:7b9f0f2e2724 29 Lesser General Public License for more details.
eveolution 0:7b9f0f2e2724 30
eveolution 0:7b9f0f2e2724 31 You should have received a copy of the GNU Lesser General Public
eveolution 0:7b9f0f2e2724 32 License along with this library; if not, write to the Free Software
eveolution 0:7b9f0f2e2724 33 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
eveolution 0:7b9f0f2e2724 34
eveolution 0:7b9f0f2e2724 35 Modified 23 November 2006 by David A. Mellis
eveolution 0:7b9f0f2e2724 36 */
eveolution 0:7b9f0f2e2724 37
eveolution 0:7b9f0f2e2724 38 #ifndef arduino_SERIAL_H
eveolution 0:7b9f0f2e2724 39 #define arduino_SERIAL_H
eveolution 0:7b9f0f2e2724 40
eveolution 0:7b9f0f2e2724 41 #include "mbed.h"
eveolution 0:7b9f0f2e2724 42 #include "platform.h"
eveolution 0:7b9f0f2e2724 43
eveolution 0:7b9f0f2e2724 44 #if DEVICE_SERIAL
eveolution 0:7b9f0f2e2724 45
eveolution 0:7b9f0f2e2724 46 #include "SerialBase.h"
eveolution 0:7b9f0f2e2724 47 #include "serial_api.h"
eveolution 0:7b9f0f2e2724 48
eveolution 0:7b9f0f2e2724 49 #define DEC 10
eveolution 0:7b9f0f2e2724 50 #define HEX 16
eveolution 0:7b9f0f2e2724 51 #define OCT 8
eveolution 0:7b9f0f2e2724 52 #define BIN 2
eveolution 0:7b9f0f2e2724 53
eveolution 0:7b9f0f2e2724 54 //namespace mbed {
eveolution 0:7b9f0f2e2724 55
eveolution 0:7b9f0f2e2724 56 /** A serial port (UART) for communication with other serial devices
eveolution 0:7b9f0f2e2724 57 * This is a variation of the Serial class that doesn't use streams,
eveolution 0:7b9f0f2e2724 58 * thus making it safe to use in interrupt handlers with the RTOS.
eveolution 0:7b9f0f2e2724 59 *
eveolution 0:7b9f0f2e2724 60 * Can be used for Full Duplex communication, or Simplex by specifying
eveolution 0:7b9f0f2e2724 61 * one pin as NC (Not Connected)
eveolution 0:7b9f0f2e2724 62 *
eveolution 0:7b9f0f2e2724 63 * Example:
eveolution 0:7b9f0f2e2724 64 * @code
eveolution 0:7b9f0f2e2724 65 * // Send a char to the PC
eveolution 0:7b9f0f2e2724 66 *
eveolution 0:7b9f0f2e2724 67 * #include "mbed.h"
eveolution 0:7b9f0f2e2724 68 *
eveolution 0:7b9f0f2e2724 69 * RawSerial pc(USBTX, USBRX);
eveolution 0:7b9f0f2e2724 70 *
eveolution 0:7b9f0f2e2724 71 * int main() {
eveolution 0:7b9f0f2e2724 72 * pc.putc('A');
eveolution 0:7b9f0f2e2724 73 * }
eveolution 0:7b9f0f2e2724 74 * @endcode
eveolution 0:7b9f0f2e2724 75 */
eveolution 0:7b9f0f2e2724 76 class ardSerial: public mbed::SerialBase {
eveolution 0:7b9f0f2e2724 77
eveolution 0:7b9f0f2e2724 78 public:
eveolution 0:7b9f0f2e2724 79 /** Create a RawSerial port, connected to the specified transmit and receive pins
eveolution 0:7b9f0f2e2724 80 *
eveolution 0:7b9f0f2e2724 81 * @param tx Transmit pin
eveolution 0:7b9f0f2e2724 82 * @param rx Receive pin
eveolution 0:7b9f0f2e2724 83 *
eveolution 0:7b9f0f2e2724 84 * @note
eveolution 0:7b9f0f2e2724 85 * Either tx or rx may be specified as NC if unused
eveolution 0:7b9f0f2e2724 86 */
eveolution 0:7b9f0f2e2724 87 ardSerial(PinName tx, PinName rx);
eveolution 0:7b9f0f2e2724 88
eveolution 0:7b9f0f2e2724 89 /** Write a char to the serial port
eveolution 0:7b9f0f2e2724 90 *
eveolution 0:7b9f0f2e2724 91 * @param c The char to write
eveolution 0:7b9f0f2e2724 92 *
eveolution 0:7b9f0f2e2724 93 * @returns The written char or -1 if an error occured
eveolution 0:7b9f0f2e2724 94 */
eveolution 0:7b9f0f2e2724 95 int putc(int c);
eveolution 0:7b9f0f2e2724 96
eveolution 0:7b9f0f2e2724 97 /** Read a char from the serial port
eveolution 0:7b9f0f2e2724 98 *
eveolution 0:7b9f0f2e2724 99 * @returns The char read from the serial port
eveolution 0:7b9f0f2e2724 100 */
eveolution 0:7b9f0f2e2724 101 int getc();
eveolution 0:7b9f0f2e2724 102
eveolution 0:7b9f0f2e2724 103 /** Write a string to the serial port
eveolution 0:7b9f0f2e2724 104 *
eveolution 0:7b9f0f2e2724 105 * @param str The string to write
eveolution 0:7b9f0f2e2724 106 *
eveolution 0:7b9f0f2e2724 107 * @returns 0 if the write succeeds, EOF for error
eveolution 0:7b9f0f2e2724 108 */
eveolution 0:7b9f0f2e2724 109 int puts(const char *str);
eveolution 0:7b9f0f2e2724 110
eveolution 0:7b9f0f2e2724 111 //virtual int write(uint8_t) = 0;
eveolution 0:7b9f0f2e2724 112 int write(uint8_t);
eveolution 0:7b9f0f2e2724 113 int write(const char *str) {
eveolution 0:7b9f0f2e2724 114 if (str == NULL) return 0;
eveolution 0:7b9f0f2e2724 115 return write((const uint8_t *)str, strlen(str));
eveolution 0:7b9f0f2e2724 116 }
eveolution 0:7b9f0f2e2724 117 virtual int write(const uint8_t *buffer, size_t size);
eveolution 0:7b9f0f2e2724 118
eveolution 0:7b9f0f2e2724 119 int print(const char[]);
eveolution 0:7b9f0f2e2724 120 int print(char);
eveolution 0:7b9f0f2e2724 121 int print(unsigned char, int = DEC);
eveolution 0:7b9f0f2e2724 122 int print(int, int = DEC);
eveolution 0:7b9f0f2e2724 123 int print(unsigned int, int = DEC);
eveolution 0:7b9f0f2e2724 124 int print(long, int = DEC);
eveolution 0:7b9f0f2e2724 125 int print(unsigned long, int = DEC);
eveolution 0:7b9f0f2e2724 126 int print(double, int = 2);
eveolution 0:7b9f0f2e2724 127
eveolution 0:7b9f0f2e2724 128 int printNumber(unsigned long, uint8_t);
eveolution 0:7b9f0f2e2724 129 int printFloat(double, uint8_t);
eveolution 0:7b9f0f2e2724 130 };
eveolution 0:7b9f0f2e2724 131
eveolution 0:7b9f0f2e2724 132 //} // namespace mbed
eveolution 0:7b9f0f2e2724 133
eveolution 0:7b9f0f2e2724 134 #endif
eveolution 0:7b9f0f2e2724 135
eveolution 0:7b9f0f2e2724 136 #endif
eveolution 0:7b9f0f2e2724 137