mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-11 15:22:13 +03:00
Inefficient Print::write(data,len) shows message if used (only in debug mode) (#4537)
* inefficient Print::write(data,len) shows message if used (only in debug mode) * make HardwareSerial's write(data,len) efficient * HardwareSerial: remove duplicate tests, move trivial code from .cpp to .h
This commit is contained in:
@ -55,10 +55,8 @@ void HardwareSerial::end()
|
||||
uart_set_debug(UART_NO);
|
||||
}
|
||||
|
||||
if (_uart) {
|
||||
uart_uninit(_uart);
|
||||
_uart = NULL;
|
||||
}
|
||||
uart_uninit(_uart);
|
||||
_uart = NULL;
|
||||
}
|
||||
|
||||
size_t HardwareSerial::setRxBufferSize(size_t size){
|
||||
@ -70,30 +68,6 @@ size_t HardwareSerial::setRxBufferSize(size_t size){
|
||||
return _rx_size;
|
||||
}
|
||||
|
||||
void HardwareSerial::swap(uint8_t tx_pin)
|
||||
{
|
||||
if(!_uart) {
|
||||
return;
|
||||
}
|
||||
uart_swap(_uart, tx_pin);
|
||||
}
|
||||
|
||||
void HardwareSerial::set_tx(uint8_t tx_pin)
|
||||
{
|
||||
if(!_uart) {
|
||||
return;
|
||||
}
|
||||
uart_set_tx(_uart, tx_pin);
|
||||
}
|
||||
|
||||
void HardwareSerial::pins(uint8_t tx, uint8_t rx)
|
||||
{
|
||||
if(!_uart) {
|
||||
return;
|
||||
}
|
||||
uart_set_pins(_uart, tx, rx);
|
||||
}
|
||||
|
||||
void HardwareSerial::setDebugOutput(bool en)
|
||||
{
|
||||
if(!_uart) {
|
||||
@ -113,16 +87,6 @@ void HardwareSerial::setDebugOutput(bool en)
|
||||
}
|
||||
}
|
||||
|
||||
bool HardwareSerial::isTxEnabled(void)
|
||||
{
|
||||
return _uart && uart_tx_enabled(_uart);
|
||||
}
|
||||
|
||||
bool HardwareSerial::isRxEnabled(void)
|
||||
{
|
||||
return _uart && uart_rx_enabled(_uart);
|
||||
}
|
||||
|
||||
int HardwareSerial::available(void)
|
||||
{
|
||||
int result = static_cast<int>(uart_rx_available(_uart));
|
||||
@ -132,27 +96,6 @@ int HardwareSerial::available(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
int HardwareSerial::peek(void)
|
||||
{
|
||||
// this may return -1, but that's okay
|
||||
return uart_peek_char(_uart);
|
||||
}
|
||||
|
||||
int HardwareSerial::read(void)
|
||||
{
|
||||
// this may return -1, but that's okay
|
||||
return uart_read_char(_uart);
|
||||
}
|
||||
|
||||
int HardwareSerial::availableForWrite(void)
|
||||
{
|
||||
if(!_uart || !uart_tx_enabled(_uart)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return static_cast<int>(uart_tx_free(_uart));
|
||||
}
|
||||
|
||||
void HardwareSerial::flush()
|
||||
{
|
||||
if(!_uart || !uart_tx_enabled(_uart)) {
|
||||
@ -165,33 +108,9 @@ void HardwareSerial::flush()
|
||||
delayMicroseconds(11000000 / uart_get_baudrate(_uart) + 1);
|
||||
}
|
||||
|
||||
size_t HardwareSerial::write(uint8_t c)
|
||||
{
|
||||
if(!_uart || !uart_tx_enabled(_uart)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uart_write_char(_uart, c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int HardwareSerial::baudRate(void)
|
||||
{
|
||||
// Null pointer on _uart is checked by SDK
|
||||
return uart_get_baudrate(_uart);
|
||||
}
|
||||
|
||||
|
||||
HardwareSerial::operator bool() const
|
||||
{
|
||||
return _uart != 0;
|
||||
}
|
||||
|
||||
|
||||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
|
||||
HardwareSerial Serial(UART0);
|
||||
#endif
|
||||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL1)
|
||||
HardwareSerial Serial1(UART1);
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user