MySensors Library & Examples  2.3.2
AltSoftSerial.h
1 /* An Alternative Software Serial Library
2  * http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
3  * Copyright (c) 2014 PJRC.COM, LLC, Paul Stoffregen, [email protected]
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE.
22  */
23 
24 #ifndef AltSoftSerial_h
25 #define AltSoftSerial_h
26 
27 #include <inttypes.h>
28 
29 #if ARDUINO >= 100
30 #include "Arduino.h"
31 #else
32 #include "WProgram.h"
33 #include "pins_arduino.h"
34 #endif
35 
36 #if defined(__arm__) && defined(CORE_TEENSY)
37 #define ALTSS_BASE_FREQ F_BUS
38 #else
39 #define ALTSS_BASE_FREQ F_CPU
40 #endif
41 
43 class AltSoftSerial : public Stream
44 {
45 public:
46  AltSoftSerial() { }
48  {
49  end();
50  }
51  static void begin(uint32_t baud)
52  {
53  init((ALTSS_BASE_FREQ + baud / 2) / baud);
54  }
55  static void end();
56  int peek();
57  int read();
58  int available();
59 #if ARDUINO >= 100
60  size_t write(uint8_t byte)
61  {
62  writeByte(byte);
63  return 1;
64  }
65  void flush()
66  {
67  flushOutput();
68  }
69 #else
70  void write(uint8_t byte)
71  {
72  writeByte(byte);
73  }
74  void flush()
75  {
76  flushInput();
77  }
78 #endif
79  using Print::write;
80  static void flushInput();
81  static void flushOutput();
82  // for drop-in compatibility with NewSoftSerial, rxPin & txPin ignored
83  AltSoftSerial(uint8_t rxPin, uint8_t txPin, bool inverse = false)
84  {
85  (void)rxPin;
86  (void)txPin;
87  (void)inverse;
88  }
89  bool listen()
90  {
91  return false;
92  }
93  bool isListening()
94  {
95  return true;
96  }
97  bool overflow()
98  {
99  bool r = timing_error;
100  timing_error = false;
101  return r;
102  }
103  static int library_version()
104  {
105  return 1;
106  }
107  static void enable_timer0(bool enable)
108  {
109  (void)enable;
110  }
111  static bool timing_error;
112 private:
113  static void init(uint32_t cycles_per_bit);
114  static void writeByte(uint8_t byte);
115 };
116 
117 #endif
AltSoftSerial::read
int read()
read
AltSoftSerial::flushInput
static void flushInput()
flushInput
AltSoftSerial::overflow
bool overflow()
Definition: AltSoftSerial.h:97
AltSoftSerial::library_version
static int library_version()
Definition: AltSoftSerial.h:103
AltSoftSerial
Definition: AltSoftSerial.h:43
AltSoftSerial::write
void write(uint8_t byte)
Definition: AltSoftSerial.h:70
AltSoftSerial::flushOutput
static void flushOutput()
flushOutput
AltSoftSerial::listen
bool listen()
Definition: AltSoftSerial.h:89
AltSoftSerial::end
static void end()
end
AltSoftSerial::available
int available()
available
AltSoftSerial::AltSoftSerial
AltSoftSerial(uint8_t rxPin, uint8_t txPin, bool inverse=false)
Definition: AltSoftSerial.h:83
AltSoftSerial::begin
static void begin(uint32_t baud)
Definition: AltSoftSerial.h:51
AltSoftSerial::enable_timer0
static void enable_timer0(bool enable)
Definition: AltSoftSerial.h:107
AltSoftSerial::flush
void flush()
Definition: AltSoftSerial.h:74
AltSoftSerial::isListening
bool isListening()
Definition: AltSoftSerial.h:93
AltSoftSerial::timing_error
static bool timing_error
timing_error
Definition: AltSoftSerial.h:111
AltSoftSerial::~AltSoftSerial
~AltSoftSerial()
Definition: AltSoftSerial.h:47
AltSoftSerial::peek
int peek()
peek