Skip to content

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