Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Compatibility to ESP32 and ESP8266 #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/RS485.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ void RS485Class::begin(unsigned long baudrate, int predelay, int postdelay)
begin(baudrate, SERIAL_8N1, predelay, postdelay);
}

void RS485Class::begin(unsigned long baudrate, uint16_t config)
void RS485Class::begin(unsigned long baudrate, RS485_SER_CONF_TYPE config)
{
begin(baudrate, config, RS485_DEFAULT_PRE_DELAY, RS485_DEFAULT_POST_DELAY);
}

void RS485Class::begin(unsigned long baudrate, uint16_t config, int predelay, int postdelay)
void RS485Class::begin(unsigned long baudrate, RS485_SER_CONF_TYPE config, int predelay, int postdelay)
{
_baudrate = baudrate;
_config = config;
Expand Down
16 changes: 13 additions & 3 deletions src/RS485.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#define SERIAL_PORT_HARDWARE Serial1
#define RS485_DEFAULT_DE_PIN 8
#define RS485_DEFAULT_RE_PIN 7
#elif defined(ESP32) || defined(ESP8266)
#define RS485_DEFAULT_DE_PIN 12
#define RS485_DEFAULT_RE_PIN 13

#else
#ifndef RS485_DEFAULT_DE_PIN
#define RS485_DEFAULT_DE_PIN A6
Expand All @@ -61,6 +65,12 @@
#define RS485_DEFAULT_PRE_DELAY 50
#define RS485_DEFAULT_POST_DELAY 50

#if defined(ESP32) || defined(ESP8266)
#define RS485_SER_CONF_TYPE SerialConfig
#else
#define RS485_SER_CONF_TYPE uint16_t
#endif

class RS485Class : public Stream {
public:
#ifdef __MBED__
Expand All @@ -69,9 +79,9 @@ class RS485Class : public Stream {
RS485Class(HardwareSerial& hwSerial, int txPin, int dePin, int rePin);

virtual void begin(unsigned long baudrate);
virtual void begin(unsigned long baudrate, uint16_t config);
virtual void begin(unsigned long baudrate, RS485_SER_CONF_TYPE config);
virtual void begin(unsigned long baudrate, int predelay, int postdelay);
virtual void begin(unsigned long baudrate, uint16_t config, int predelay, int postdelay);
virtual void begin(unsigned long baudrate, RS485_SER_CONF_TYPE config, int predelay, int postdelay);
virtual void end();
virtual int available();
virtual int peek();
Expand Down Expand Up @@ -103,7 +113,7 @@ class RS485Class : public Stream {

bool _transmisionBegun;
unsigned long _baudrate;
uint16_t _config;
RS485_SER_CONF_TYPE _config;
};

extern RS485Class RS485;
Expand Down
Loading