mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Serial.flush modification (#5293)
* Modify Serial.flush * Add function to uart tests
This commit is contained in:
parent
8b16d9c1d1
commit
8c3f1be63f
@ -108,14 +108,16 @@ int HardwareSerial::available(void)
|
||||
|
||||
void HardwareSerial::flush()
|
||||
{
|
||||
uint8_t bit_length = 0;
|
||||
if(!_uart || !uart_tx_enabled(_uart)) {
|
||||
return;
|
||||
}
|
||||
|
||||
bit_length = uart_get_bit_length(_uart_nr); // data width, parity and stop
|
||||
uart_wait_tx_empty(_uart);
|
||||
//Workaround for a bug in serial not actually being finished yet
|
||||
//Wait for 8 data bits, 1 parity and 2 stop bits, just in case
|
||||
delayMicroseconds(11000000 / uart_get_baudrate(_uart) + 1);
|
||||
delayMicroseconds(bit_length * 1000000 / uart_get_baudrate(_uart) + 1);
|
||||
}
|
||||
|
||||
void HardwareSerial::startDetectBaudrate()
|
||||
|
@ -48,6 +48,10 @@
|
||||
#include "user_interface.h"
|
||||
#include "uart_register.h"
|
||||
|
||||
#define MODE2WIDTH(mode) (((mode%16)>>2)+5)
|
||||
#define MODE2STOP(mode) (((mode)>>5)+1)
|
||||
#define MODE2PARITY(mode) (mode%4)
|
||||
|
||||
/*
|
||||
Some general architecture for GDB integration with the UART to enable
|
||||
serial debugging.
|
||||
@ -204,7 +208,14 @@ uart_read_char_unsafe(uart_t* uart)
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t
|
||||
uint8_t
|
||||
uart_get_bit_length(const int uart_nr)
|
||||
{
|
||||
// return bit length from uart mode, +1 for the start bit which is always there.
|
||||
return MODE2WIDTH(USC0(uart_nr)) + MODE2PARITY(USC0(uart_nr)) + MODE2STOP(USC0(uart_nr)) + 1;
|
||||
}
|
||||
|
||||
size_t
|
||||
uart_rx_available(uart_t* uart)
|
||||
{
|
||||
if(uart == NULL || !uart->rx_enabled)
|
||||
|
@ -147,6 +147,7 @@ int uart_get_debug();
|
||||
void uart_start_detect_baudrate(int uart_nr);
|
||||
int uart_detect_baudrate(int uart_nr);
|
||||
|
||||
uint8_t uart_get_bit_length(const int uart_nr);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
} // extern "C"
|
||||
|
@ -313,6 +313,15 @@ uart_get_baudrate(uart_t* uart)
|
||||
return uart->baud_rate;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
uart_get_bit_length(const int uart_nr)
|
||||
{
|
||||
uint8_t width = ((uart_nr % 16) >> 2) + 5;
|
||||
uint8_t parity = (uart_nr >> 5) + 1;
|
||||
uint8_t stop = uart_nr % 4;
|
||||
return (width + parity + stop + 1);
|
||||
}
|
||||
|
||||
uart_t*
|
||||
uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user