File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,7 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
200200 } else {
201201 // Polling mode has no IRQs used
202202 }
203+ _break = false ;
203204 _running = true ;
204205}
205206
@@ -365,6 +366,25 @@ SerialUART::operator bool() {
365366 return _running;
366367}
367368
369+ bool SerialUART::getBreakReceived () {
370+ if (!_running) {
371+ return false ;
372+ }
373+
374+ if (_polling) {
375+ _handleIRQ (false );
376+ } else {
377+ _pumpFIFO ();
378+ }
379+
380+ mutex_enter_blocking (&_fifoMutex);
381+ bool break_received = _break;
382+ _break = false ;
383+ mutex_exit (&_fifoMutex);
384+
385+ return break_received;
386+ }
387+
368388void arduino::serialEvent1Run (void ) {
369389 if (serialEvent1 && Serial1.available ()) {
370390 serialEvent1 ();
@@ -391,8 +411,12 @@ void __not_in_flash_func(SerialUART::_handleIRQ)(bool inIRQ) {
391411 uart_get_hw (_uart)->icr = UART_UARTICR_RTIC_BITS | UART_UARTICR_RXIC_BITS;
392412 while (uart_is_readable (_uart)) {
393413 uint32_t raw = uart_get_hw (_uart)->dr ;
394- if (raw & 0x700 ) {
395- // Framing, Parity, or Break. Ignore this bad char
414+ if (raw & 0x400 ) {
415+ // break!
416+ _break = true ;
417+ continue ;
418+ } else if (raw & 0x300 ) {
419+ // Framing, Parity Error. Ignore this bad char
396420 continue ;
397421 }
398422 uint8_t val = raw & 0xff ;
Original file line number Diff line number Diff line change @@ -71,6 +71,10 @@ class SerialUART : public HardwareSerial {
7171 // Not to be called by users, only from the IRQ handler. In public so that the C-language IQR callback can access it
7272 void _handleIRQ (bool inIRQ = true );
7373
74+ // Allows the user to sleep until a break is received (self-clears the flag
75+ // on read)
76+ bool getBreakReceived ();
77+
7478private:
7579 bool _running = false ;
7680 uart_inst_t *_uart;
@@ -81,6 +85,7 @@ class SerialUART : public HardwareSerial {
8185 mutex_t _mutex;
8286 bool _polling = false ;
8387 bool _overflow;
88+ bool _break;
8489
8590 // Lockless, IRQ-handled circular queue
8691 uint32_t _writer;
You can’t perform that action at this time.
0 commit comments