Merge pull request #287 from edogaldo/Fix-HardwareSerial.flush()

Make HardwareSerial.flush() compatible with Arduino 1.0 api
This commit is contained in:
Roger Clark 2017-05-25 18:26:01 +10:00 committed by GitHub
commit 8c433e3c71
2 changed files with 6 additions and 5 deletions

View File

@ -193,7 +193,8 @@ size_t HardwareSerial::write(unsigned char ch) {
return 1;
}
/* edogaldo: Waits for the transmission of outgoing serial data to complete (Arduino 1.0 api specs) */
void HardwareSerial::flush(void) {
usart_reset_rx(this->usart_device);
usart_reset_tx(this->usart_device);
while(!rb_is_empty(this->usart_device->wb)); // wait for TX buffer empty
while(!((this->usart_device->regs->SR) & (1<<USART_SR_TC_BIT))); // wait for TC (Transmission Complete) flag set
}

View File

@ -52,9 +52,9 @@ extern "C"{
* One byte is left free to distinguish empty from full. */
typedef struct ring_buffer {
volatile uint8 *buf; /**< Buffer items are stored into */
uint16 head; /**< Index of the next item to remove */
uint16 tail; /**< Index where the next item will get inserted */
uint16 size; /**< Buffer capacity minus one */
volatile uint16 head; /**< Index of the next item to remove */
volatile uint16 tail; /**< Index where the next item will get inserted */
volatile uint16 size; /**< Buffer capacity minus one */
} ring_buffer;
/**