Skip to content

Commit d9e37af

Browse files
authored
Merge pull request #27 from arduino-libraries/mbed_pinNames_support
Allow using mbed pin names and external defines
2 parents 9a6b830 + 8216529 commit d9e37af

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Diff for: src/RS485.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919

2020
#include "RS485.h"
2121

22+
#ifdef __MBED__
23+
#include "pinDefinitions.h"
24+
RS485Class::RS485Class(HardwareSerial& hwSerial, PinName txPin, PinName dePin, PinName rePin) :
25+
_serial(&hwSerial),
26+
_txPin(PinNameToIndex(txPin)),
27+
_dePin(PinNameToIndex(dePin)),
28+
_rePin(PinNameToIndex(rePin)),
29+
_transmisionBegun(false)
30+
{
31+
}
32+
#endif
33+
2234
RS485Class::RS485Class(HardwareSerial& hwSerial, int txPin, int dePin, int rePin) :
2335
_serial(&hwSerial),
2436
_txPin(txPin),
@@ -186,4 +198,8 @@ void RS485Class::setDelays(int predelay, int postdelay)
186198
_postdelay = postdelay;
187199
}
188200

201+
#ifdef RS485_SERIAL_PORT
202+
RS485Class RS485(RS485_SERIAL_PORT, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
203+
#else
189204
RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
205+
#endif

Diff for: src/RS485.h

+7
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
#include <Arduino.h>
2424

25+
#ifndef RS485_DEFAULT_TX_PIN
2526
#ifdef PIN_SERIAL1_TX
2627
#define RS485_DEFAULT_TX_PIN PIN_SERIAL1_TX
2728
#else
2829
#define RS485_DEFAULT_TX_PIN 1
2930
#endif
31+
#endif
3032

3133
#ifdef __AVR__
3234
#define RS485_DEFAULT_DE_PIN 2
@@ -35,16 +37,21 @@
3537
#define RS485_DEFAULT_DE_PIN A1
3638
#define RS485_DEFAULT_RE_PIN A0
3739
#else
40+
#ifndef RS485_DEFAULT_DE_PIN
3841
#define RS485_DEFAULT_DE_PIN A6
3942
#define RS485_DEFAULT_RE_PIN A5
4043
#endif
44+
#endif
4145

4246

4347
#define RS485_DEFAULT_PRE_DELAY 50
4448
#define RS485_DEFAULT_POST_DELAY 50
4549

4650
class RS485Class : public Stream {
4751
public:
52+
#ifdef __MBED__
53+
RS485Class(HardwareSerial& hwSerial, PinName txPin, PinName dePin, PinName rePin);
54+
#endif
4855
RS485Class(HardwareSerial& hwSerial, int txPin, int dePin, int rePin);
4956

5057
virtual void begin(unsigned long baudrate);

0 commit comments

Comments
 (0)