From 9692cbc619275b7aa93658df4bb82ffc831d72d4 Mon Sep 17 00:00:00 2001 From: Robert Seidt <46084345+rseidt@users.noreply.github.com> Date: Wed, 3 Apr 2024 21:14:29 +0200 Subject: [PATCH] dynamic type for serialconfig (#1) Co-authored-by: Robert Seidt --- src/RS485.cpp | 4 ++-- src/RS485.h | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/RS485.cpp b/src/RS485.cpp index 5c8842d..56da6d4 100644 --- a/src/RS485.cpp +++ b/src/RS485.cpp @@ -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; diff --git a/src/RS485.h b/src/RS485.h index 787d66c..17c915d 100644 --- a/src/RS485.h +++ b/src/RS485.h @@ -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 @@ -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__ @@ -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(); @@ -103,7 +113,7 @@ class RS485Class : public Stream { bool _transmisionBegun; unsigned long _baudrate; - uint16_t _config; + RS485_SER_CONF_TYPE _config; }; extern RS485Class RS485;