Skip to content

Commit 45bd838

Browse files
committed
Update HardwareSerial to return both the nominal (set) value instead of the actual working value
1 parent c9d43cf commit 45bd838

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

cores/esp32/HardwareSerial.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ void serialEventRun(void)
135135
HardwareSerial::HardwareSerial(int uart_nr) :
136136
_uart_nr(uart_nr),
137137
_uart(NULL),
138+
_baudrate(0),
138139
_rxBufferSize(256),
139140
_txBufferSize(0),
140141
_onReceiveCB(NULL),
@@ -395,6 +396,8 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
395396
_uart = NULL;
396397
}
397398
}
399+
else
400+
_baudrate = baud;
398401
// create a task to deal with Serial Events when, for example, calling begin() twice to change the baudrate,
399402
// or when setting the callback before calling begin()
400403
if (_uart != NULL && (_onReceiveCB != NULL || _onReceiveErrorCB != NULL) && _eventTask == NULL) {
@@ -427,6 +430,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
427430
void HardwareSerial::updateBaudRate(unsigned long baud)
428431
{
429432
uartSetBaudRate(_uart, baud);
433+
_baudrate = baud;
430434
}
431435

432436
void HardwareSerial::end(bool fullyTerminate)
@@ -449,6 +453,7 @@ void HardwareSerial::end(bool fullyTerminate)
449453
delay(10);
450454
uartEnd(_uart);
451455
_uart = 0;
456+
_baudrate = 0;
452457
_destroyEventTask();
453458
}
454459

@@ -529,10 +534,12 @@ size_t HardwareSerial::write(const uint8_t *buffer, size_t size)
529534
uartWriteBuf(_uart, buffer, size);
530535
return size;
531536
}
532-
uint32_t HardwareSerial::baudRate()
533537

538+
uint32_t HardwareSerial::baudRate(bool nominal)
534539
{
535-
return uartGetBaudRate(_uart);
540+
if (nominal)
541+
return _baudrate;
542+
return uartGetBaudRate(_uart);
536543
}
537544
HardwareSerial::operator bool() const
538545
{

cores/esp32/HardwareSerial.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class HardwareSerial: public Stream
152152
{
153153
return write((uint8_t) n);
154154
}
155-
uint32_t baudRate();
155+
uint32_t baudRate(bool nominal = true);
156156
operator bool() const;
157157

158158
void setDebugOutput(bool);

0 commit comments

Comments
 (0)