You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Adds HardwareSerial::onReceiveTimeout()
* Fixed typo
* Changes requested
* Fix eventQueueReset
* Changed _onReceiveTimeout to _rxTimeout for consistency
* Uniform uart_set_rx_timeout condition
* test _uart not NULL in eventQueueReset()
check if _uart is not NULL before using it.
* revert last commit - no need for it
reverting last change made - it is not necessary.
* adds onReceive() parameter
In order to allow the user to choose if onReceive() call back will be called only when UART Rx timeout happens or also when UART FIFO gets 120 bytes,
a new parameter has been added to onReceive() with the default behavior based on timeout.
void onReceive(OnReceiveCb function, bool onlyOnTimeout = true);
onReceive will setup a callback that will be called whenever an UART interruption occurs (UART_INTR_RXFIFO_FULL or UART_INTR_RXFIFO_TOUT)
UART_INTR_RXFIFO_FULL interrupt triggers at UART_FULL_THRESH_DEFAULT bytes received (defined as 120 bytes by default in IDF)
UART_INTR_RXFIFO_TOUT interrupt triggers at UART_TOUT_THRESH_DEFAULT symbols passed without any reception (defined as 10 symbos by default in IDF)
onlyOnTimeout parameter will define how onReceive will behave:
Default: true -- The callback will only be called when RX Timeout happens.
Whole stream of bytes will be ready for being read on the callback function at once.
This option may lead to Rx Overflow depending on the Rx Buffer Size and number of bytes received in the streaming
false -- The callback will be called when FIFO reaches 120 bytes and also on RX Timeout.
The stream of incommig bytes will be "split" into blocks of 120 bytes on each callback.
This option avoid any sort of Rx Overflow, but leaves the UART packet reassembling work to the Application.
* Adds onReceive() parameter for timeout only
* Adds back setRxTimeout()
* Adds setRxTimeout()
* CI Syntax error - "," missing
Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
Copy file name to clipboardExpand all lines: cores/esp32/HardwareSerial.h
+27-3
Original file line number
Diff line number
Diff line change
@@ -73,10 +73,31 @@ class HardwareSerial: public Stream
73
73
HardwareSerial(int uart_nr);
74
74
~HardwareSerial();
75
75
76
-
// onReceive will setup a callback for whenever UART data is received
77
-
// it will work as UART Rx interrupt -- Using C++ 11 std::fuction
78
-
voidonReceive(OnReceiveCb function);
76
+
// setRxTimeout sets the timeout after which onReceive callback will be called (after receiving data, it waits for this time of UART rx inactivity to call the callback fnc)
77
+
// param symbols_timeout defines a timeout threshold in uart symbol periods. Setting 0 symbol timeout disables the callback call by timeout.
78
+
// Maximum timeout setting is calculacted automatically by IDF. If set above the maximum, it is ignored and an error is printed on Serial0 (check console).
79
+
// Examples: Maximum for 11 bits symbol is 92 (SERIAL_8N2, SERIAL_8E1, SERIAL_8O1, etc), Maximum for 10 bits symbol is 101 (SERIAL_8N1).
80
+
// For example symbols_timeout=1 defines a timeout equal to transmission time of one symbol (~11 bit) on current baudrate.
81
+
// For a baudrate of 9600, SERIAL_8N1 (10 bit symbol) and symbols_timeout = 3, the timeout would be 3 / (9600 / 10) = 3.125 ms
82
+
voidsetRxTimeout(uint8_t symbols_timeout);
83
+
84
+
// onReceive will setup a callback that will be called whenever an UART interruption occurs (UART_INTR_RXFIFO_FULL or UART_INTR_RXFIFO_TOUT)
85
+
// UART_INTR_RXFIFO_FULL interrupt triggers at UART_FULL_THRESH_DEFAULT bytes received (defined as 120 bytes by default in IDF)
86
+
// UART_INTR_RXFIFO_TOUT interrupt triggers at UART_TOUT_THRESH_DEFAULT symbols passed without any reception (defined as 10 symbos by default in IDF)
87
+
// onlyOnTimeout parameter will define how onReceive will behave:
88
+
// Default: true -- The callback will only be called when RX Timeout happens.
89
+
// Whole stream of bytes will be ready for being read on the callback function at once.
90
+
// This option may lead to Rx Overflow depending on the Rx Buffer Size and number of bytes received in the streaming
91
+
// false -- The callback will be called when FIFO reaches 120 bytes and also on RX Timeout.
92
+
// The stream of incommig bytes will be "split" into blocks of 120 bytes on each callback.
93
+
// This option avoid any sort of Rx Overflow, but leaves the UART packet reassembling work to the Application.
0 commit comments