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) {
200
200
} else {
201
201
// Polling mode has no IRQs used
202
202
}
203
+ _break = false ;
203
204
_running = true ;
204
205
}
205
206
@@ -365,6 +366,25 @@ SerialUART::operator bool() {
365
366
return _running;
366
367
}
367
368
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
+
368
388
void arduino::serialEvent1Run (void ) {
369
389
if (serialEvent1 && Serial1.available ()) {
370
390
serialEvent1 ();
@@ -391,8 +411,12 @@ void __not_in_flash_func(SerialUART::_handleIRQ)(bool inIRQ) {
391
411
uart_get_hw (_uart)->icr = UART_UARTICR_RTIC_BITS | UART_UARTICR_RXIC_BITS;
392
412
while (uart_is_readable (_uart)) {
393
413
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
396
420
continue ;
397
421
}
398
422
uint8_t val = raw & 0xff ;
Original file line number Diff line number Diff line change @@ -71,6 +71,10 @@ class SerialUART : public HardwareSerial {
71
71
// Not to be called by users, only from the IRQ handler. In public so that the C-language IQR callback can access it
72
72
void _handleIRQ (bool inIRQ = true );
73
73
74
+ // Allows the user to sleep until a break is received (self-clears the flag
75
+ // on read)
76
+ bool getBreakReceived ();
77
+
74
78
private:
75
79
bool _running = false ;
76
80
uart_inst_t *_uart;
@@ -81,6 +85,7 @@ class SerialUART : public HardwareSerial {
81
85
mutex_t _mutex;
82
86
bool _polling = false ;
83
87
bool _overflow;
88
+ bool _break;
84
89
85
90
// Lockless, IRQ-handled circular queue
86
91
uint32_t _writer;
You can’t perform that action at this time.
0 commit comments