Skip to content

Commit ce61074

Browse files
coddingtonbearme-no-dev
authored andcommitted
Add functionality allowing rxBuffer of HardwareSerial to be changed in size via HardwareSerial::setRxBufferSize. (#1855)
1 parent 339618f commit ce61074

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

Diff for: cores/esp32/HardwareSerial.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ void HardwareSerial::end()
4646
_uart = 0;
4747
}
4848

49+
size_t HardwareSerial::setRxBufferSize(size_t new_size) {
50+
return uartResizeRxBuffer(_uart, new_size);
51+
}
52+
4953
void HardwareSerial::setDebugOutput(bool en)
5054
{
5155
if(_uart == 0) {

Diff for: cores/esp32/HardwareSerial.h

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class HardwareSerial: public Stream
7070
uint32_t baudRate();
7171
operator bool() const;
7272

73+
size_t setRxBufferSize(size_t);
7374
void setDebugOutput(bool);
7475

7576
protected:

Diff for: cores/esp32/esp32-hal-uart.c

+20
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,26 @@ void uartEnd(uart_t* uart)
240240
uartDetachTx(uart);
241241
}
242242

243+
size_t uartResizeRxBuffer(uart_t * uart, size_t new_size) {
244+
if(uart == NULL) {
245+
return;
246+
}
247+
248+
UART_MUTEX_LOCK();
249+
if(uart->queue != NULL) {
250+
uint8_t c;
251+
while(xQueueReceive(uart->queue, &c, 0));
252+
vQueueDelete(uart->queue);
253+
uart->queue = xQueueCreate(new_size, sizeof(uint8_t));
254+
if(uart->queue == NULL) {
255+
return NULL;
256+
}
257+
}
258+
UART_MUTEX_UNLOCK();
259+
260+
return new_size;
261+
}
262+
243263
uint32_t uartAvailable(uart_t* uart)
244264
{
245265
if(uart == NULL || uart->queue == NULL) {

Diff for: cores/esp32/esp32-hal-uart.h

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ void uartFlush(uart_t* uart);
6767
void uartSetBaudRate(uart_t* uart, uint32_t baud_rate);
6868
uint32_t uartGetBaudRate(uart_t* uart);
6969

70+
size_t uartResizeRxBuffer(uart_t* uart, size_t new_size);
71+
7072
void uartSetDebug(uart_t* uart);
7173
int uartGetDebug();
7274

0 commit comments

Comments
 (0)