Skip to content

Adds functionality allowing size of HardwareSerial's RX buffer to be changed at runtime. #1855

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 1 commit into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cores/esp32/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ void HardwareSerial::end()
_uart = 0;
}

size_t HardwareSerial::setRxBufferSize(size_t new_size) {
return uartResizeRxBuffer(_uart, new_size);
}

void HardwareSerial::setDebugOutput(bool en)
{
if(_uart == 0) {
Expand Down
1 change: 1 addition & 0 deletions cores/esp32/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class HardwareSerial: public Stream
uint32_t baudRate();
operator bool() const;

size_t setRxBufferSize(size_t);
void setDebugOutput(bool);

protected:
Expand Down
20 changes: 20 additions & 0 deletions cores/esp32/esp32-hal-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,26 @@ void uartEnd(uart_t* uart)
uartDetachTx(uart);
}

size_t uartResizeRxBuffer(uart_t * uart, size_t new_size) {
if(uart == NULL) {
return;
}

UART_MUTEX_LOCK();
if(uart->queue != NULL) {
uint8_t c;
while(xQueueReceive(uart->queue, &c, 0));
vQueueDelete(uart->queue);
uart->queue = xQueueCreate(new_size, sizeof(uint8_t));
if(uart->queue == NULL) {
return NULL;
}
}
UART_MUTEX_UNLOCK();

return new_size;
}

uint32_t uartAvailable(uart_t* uart)
{
if(uart == NULL || uart->queue == NULL) {
Expand Down
2 changes: 2 additions & 0 deletions cores/esp32/esp32-hal-uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ void uartFlush(uart_t* uart);
void uartSetBaudRate(uart_t* uart, uint32_t baud_rate);
uint32_t uartGetBaudRate(uart_t* uart);

size_t uartResizeRxBuffer(uart_t* uart, size_t new_size);

void uartSetDebug(uart_t* uart);
int uartGetDebug();

Expand Down