Skip to content

Commit

Permalink
Add MY_RS485_DE_INVERSE define to invert the device enable pin polari…
Browse files Browse the repository at this point in the history
…ty (#1358)

* Add MY_RS485_DE_INVERSE define to invert the device enable pin polarity
  • Loading branch information
ltigges authored and mfalkvidd committed Nov 6, 2019
1 parent b9798e4 commit b7bed69
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
8 changes: 8 additions & 0 deletions MyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@
*/
//#define MY_RS485_DE_PIN (2)

/**
* @def MY_RS485_DE_INVERSE
* @brief Define this if RS485 driver enable pin polarity is inverted (low-active).
*/
//#define MY_RS485_DE_INVERSE

/**
* @def MY_RS485_HWSERIAL
* @brief Define this if RS485 is connected to a hardware serial port.
Expand Down Expand Up @@ -2317,6 +2323,8 @@
#define MY_OTA_USE_I2C_EEPROM
// RS485
#define MY_RS485
#define MY_RS485_DE_PIN
#define MY_RS485_DE_INVERSE
#define MY_RS485_HWSERIAL
// RF24
#define MY_RADIO_RF24
Expand Down
18 changes: 17 additions & 1 deletion hal/transport/RS485/MyTransportRS485.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@
#endif

#if defined(MY_RS485_DE_PIN)
#if !defined(MY_RS485_DE_INVERSE)
#define assertDE() hwDigitalWrite(MY_RS485_DE_PIN, HIGH); delayMicroseconds(5)
#define deassertDE() hwDigitalWrite(MY_RS485_DE_PIN, LOW)

#else
#define assertDE() hwDigitalWrite(MY_RS485_DE_PIN, LOW); delayMicroseconds(5)
#define deassertDE() hwDigitalWrite(MY_RS485_DE_PIN, HIG)
#endif
#else
#define assertDE()
#define deassertDE()
Expand Down Expand Up @@ -264,7 +268,11 @@ bool transportSend(const uint8_t to, const void* data, const uint8_t len, const
}

#if defined(MY_RS485_DE_PIN)
#if !defined(MY_RS485_DE_INVERSE)
hwDigitalWrite(MY_RS485_DE_PIN, HIGH);
#else
hwDigitalWrite(MY_RS485_DE_PIN, LOW);
#endif
delayMicroseconds(5);
#endif

Expand Down Expand Up @@ -310,7 +318,11 @@ bool transportSend(const uint8_t to, const void* data, const uint8_t len, const
_dev.flush();
#endif
#endif
#if !defined(MY_RS485_DE_INVERSE)
hwDigitalWrite(MY_RS485_DE_PIN, LOW);
#else
hwDigitalWrite(MY_RS485_DE_PIN, HIGH);
#endif
#endif
return true;
}
Expand All @@ -324,7 +336,11 @@ bool transportInit(void)
_serialReset();
#if defined(MY_RS485_DE_PIN)
hwPinMode(MY_RS485_DE_PIN, OUTPUT);
#if !defined(MY_RS485_DE_INVERSE)
hwDigitalWrite(MY_RS485_DE_PIN, LOW);
#else
hwDigitalWrite(MY_RS485_DE_PIN, HIGH);
#endif
#endif
return true;
}
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ MY_RFM69_TX_POWER_DBM LITERAL1
MY_RS485 LITERAL1
MY_RS485_BAUD_RATE LITERAL1
MY_RS485_DE_PIN LITERAL1
MY_RS485_DE_INVERSE LITERAL1
MY_RS485_HWSERIAL LITERAL1
MY_RS485_MAX_MESSAGE_LENGTH LITERAL1
MY_RS485_SOH_COUNT LITERAL1
Expand Down

0 comments on commit b7bed69

Please sign in to comment.