diff options
| author | Cristian Maglie <c.maglie@bug.st> | 2013-11-14 19:52:00 +0100 | 
|---|---|---|
| committer | Cristian Maglie <c.maglie@bug.st> | 2013-11-15 12:54:59 +0100 | 
| commit | a5d1990afdd4d783b4623e4ced8833d3e1a764ae (patch) | |
| tree | 77a7cf76adb894a1b5787056835d3895c532c8ec /libraries/SoftwareSerial/SoftwareSerial.h | |
| parent | f0fa1fd39a6beef4e4fc4ad04b03033b8c16e4ba (diff) | |
Revert "SoftwareSerial library to the new format"
This reverts commit 38c3bbbd3c83eda057d4857635fbd78a4785c3a4.
Diffstat (limited to 'libraries/SoftwareSerial/SoftwareSerial.h')
| -rw-r--r-- | libraries/SoftwareSerial/SoftwareSerial.h | 112 | 
1 files changed, 112 insertions, 0 deletions
diff --git a/libraries/SoftwareSerial/SoftwareSerial.h b/libraries/SoftwareSerial/SoftwareSerial.h new file mode 100644 index 0000000..a6a60b5 --- /dev/null +++ b/libraries/SoftwareSerial/SoftwareSerial.h @@ -0,0 +1,112 @@ +/*
 +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 <inttypes.h>
 +#include <Stream.h>
 +
 +/******************************************************************************
 +* Definitions
 +******************************************************************************/
 +
 +#define _SS_MAX_RX_BUFF 64 // RX buffer size
 +#ifndef GCC_VERSION
 +#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
 +#endif
 +
 +class SoftwareSerial : public Stream
 +{
 +private:
 +  // per object data
 +  uint8_t _receivePin;
 +  uint8_t _receiveBitMask;
 +  volatile uint8_t *_receivePortRegister;
 +  uint8_t _transmitBitMask;
 +  volatile uint8_t *_transmitPortRegister;
 +
 +  uint16_t _rx_delay_centering;
 +  uint16_t _rx_delay_intrabit;
 +  uint16_t _rx_delay_stopbit;
 +  uint16_t _tx_delay;
 +
 +  uint16_t _buffer_overflow:1;
 +  uint16_t _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();
 +  uint8_t rx_pin_read();
 +  void tx_pin_write(uint8_t pin_state);
 +  void setTX(uint8_t transmitPin);
 +  void setRX(uint8_t receivePin);
 +
 +  // private static method for timing
 +  static inline void tunedDelay(uint16_t delay);
 +
 +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 size_t write(uint8_t byte);
 +  virtual int read();
 +  virtual int available();
 +  virtual void flush();
 +  
 +  using Print::write;
 +
 +  // public only for easy access by interrupt handlers
 +  static inline void handle_interrupt();
 +};
 +
 +// Arduino 0012 workaround
 +#undef int
 +#undef char
 +#undef long
 +#undef byte
 +#undef float
 +#undef abs
 +#undef round
 +
 +#endif
  | 
