Skip to content
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

Add isFlushed() method to HardwareSerial class for AVR and UARTClass for SAM #3737

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions build/shared/lib/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ println KEYWORD2 Serial_Println
available KEYWORD2 Serial_Available
availableForWrite KEYWORD2
flush KEYWORD2 Serial_Flush
isFlushed KEYWORD2
setTimeout KEYWORD2
find KEYWORD2
findUntil KEYWORD2
Expand Down
6 changes: 6 additions & 0 deletions hardware/arduino/avr/cores/arduino/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ void HardwareSerial::flush()
// the hardware finished tranmission (TXC is set).
}

bool HardwareSerial::isFlushed(void)
{
if (!_written) return true;
return (_tx_buffer_head == _tx_buffer_tail) && bit_is_clear(*_ucsrb, UDRIE0) && bit_is_set(*_ucsra, TXC0);
}

size_t HardwareSerial::write(uint8_t c)
{
_written = true;
Expand Down
1 change: 1 addition & 0 deletions hardware/arduino/avr/cores/arduino/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class HardwareSerial : public Stream
virtual int read(void);
int availableForWrite(void);
virtual void flush(void);
virtual bool isFlushed(void);
virtual size_t write(uint8_t);
inline size_t write(unsigned long n) { return write((uint8_t)n); }
inline size_t write(long n) { return write((uint8_t)n); }
Expand Down
5 changes: 5 additions & 0 deletions hardware/arduino/sam/cores/arduino/UARTClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ void UARTClass::flush( void )
;
}

bool UARTClass::isFlushed( void )
{
return ((_pUart->UART_SR & UART_SR_TXRDY) == UART_SR_TXRDY) && (_tx_buffer->_iTail == _tx_buffer->_iHead);
}

size_t UARTClass::write( const uint8_t uc_data )
{
// Is the hardware currently busy?
Expand Down
1 change: 1 addition & 0 deletions hardware/arduino/sam/cores/arduino/UARTClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class UARTClass : public HardwareSerial
int peek(void);
int read(void);
void flush(void);
bool isFlushed(void);
size_t write(const uint8_t c);
using Print::write; // pull in write(str) and write(buf, size) from Print

Expand Down