Skip to content

Commit 255f010

Browse files
committed
ESP8266 ESP32 compatible
1 parent 2ca6377 commit 255f010

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

README.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/
88
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"]
99

1010
Enables sending and receiving data using the RS-485 standard with RS-485 shields, like the MKR 485 Shield.
11+
I've Made this compatible with ESP8266 and ESP32.
1112

1213
This library supports the Maxim Integrated MAX3157 and equivalent chipsets.
1314

src/RS485.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ void RS485Class::begin(unsigned long baudrate, int predelay, int postdelay)
3838
begin(baudrate, SERIAL_8N1, predelay, postdelay);
3939
}
4040

41-
void RS485Class::begin(unsigned long baudrate, uint16_t config)
41+
void RS485Class::begin(unsigned long baudrate, RS485_SER_CONF_TYPE config)
4242
{
4343
begin(baudrate, config, RS485_DEFAULT_PRE_DELAY, RS485_DEFAULT_POST_DELAY);
4444
}
4545

46-
void RS485Class::begin(unsigned long baudrate, uint16_t config, int predelay, int postdelay)
46+
void RS485Class::begin(unsigned long baudrate, RS485_SER_CONF_TYPE config, int predelay, int postdelay)
4747
{
4848
_baudrate = baudrate;
4949
_config = config;

src/RS485.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,22 @@
3131
#ifdef __AVR__
3232
#define RS485_DEFAULT_DE_PIN 2
3333
#define RS485_DEFAULT_RE_PIN -1
34+
#elif defined(ESP32) || defined(ESP8266)
35+
#define RS485_DEFAULT_DE_PIN 0
36+
#define RS485_DEFAULT_RE_PIN 0
3437
#else
3538
#define RS485_DEFAULT_DE_PIN A6
3639
#define RS485_DEFAULT_RE_PIN A5
3740
#endif
3841

42+
#if defined(ESP8266)
43+
#define RS485_SER_CONF_TYPE SerialConfig
44+
#elif defined(ESP32)
45+
#define RS485_SER_CONF_TYPE uint32_t
46+
#else
47+
#define RS485_SER_CONF_TYPE uint16_t
48+
#endif
49+
3950

4051
#define RS485_DEFAULT_PRE_DELAY 50
4152
#define RS485_DEFAULT_POST_DELAY 50
@@ -45,9 +56,9 @@ class RS485Class : public Stream {
4556
RS485Class(HardwareSerial& hwSerial, int txPin, int dePin, int rePin);
4657

4758
virtual void begin(unsigned long baudrate);
48-
virtual void begin(unsigned long baudrate, uint16_t config);
59+
virtual void begin(unsigned long baudrate, RS485_SER_CONF_TYPE config);
4960
virtual void begin(unsigned long baudrate, int predelay, int postdelay);
50-
virtual void begin(unsigned long baudrate, uint16_t config, int predelay, int postdelay);
61+
virtual void begin(unsigned long baudrate, RS485_SER_CONF_TYPE config, int predelay, int postdelay);
5162
virtual void end();
5263
virtual int available();
5364
virtual int peek();

0 commit comments

Comments
 (0)