mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-29 10:17:15 +02:00
UART rework
many possible problems fixed in preparation for thread-safe
This commit is contained in:
@ -33,11 +33,7 @@ void HardwareSerial::setDebugOutput(bool en)
|
||||
return;
|
||||
}
|
||||
if(en) {
|
||||
if(_uart->txEnabled) {
|
||||
uartSetDebug(_uart);
|
||||
} else {
|
||||
uartSetDebug(0);
|
||||
}
|
||||
uartSetDebug(_uart);
|
||||
} else {
|
||||
if(uartGetDebug() == _uart_nr) {
|
||||
uartSetDebug(0);
|
||||
@ -45,33 +41,14 @@ void HardwareSerial::setDebugOutput(bool en)
|
||||
}
|
||||
}
|
||||
|
||||
bool HardwareSerial::isTxEnabled(void)
|
||||
{
|
||||
if(_uart == 0) {
|
||||
return false;
|
||||
}
|
||||
return _uart->txEnabled;
|
||||
}
|
||||
|
||||
bool HardwareSerial::isRxEnabled(void)
|
||||
{
|
||||
if(_uart == 0) {
|
||||
return false;
|
||||
}
|
||||
return _uart->rxEnabled;
|
||||
}
|
||||
|
||||
int HardwareSerial::available(void)
|
||||
{
|
||||
if (_uart && _uart->rxEnabled) {
|
||||
return uartAvailable(_uart);
|
||||
}
|
||||
return 0;
|
||||
return uartAvailable(_uart);
|
||||
}
|
||||
|
||||
int HardwareSerial::peek(void)
|
||||
{
|
||||
if (_uart && _uart->rxEnabled) {
|
||||
if (available()) {
|
||||
return uartPeek(_uart);
|
||||
}
|
||||
return -1;
|
||||
@ -79,7 +56,7 @@ int HardwareSerial::peek(void)
|
||||
|
||||
int HardwareSerial::read(void)
|
||||
{
|
||||
if(_uart && _uart->rxEnabled) {
|
||||
if(available()) {
|
||||
return uartRead(_uart);
|
||||
}
|
||||
return -1;
|
||||
@ -87,26 +64,17 @@ int HardwareSerial::read(void)
|
||||
|
||||
void HardwareSerial::flush()
|
||||
{
|
||||
if(_uart == 0 || !_uart->txEnabled) {
|
||||
return;
|
||||
}
|
||||
uartFlush(_uart);
|
||||
}
|
||||
|
||||
size_t HardwareSerial::write(uint8_t c)
|
||||
{
|
||||
if(_uart == 0 || !_uart->txEnabled) {
|
||||
return 0;
|
||||
}
|
||||
uartWrite(_uart, c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t HardwareSerial::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
if(_uart == 0 || !_uart->txEnabled) {
|
||||
return 0;
|
||||
}
|
||||
uartWriteBuf(_uart, buffer, size);
|
||||
return size;
|
||||
}
|
||||
|
Reference in New Issue
Block a user