HardwareSerial - availableForWrite() support (#1226)

* HardwareSerial - availableForWrite() support

* fix indentation errors (tab vs space)
This commit is contained in:
mtabu 2018-04-06 18:07:46 +02:00 committed by Me No Dev
parent 149190fe11
commit aa1288aa6e
4 changed files with 14 additions and 0 deletions

View File

@ -62,6 +62,10 @@ int HardwareSerial::available(void)
{
return uartAvailable(_uart);
}
int HardwareSerial::availableForWrite(void)
{
return uartAvailableForWrite(_uart);
}
int HardwareSerial::peek(void)
{

View File

@ -40,6 +40,7 @@ public:
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);

View File

@ -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) {

View File

@ -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);