|
| 1 | +/* |
| 2 | + Copyright (c) 2016 Arduino LLC. All right reserved. |
| 3 | +
|
| 4 | + This library is free software; you can redistribute it and/or |
| 5 | + modify it under the terms of the GNU Lesser General Public |
| 6 | + License as published by the Free Software Foundation; either |
| 7 | + version 2.1 of the License, or (at your option) any later version. |
| 8 | +
|
| 9 | + This library is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | + See the GNU Lesser General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU Lesser General Public |
| 15 | + License along with this library; if not, write to the Free Software |
| 16 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | +*/ |
| 18 | + |
| 19 | +#pragma once |
| 20 | + |
| 21 | +#include <inttypes.h> |
| 22 | +#include "Stream.h" |
| 23 | + |
| 24 | +// XXX: Those constants should be defined as const int / enums? |
| 25 | +// XXX: shall we use namespaces too? |
| 26 | +#define SERIAL_PARITY_EVEN (0x1ul) |
| 27 | +#define SERIAL_PARITY_ODD (0x2ul) |
| 28 | +#define SERIAL_PARITY_NONE (0x3ul) |
| 29 | +#define SERIAL_PARITY_MARK (0x4ul) |
| 30 | +#define SERIAL_PARITY_SPACE (0x5ul) |
| 31 | +#define SERIAL_PARITY_MASK (0xFul) |
| 32 | + |
| 33 | +#define SERIAL_STOP_BIT_1 (0x10ul) |
| 34 | +#define SERIAL_STOP_BIT_1_5 (0x20ul) |
| 35 | +#define SERIAL_STOP_BIT_2 (0x30ul) |
| 36 | +#define SERIAL_STOP_BIT_MASK (0xF0ul) |
| 37 | + |
| 38 | +#define SERIAL_DATA_5 (0x100ul) |
| 39 | +#define SERIAL_DATA_6 (0x200ul) |
| 40 | +#define SERIAL_DATA_7 (0x300ul) |
| 41 | +#define SERIAL_DATA_8 (0x400ul) |
| 42 | +#define SERIAL_DATA_MASK (0xF00ul) |
| 43 | + |
| 44 | +#define SERIAL_5N1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_NONE | SERIAL_DATA_5) |
| 45 | +#define SERIAL_6N1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_NONE | SERIAL_DATA_6) |
| 46 | +#define SERIAL_7N1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_NONE | SERIAL_DATA_7) |
| 47 | +#define SERIAL_8N1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_NONE | SERIAL_DATA_8) |
| 48 | +#define SERIAL_5N2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_NONE | SERIAL_DATA_5) |
| 49 | +#define SERIAL_6N2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_NONE | SERIAL_DATA_6) |
| 50 | +#define SERIAL_7N2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_NONE | SERIAL_DATA_7) |
| 51 | +#define SERIAL_8N2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_NONE | SERIAL_DATA_8) |
| 52 | +#define SERIAL_5E1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_EVEN | SERIAL_DATA_5) |
| 53 | +#define SERIAL_6E1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_EVEN | SERIAL_DATA_6) |
| 54 | +#define SERIAL_7E1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_EVEN | SERIAL_DATA_7) |
| 55 | +#define SERIAL_8E1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_EVEN | SERIAL_DATA_8) |
| 56 | +#define SERIAL_5E2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_EVEN | SERIAL_DATA_5) |
| 57 | +#define SERIAL_6E2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_EVEN | SERIAL_DATA_6) |
| 58 | +#define SERIAL_7E2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_EVEN | SERIAL_DATA_7) |
| 59 | +#define SERIAL_8E2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_EVEN | SERIAL_DATA_8) |
| 60 | +#define SERIAL_5O1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_ODD | SERIAL_DATA_5) |
| 61 | +#define SERIAL_6O1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_ODD | SERIAL_DATA_6) |
| 62 | +#define SERIAL_7O1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_ODD | SERIAL_DATA_7) |
| 63 | +#define SERIAL_8O1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_ODD | SERIAL_DATA_8) |
| 64 | +#define SERIAL_5O2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_ODD | SERIAL_DATA_5) |
| 65 | +#define SERIAL_6O2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_ODD | SERIAL_DATA_6) |
| 66 | +#define SERIAL_7O2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_ODD | SERIAL_DATA_7) |
| 67 | +#define SERIAL_8O2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_ODD | SERIAL_DATA_8) |
| 68 | +#define SERIAL_5M1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_MARK | SERIAL_DATA_5) |
| 69 | +#define SERIAL_6M1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_MARK | SERIAL_DATA_6) |
| 70 | +#define SERIAL_7M1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_MARK | SERIAL_DATA_7) |
| 71 | +#define SERIAL_8M1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_MARK | SERIAL_DATA_8) |
| 72 | +#define SERIAL_5M2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_MARK | SERIAL_DATA_5) |
| 73 | +#define SERIAL_6M2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_MARK | SERIAL_DATA_6) |
| 74 | +#define SERIAL_7M2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_MARK | SERIAL_DATA_7) |
| 75 | +#define SERIAL_8M2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_MARK | SERIAL_DATA_8) |
| 76 | +#define SERIAL_5S1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_SPACE | SERIAL_DATA_5) |
| 77 | +#define SERIAL_6S1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_SPACE | SERIAL_DATA_6) |
| 78 | +#define SERIAL_7S1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_SPACE | SERIAL_DATA_7) |
| 79 | +#define SERIAL_8S1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_SPACE | SERIAL_DATA_8) |
| 80 | +#define SERIAL_5S2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_SPACE | SERIAL_DATA_5) |
| 81 | +#define SERIAL_6S2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_SPACE | SERIAL_DATA_6) |
| 82 | +#define SERIAL_7S2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_SPACE | SERIAL_DATA_7) |
| 83 | +#define SERIAL_8S2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_SPACE | SERIAL_DATA_8) |
| 84 | + |
| 85 | +class HardwareSerial : public Stream |
| 86 | +{ |
| 87 | + public: |
| 88 | + virtual void begin(unsigned long) = 0; |
| 89 | + virtual void begin(unsigned long baudrate, uint16_t config) = 0; |
| 90 | + virtual void end() = 0; |
| 91 | + virtual int available(void) = 0; |
| 92 | + virtual int peek(void) = 0; |
| 93 | + virtual int read(void) = 0; |
| 94 | + virtual void flush(void) = 0; |
| 95 | + virtual size_t write(uint8_t) = 0; |
| 96 | + using Print::write; // pull in write(str) and write(buf, size) from Print |
| 97 | + virtual operator bool() = 0; |
| 98 | +}; |
| 99 | + |
| 100 | +// XXX: Are we keeping the serialEvent API? |
| 101 | +extern void serialEventRun(void) __attribute__((weak)); |
| 102 | + |
0 commit comments