From 761b5a5629815626cd2ba0196458b75523a78e9a Mon Sep 17 00:00:00 2001 From: Morten Abusland Date: Fri, 16 Mar 2018 21:53:48 +0100 Subject: [PATCH 1/2] HardwareSerial - availableForWrite() support --- cores/esp32/HardwareSerial.cpp | 4 ++++ cores/esp32/HardwareSerial.h | 1 + cores/esp32/esp32-hal-uart.c | 8 ++++++++ cores/esp32/esp32-hal-uart.h | 1 + 4 files changed, 14 insertions(+) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index b1245cb672c..8d1cf548a07 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -60,6 +60,10 @@ int HardwareSerial::available(void) { return uartAvailable(_uart); } +int HardwareSerial::availableForWrite(void) +{ + return uartAvailableForWrite(_uart); +} int HardwareSerial::peek(void) { diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index 1338f1c31ed..b7266ffc85e 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -40,6 +40,7 @@ class HardwareSerial: public Stream void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1, bool invert=false); void end(); int available(void); + int availableForWrite(void); int peek(void); int read(void); void flush(void); diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 6612668901b..4ee3c2f8b43 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -248,6 +248,14 @@ uint32_t uartAvailable(uart_t* uart) return uxQueueMessagesWaiting(uart->queue); } +uint32_t uartAvailableForWrite(uart_t* uart) +{ + if(uart == NULL) { + return 0; + } + return 0x7f - uart->dev->status.txfifo_cnt; +} + uint8_t uartRead(uart_t* uart) { if(uart == NULL || uart->queue == NULL) { diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index ce83f1461c7..5cd6e965099 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -55,6 +55,7 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx void uartEnd(uart_t* uart); uint32_t uartAvailable(uart_t* uart); +uint32_t uartAvailableForWrite(uart_t* uart); uint8_t uartRead(uart_t* uart); uint8_t uartPeek(uart_t* uart); From daddfcf3a382f8d7197f240195c4a3f90b9aed1d Mon Sep 17 00:00:00 2001 From: Morten Abusland Date: Fri, 16 Mar 2018 22:39:38 +0100 Subject: [PATCH 2/2] fix indentation errors (tab vs space) --- cores/esp32/HardwareSerial.cpp | 2 +- cores/esp32/HardwareSerial.h | 2 +- cores/esp32/esp32-hal-uart.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 8d1cf548a07..52b6f6b0d74 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -62,7 +62,7 @@ int HardwareSerial::available(void) } int HardwareSerial::availableForWrite(void) { - return uartAvailableForWrite(_uart); + return uartAvailableForWrite(_uart); } int HardwareSerial::peek(void) diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index b7266ffc85e..75660130c05 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -40,7 +40,7 @@ class HardwareSerial: public Stream void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1, bool invert=false); void end(); int available(void); - int availableForWrite(void); + int availableForWrite(void); int peek(void); int read(void); void flush(void); diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 4ee3c2f8b43..bcf9d045093 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -250,10 +250,10 @@ uint32_t uartAvailable(uart_t* uart) uint32_t uartAvailableForWrite(uart_t* uart) { - if(uart == NULL) { - return 0; - } - return 0x7f - uart->dev->status.txfifo_cnt; + if(uart == NULL) { + return 0; + } + return 0x7f - uart->dev->status.txfifo_cnt; } uint8_t uartRead(uart_t* uart)