Skip to content

feat (uart): implement proper operator bool() #2712

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions cores/arduino/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,14 @@ void HardwareSerial::begin(unsigned long baud, byte config)
uart_init(&_serial, (uint32_t)baud, databits, parity, stopbits, _rx_invert, _tx_invert, _data_invert);
enableHalfDuplexRx();
uart_attach_rx_callback(&_serial, _rx_complete_irq);

_ready = true;
}

void HardwareSerial::end()
{
_ready = false;

// wait for transmission of outgoing data
flush(TX_TIMEOUT);

Expand Down
3 changes: 2 additions & 1 deletion cores/arduino/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class HardwareSerial : public Stream {
using Print::write; // pull in write(str) from Print
operator bool()
{
return true;
return _ready;
}

void setRx(uint32_t _rx);
Expand Down Expand Up @@ -189,6 +189,7 @@ class HardwareSerial : public Stream {
#endif // HAL_UART_MODULE_ENABLED && !HAL_UART_MODULE_ONLY

private:
bool _ready;
bool _rx_enabled;
uint8_t _config;
unsigned long _baud;
Expand Down