-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fixes UART pin setting + adds CTS/RTS HW Flow Control #6272
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
56da126
fixes setPins and begin to keep rx/tx unmodified
SuGlider 2e70fc8
adds Hardware Flow Control mode and CTS/RTS pin setting
SuGlider 6ab86c6
adds Hardware Flow Control mode and CTS/RTS pin setting
SuGlider 01921d2
adds Hardware Flow Control mode and CTS/RTS pin setting
SuGlider d926df6
adds Hardware Flow Control mode and CTS/RTS pin setting
SuGlider 4cdcf11
Merge branch 'master' into uart-pins
SuGlider 195a023
Merge branch 'master' into uart-pins
SuGlider a7d2bf0
Code Review
SuGlider 21c683e
Merge branch 'uart-pins' of https://github.com/suglider/arduino-esp32…
SuGlider File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,37 +114,46 @@ void serialEventRun(void) | |
} | ||
#endif | ||
|
||
|
||
HardwareSerial::HardwareSerial(int uart_nr) : _uart_nr(uart_nr), _uart(NULL), _rxBufferSize(256) {} | ||
|
||
enum { UART_NUM_0, UART_NUM_1, UART_NUM_2 }; | ||
|
||
void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert, unsigned long timeout_ms, uint8_t rxfifo_full_thrhd) | ||
{ | ||
if(0 > _uart_nr || _uart_nr >= SOC_UART_NUM) { | ||
log_e("Serial number is invalid, please use numers from 0 to %u", SOC_UART_NUM - 1); | ||
return; | ||
} | ||
|
||
// First Time or after end() --> set default Pins | ||
if (!uartIsDriverInstalled(_uart)) { | ||
switch (_uart_nr) { | ||
case UART_NUM_0: | ||
rxPin = rxPin < 0 ? SOC_RX0 : rxPin; | ||
txPin = txPin < 0 ? SOC_TX0 : txPin; | ||
break; | ||
#if SOC_UART_NUM > 1 // may save some flash bytes... | ||
case UART_NUM_1: | ||
rxPin = rxPin < 0 ? RX1 : rxPin; | ||
txPin = txPin < 0 ? TX1 : txPin; | ||
break; | ||
#endif | ||
#if SOC_UART_NUM > 2 // may save some flash bytes... | ||
case UART_NUM_2: | ||
rxPin = rxPin < 0 ? RX2 : rxPin; | ||
txPin = txPin < 0 ? TX2 : txPin; | ||
break; | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. always add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
} | ||
} | ||
|
||
if(_uart) { | ||
// in this case it is a begin() over a previous begin() - maybe to change baud rate | ||
// thus do not disable debug output | ||
end(false); | ||
} | ||
if(_uart_nr == 0 && rxPin < 0 && txPin < 0) { | ||
rxPin = SOC_RX0; | ||
txPin = SOC_TX0; | ||
} | ||
#if SOC_UART_NUM > 1 | ||
if(_uart_nr == 1 && rxPin < 0 && txPin < 0) { | ||
rxPin = RX1; | ||
txPin = TX1; | ||
} | ||
#endif | ||
#if SOC_UART_NUM > 2 | ||
if(_uart_nr == 2 && rxPin < 0 && txPin < 0) { | ||
rxPin = RX2; | ||
txPin = TX2; | ||
} | ||
#endif | ||
|
||
// IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified. | ||
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, _rxBufferSize, invert, rxfifo_full_thrhd); | ||
if (!baud) { | ||
// using baud rate as zero, forces it to try to detect the current baud rate in place | ||
|
@@ -280,9 +289,16 @@ void HardwareSerial::setRxInvert(bool invert) | |
uartSetRxInvert(_uart, invert); | ||
} | ||
|
||
void HardwareSerial::setPins(uint8_t rxPin, uint8_t txPin) | ||
// negative Pin value will keep it unmodified | ||
void HardwareSerial::setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) | ||
{ | ||
uartSetPins(_uart, rxPin, txPin, ctsPin, rtsPin); | ||
} | ||
|
||
// Enables or disables Hardware Flow Control using RTS and/or CTS pins (must use setAllPins() before) | ||
void HardwareSerial::setHwFlowCtrlMode(uint8_t mode, uint8_t threshold) | ||
{ | ||
uartSetPins(_uart, rxPin, txPin); | ||
uartSetHwFlowCtrlMode(_uart, mode, threshold); | ||
} | ||
|
||
size_t HardwareSerial::setRxBufferSize(size_t new_size) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this enum will be used just for the switch statement, let's use int instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is solved now by including "driver/uart.h" that has those defines.