Add functionality allowing rxBuffer of HardwareSerial to be changed in size via HardwareSerial::setRxBufferSize. (#1855)

This commit is contained in:
Adam Coddington 2018-09-17 12:16:18 -07:00 committed by Me No Dev
parent 339618f8ef
commit ce61074802
4 changed files with 27 additions and 0 deletions

View File

@ -46,6 +46,10 @@ void HardwareSerial::end()
_uart = 0; _uart = 0;
} }
size_t HardwareSerial::setRxBufferSize(size_t new_size) {
return uartResizeRxBuffer(_uart, new_size);
}
void HardwareSerial::setDebugOutput(bool en) void HardwareSerial::setDebugOutput(bool en)
{ {
if(_uart == 0) { if(_uart == 0) {

View File

@ -70,6 +70,7 @@ public:
uint32_t baudRate(); uint32_t baudRate();
operator bool() const; operator bool() const;
size_t setRxBufferSize(size_t);
void setDebugOutput(bool); void setDebugOutput(bool);
protected: protected:

View File

@ -240,6 +240,26 @@ void uartEnd(uart_t* uart)
uartDetachTx(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) uint32_t uartAvailable(uart_t* uart)
{ {
if(uart == NULL || uart->queue == NULL) { if(uart == NULL || uart->queue == NULL) {

View File

@ -67,6 +67,8 @@ void uartFlush(uart_t* uart);
void uartSetBaudRate(uart_t* uart, uint32_t baud_rate); void uartSetBaudRate(uart_t* uart, uint32_t baud_rate);
uint32_t uartGetBaudRate(uart_t* uart); uint32_t uartGetBaudRate(uart_t* uart);
size_t uartResizeRxBuffer(uart_t* uart, size_t new_size);
void uartSetDebug(uart_t* uart); void uartSetDebug(uart_t* uart);
int uartGetDebug(); int uartGetDebug();