Commit 54e58bcf authored by Eric Duminil's avatar Eric Duminil
Browse files

Avoid name conflict

parent 7e48d847
...@@ -18,7 +18,7 @@ namespace config { ...@@ -18,7 +18,7 @@ namespace config {
} }
#if defined(ESP8266) #if defined(ESP8266)
# include "src/lib/Esp8266EdgeSoftwareSerial/SoftwareSerial.h" # include "src/lib/Esp8266EdgeSoftwareSerial/MySoftwareSerial.h"
# define S8_RX_PIN 13 // GPIO13, a.k.a. D7, connected to S8 Tx pin. # define S8_RX_PIN 13 // GPIO13, a.k.a. D7, connected to S8 Tx pin.
# define S8_TX_PIN 15 // GPIO15, a.k.a. D8, connected to S8 Rx pin. # define S8_TX_PIN 15 // GPIO15, a.k.a. D8, connected to S8 Rx pin.
SoftwareSerial S8_serial(S8_RX_PIN, S8_TX_PIN); SoftwareSerial S8_serial(S8_RX_PIN, S8_TX_PIN);
......
/* /*
SoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266. MySoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266.
Copyright (c) 2015-2016 Peter Lerup. All rights reserved. Copyright (c) 2015-2016 Peter Lerup. All rights reserved.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
...@@ -27,13 +27,13 @@ extern "C" { ...@@ -27,13 +27,13 @@ extern "C" {
#include "gpio.h" #include "gpio.h"
} }
#include "SoftwareSerial.h" #include "MySoftwareSerial.h"
#define MAX_PIN 15 #define MAX_PIN 15
// As the Arduino attachInterrupt has no parameter, lists of objects // As the Arduino attachInterrupt has no parameter, lists of objects
// and callbacks corresponding to each possible GPIO pins have to be defined // and callbacks corresponding to each possible GPIO pins have to be defined
SoftwareSerial *ObjList[MAX_PIN + 1]; MySoftwareSerial *ObjList[MAX_PIN + 1];
void ICACHE_RAM_ATTR sws_isr_0() { ObjList[0]->rxRead(); }; void ICACHE_RAM_ATTR sws_isr_0() { ObjList[0]->rxRead(); };
void ICACHE_RAM_ATTR sws_isr_1() { ObjList[1]->rxRead(); }; void ICACHE_RAM_ATTR sws_isr_1() { ObjList[1]->rxRead(); };
...@@ -68,7 +68,7 @@ static void(*ISRList[MAX_PIN + 1])() = { ...@@ -68,7 +68,7 @@ static void(*ISRList[MAX_PIN + 1])() = {
sws_isr_15 sws_isr_15
}; };
SoftwareSerial::SoftwareSerial(int receivePin, int transmitPin, bool inverse_logic, unsigned int buffSize, bool edge_triggered) { MySoftwareSerial::MySoftwareSerial(int receivePin, int transmitPin, bool inverse_logic, unsigned int buffSize, bool edge_triggered) {
m_oneWire = (receivePin == transmitPin); m_oneWire = (receivePin == transmitPin);
m_rxValid = m_txValid = m_txEnableValid = false; m_rxValid = m_txValid = m_txEnableValid = false;
m_buffer = NULL; m_buffer = NULL;
...@@ -99,7 +99,7 @@ SoftwareSerial::SoftwareSerial(int receivePin, int transmitPin, bool inverse_log ...@@ -99,7 +99,7 @@ SoftwareSerial::SoftwareSerial(int receivePin, int transmitPin, bool inverse_log
begin(9600); begin(9600);
} }
SoftwareSerial::~SoftwareSerial() { MySoftwareSerial::~MySoftwareSerial() {
enableRx(false); enableRx(false);
if (m_rxValid) if (m_rxValid)
ObjList[m_rxPin] = NULL; ObjList[m_rxPin] = NULL;
...@@ -107,11 +107,11 @@ SoftwareSerial::~SoftwareSerial() { ...@@ -107,11 +107,11 @@ SoftwareSerial::~SoftwareSerial() {
free(m_buffer); free(m_buffer);
} }
bool SoftwareSerial::isValidGPIOpin(int pin) { bool MySoftwareSerial::isValidGPIOpin(int pin) {
return (pin >= 0 && pin <= 5) || (pin >= 12 && pin <= MAX_PIN); return (pin >= 0 && pin <= 5) || (pin >= 12 && pin <= MAX_PIN);
} }
void SoftwareSerial::begin(long speed) { void MySoftwareSerial::begin(long speed) {
// Use getCycleCount() loop to get as exact timing as possible // Use getCycleCount() loop to get as exact timing as possible
m_bitTime = F_CPU / speed; m_bitTime = F_CPU / speed;
// By default enable interrupt during tx only for low speed // By default enable interrupt during tx only for low speed
...@@ -121,11 +121,11 @@ void SoftwareSerial::begin(long speed) { ...@@ -121,11 +121,11 @@ void SoftwareSerial::begin(long speed) {
enableRx(true); enableRx(true);
} }
long SoftwareSerial::baudRate() { long MySoftwareSerial::baudRate() {
return F_CPU / m_bitTime; return F_CPU / m_bitTime;
} }
void SoftwareSerial::setTransmitEnablePin(int transmitEnablePin) { void MySoftwareSerial::setTransmitEnablePin(int transmitEnablePin) {
if (isValidGPIOpin(transmitEnablePin)) { if (isValidGPIOpin(transmitEnablePin)) {
m_txEnableValid = true; m_txEnableValid = true;
m_txEnablePin = transmitEnablePin; m_txEnablePin = transmitEnablePin;
...@@ -137,11 +137,11 @@ void SoftwareSerial::setTransmitEnablePin(int transmitEnablePin) { ...@@ -137,11 +137,11 @@ void SoftwareSerial::setTransmitEnablePin(int transmitEnablePin) {
} }
} }
void SoftwareSerial::enableIntTx(bool on) { void MySoftwareSerial::enableIntTx(bool on) {
m_intTxEnabled = on; m_intTxEnabled = on;
} }
void SoftwareSerial::enableTx(bool on) { void MySoftwareSerial::enableTx(bool on) {
if (m_oneWire && m_txValid) { if (m_oneWire && m_txValid) {
if (on) { if (on) {
enableRx(false); enableRx(false);
...@@ -157,7 +157,7 @@ void SoftwareSerial::enableTx(bool on) { ...@@ -157,7 +157,7 @@ void SoftwareSerial::enableTx(bool on) {
} }
} }
void SoftwareSerial::enableRx(bool on) { void MySoftwareSerial::enableRx(bool on) {
if (m_rxValid) { if (m_rxValid) {
if (on) { if (on) {
if (m_edge) if (m_edge)
...@@ -171,14 +171,14 @@ void SoftwareSerial::enableRx(bool on) { ...@@ -171,14 +171,14 @@ void SoftwareSerial::enableRx(bool on) {
} }
} }
int SoftwareSerial::read() { int MySoftwareSerial::read() {
if (!m_rxValid || (m_inPos == m_outPos)) return -1; if (!m_rxValid || (m_inPos == m_outPos)) return -1;
uint8_t ch = m_buffer[m_outPos]; uint8_t ch = m_buffer[m_outPos];
m_outPos = (m_outPos + 1) % m_buffSize; m_outPos = (m_outPos + 1) % m_buffSize;
return ch; return ch;
} }
int SoftwareSerial::available() { int MySoftwareSerial::available() {
if (!m_rxValid) return 0; if (!m_rxValid) return 0;
int avail = m_inPos - m_outPos; int avail = m_inPos - m_outPos;
if (avail < 0) avail += m_buffSize; if (avail < 0) avail += m_buffSize;
...@@ -187,7 +187,7 @@ int SoftwareSerial::available() { ...@@ -187,7 +187,7 @@ int SoftwareSerial::available() {
#define WAIT { while (ESP.getCycleCount()-start < wait) if (m_intTxEnabled) optimistic_yield(1); wait += m_bitTime; } #define WAIT { while (ESP.getCycleCount()-start < wait) if (m_intTxEnabled) optimistic_yield(1); wait += m_bitTime; }
size_t SoftwareSerial::write(uint8_t b) { size_t MySoftwareSerial::write(uint8_t b) {
if (!m_txValid) return 0; if (!m_txValid) return 0;
if (m_invert) b = ~b; if (m_invert) b = ~b;
...@@ -215,22 +215,22 @@ size_t SoftwareSerial::write(uint8_t b) { ...@@ -215,22 +215,22 @@ size_t SoftwareSerial::write(uint8_t b) {
return 1; return 1;
} }
void SoftwareSerial::flush() { void MySoftwareSerial::flush() {
m_inPos = m_outPos = 0; m_inPos = m_outPos = 0;
} }
bool SoftwareSerial::overflow() { bool MySoftwareSerial::overflow() {
bool res = m_overflow; bool res = m_overflow;
m_overflow = false; m_overflow = false;
return res; return res;
} }
int SoftwareSerial::peek() { int MySoftwareSerial::peek() {
if (!m_rxValid || (m_inPos == m_outPos)) return -1; if (!m_rxValid || (m_inPos == m_outPos)) return -1;
return m_buffer[m_outPos]; return m_buffer[m_outPos];
} }
inline bool SoftwareSerial::propgateBits(bool level, int pulseBitLength) inline bool MySoftwareSerial::propgateBits(bool level, int pulseBitLength)
{ {
for (int i = 0; i < pulseBitLength; i++) for (int i = 0; i < pulseBitLength; i++)
{ {
...@@ -247,12 +247,12 @@ inline bool SoftwareSerial::propgateBits(bool level, int pulseBitLength) ...@@ -247,12 +247,12 @@ inline bool SoftwareSerial::propgateBits(bool level, int pulseBitLength)
return false; return false;
} }
inline void SoftwareSerial::setWaitingForStart() inline void MySoftwareSerial::setWaitingForStart()
{ {
m_getByteState = awaitingStart; m_getByteState = awaitingStart;
} }
inline void SoftwareSerial::setStartBit(unsigned long start) inline void MySoftwareSerial::setStartBit(unsigned long start)
{ {
// mark - the start of a pulse // mark - the start of a pulse
// set the timers and wait for the next pulse // set the timers and wait for the next pulse
...@@ -263,7 +263,7 @@ inline void SoftwareSerial::setStartBit(unsigned long start) ...@@ -263,7 +263,7 @@ inline void SoftwareSerial::setStartBit(unsigned long start)
m_getByteState = gotStart; m_getByteState = gotStart;
} }
void ICACHE_RAM_ATTR SoftwareSerial::rxRead() { void ICACHE_RAM_ATTR MySoftwareSerial::rxRead() {
// Advance the starting point for the samples but compensate for the // Advance the starting point for the samples but compensate for the
// initial delay which occurs before the interrupt is delivered // initial delay which occurs before the interrupt is delivered
unsigned long wait = m_bitTime + m_bitTime / 3 - 500; unsigned long wait = m_bitTime + m_bitTime / 3 - 500;
......
/* /*
SoftwareSerial.h MySoftwareSerial.h
SoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266. MySoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266.
Copyright (c) 2015-2016 Peter Lerup. All rights reserved. Copyright (c) 2015-2016 Peter Lerup. All rights reserved.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
...@@ -20,8 +20,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ...@@ -20,8 +20,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#ifndef SoftwareSerial_h #ifndef MySoftwareSerial_h
#define SoftwareSerial_h #define MySoftwareSerial_h
#include <inttypes.h> #include <inttypes.h>
#include <Stream.h> #include <Stream.h>
...@@ -32,10 +32,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ...@@ -32,10 +32,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// Speed up to 115200 can be used. // Speed up to 115200 can be used.
class SoftwareSerial : public Stream { class MySoftwareSerial : public Stream {
public: public:
SoftwareSerial(int receivePin, int transmitPin, bool inverse_logic = false, unsigned int buffSize = 64, bool edge_triggered = false); MySoftwareSerial(int receivePin, int transmitPin, bool inverse_logic = false, unsigned int buffSize = 64, bool edge_triggered = false);
virtual ~SoftwareSerial(); virtual ~MySoftwareSerial();
void begin(long speed); void begin(long speed);
long baudRate(); long baudRate();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment