|
| 1 | +/* |
| 2 | + HardwareSerial.cpp - Hardware serial library for Wiring |
| 3 | + Copyright (c) 2006 Nicholas Zambetti. All right reserved. |
| 4 | +
|
| 5 | + This library is free software; you can redistribute it and/or |
| 6 | + modify it under the terms of the GNU Lesser General Public |
| 7 | + License as published by the Free Software Foundation; either |
| 8 | + version 2.1 of the License, or (at your option) any later version. |
| 9 | +
|
| 10 | + This library is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + Lesser General Public License for more details. |
| 14 | +
|
| 15 | + You should have received a copy of the GNU Lesser General Public |
| 16 | + License along with this library; if not, write to the Free Software |
| 17 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | + |
| 19 | + Modified 23 November 2006 by David A. Mellis |
| 20 | + Modified 28 September 2010 by Mark Sproul |
| 21 | + Modified 14 August 2012 by Alarus |
| 22 | + Modified 3 December 2013 by Matthijs Kooijman |
| 23 | +*/ |
| 24 | + |
| 25 | +#include "Arduino.h" |
| 26 | +#include "HardwareSerial.h" |
| 27 | + |
| 28 | +// SerialEvent functions are weak, so when the user doesn't define them, |
| 29 | +// the linker just sets their address to 0 (which is checked below). |
| 30 | +// The Serialx_available is just a wrapper around Serialx.available(), |
| 31 | +// but we can refer to it weakly so we don't pull in the entire |
| 32 | +// HardwareSerial instance if the user doesn't also refer to it. |
| 33 | + |
| 34 | +void serialEvent() __attribute__((weak)); |
| 35 | +bool SerialUSB_empty() __attribute__((weak)); |
| 36 | + |
| 37 | +void serial1Event() __attribute__((weak)); |
| 38 | +bool Serial1_empty() __attribute__((weak)); |
| 39 | + |
| 40 | +#if SERIAL_INTERFACES_COUNT > 1 |
| 41 | + |
| 42 | +void serial2Event() __attribute__((weak)); |
| 43 | +bool Serial2_empty() __attribute__((weak)); |
| 44 | + |
| 45 | +#endif |
| 46 | + |
| 47 | +#if SERIAL_INTERFACES_COUNT > 2 |
| 48 | + |
| 49 | +void serial3Event() __attribute__((weak)); |
| 50 | +bool Serial3_empty() __attribute__((weak)); |
| 51 | + |
| 52 | +#endif |
| 53 | + |
| 54 | +#if SERIAL_INTERFACES_COUNT > 3 |
| 55 | + |
| 56 | +void serial4Event() __attribute__((weak)); |
| 57 | +bool Serial4_empty() __attribute__((weak)); |
| 58 | + |
| 59 | +#endif |
| 60 | + |
| 61 | +#if SERIAL_INTERFACES_COUNT > 4 |
| 62 | + |
| 63 | +void serial5Event() __attribute__((weak)); |
| 64 | +bool Serial5_empty() __attribute__((weak)); |
| 65 | + |
| 66 | +#endif |
| 67 | + |
| 68 | +void serialEventRun(void) |
| 69 | +{ |
| 70 | + if (serialEvent && SerialUSB_empty && !SerialUSB_empty()) { serialEvent(); } |
| 71 | + |
| 72 | + if (serial1Event && Serial1_empty && !Serial1_empty()) { serial1Event(); } |
| 73 | +#if SERIAL_INTERFACES_COUNT > 1 |
| 74 | + if (serial2Event && Serial2_empty && !Serial2_empty()) { serial2Event(); } |
| 75 | +#endif |
| 76 | +#if SERIAL_INTERFACES_COUNT > 2 |
| 77 | + if (serial3Event && Serial3_empty && !Serial3_empty()) { serial3Event(); } |
| 78 | +#endif |
| 79 | +#if SERIAL_INTERFACES_COUNT > 3 |
| 80 | + if (serial4Event && Serial4_empty && !Serial4_empty()) { serial4Event(); } |
| 81 | +#endif |
| 82 | +#if SERIAL_INTERFACES_COUNT > 4 |
| 83 | + if (serial5Event && Serial5_empty && !Serial5_empty()) { serial5Event(); } |
| 84 | +#endif |
| 85 | +#if SERIAL_INTERFACES_COUNT > 5 |
| 86 | + if (serial6Event && Serial6_empty && !Serial6_empty()) { serial6Event(); } |
| 87 | +#endif |
| 88 | +} |
0 commit comments