aboutsummaryrefslogtreecommitdiff
path: root/src/core/SoftwareSerial.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/SoftwareSerial.h')
-rw-r--r--src/core/SoftwareSerial.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/core/SoftwareSerial.h b/src/core/SoftwareSerial.h
new file mode 100644
index 0000000..fd6287d
--- /dev/null
+++ b/src/core/SoftwareSerial.h
@@ -0,0 +1,104 @@
+/*
+ * This class is porting arduino's SoftwareSerial for eXodusino
+ *
+ * Created on: 2012/03/17
+ * @author nucho
+ */
+
+/*
+ SoftwareSerial.h (formerly NewSoftSerial.h) -
+ Multi-instance software serial library for Arduino/Wiring
+ -- Interrupt-driven receive and other improvements by ladyada
+ (http://ladyada.net)
+ -- Tuning, circular buffer, derivation from class Print/Stream,
+ multi-instance support, porting to 8MHz processors,
+ various optimizations, PROGMEM delay tables, inverse logic and
+ direct port writing by Mikal Hart (http://www.arduiniana.org)
+ -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com)
+ -- 20MHz processor support by Garrett Mace (http://www.macetech.com)
+ -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+ The latest version of this library can always be found at
+ http://arduiniana.org.
+ */
+
+#ifndef SoftwareSerial_h
+#define SoftwareSerial_h
+
+#include "Print.h"
+#include "LPC11xx.h"
+
+/******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#define _SS_MAX_RX_BUFF 64 // RX buffer size
+class SoftwareSerial: public Print {
+private:
+ // per object data
+ uint8_t _receivePin;
+ uint8_t _transmitPin;
+
+ uint16_t _rx_delay_centering;
+ uint16_t _rx_delay_intrabit;
+ uint16_t _rx_delay_stopbit;
+ uint16_t _tx_delay;
+
+ bool _buffer_overflow :1;
+ bool _inverse_logic :1;
+
+ // static data
+ static char _receive_buffer[_SS_MAX_RX_BUFF];
+ static volatile uint8_t _receive_buffer_tail;
+ static volatile uint8_t _receive_buffer_head;
+ static SoftwareSerial *active_object;
+
+ // private methods
+ void recv();
+ void setTX(uint8_t transmitPin);
+ void setRX(uint8_t receivePin);
+
+public:
+ // public methods
+ SoftwareSerial(uint8_t receivePin, uint8_t transmitPin,
+ bool inverse_logic = false);
+
+ ~SoftwareSerial();
+ void begin(long speed);
+ bool listen();
+ void end();
+ bool isListening() {
+ return this == active_object;
+ }
+ bool overflow() {
+ bool ret = _buffer_overflow;
+ _buffer_overflow = false;
+ return ret;
+ }
+ int peek();
+
+ virtual void write(const char c);
+ int read();
+ int available();
+ void flush();
+
+ using Print::write;// pull in write(buf, size) from Print
+
+ // public only for easy access by interrupt handlers
+ static inline void handle_interrupt();
+};
+
+#endif