Skip to content

Add option for custom rxPin and txPin with HardwareSerial (e.g. for ESP32) #34

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

cyberman54
Copy link
Contributor

ESP32 boards support remapping of GPIO pins to Serial ports (UART0/1/2).

This PR enhances API in Serial.h with an option to pass custom rxPin and txPin to HardwareSerial. It keeps all usage options of the former API (i.e. for using SoftwareSerial), so this change shouldn't break any code created before this PR.

@cyberman54 cyberman54 changed the title Add option to custom rxPin and txPin to HardwareSerial (e.g. for ESP32) Add option for custom rxPin and txPin with HardwareSerial (e.g. for ESP32) Feb 16, 2022
void begin(int baudRate) {
serial.begin(baudRate);
void begin(int baudRate = 9600, uint32_t config = SERIAL_8N1, int pinRx = -1, int pinTx = -1) {
serial.begin(baudRate, config, pinRx, pinTx);
Copy link
Owner

@lewapek lewapek Feb 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esp32 HardwareSerial is different - and if you try to compile for arduino this would not work
the solution is to put you modified API (with additional params) behind preprocessor directive so it's compiled only in case of esp32

abstractSerial->begin(baudRate);
}
void begin(int baudRate = 9600, uint32_t config = SERIAL_8N1, int pinRx = -1, int pinTx = -1) {
abstractSerial->begin(baudRate, config, pinRx, pinTx);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep 2 spaces indentation to be consistent with the rest of the project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants