@@ -34,9 +34,6 @@ struct uart_struct_t {
3434 uint8_t num ;
3535 bool has_peek ;
3636 uint8_t peek_byte ;
37- QueueHandle_t uart_event_queue ;
38- void (* onReceive )(void );
39- TaskHandle_t envent_task ;
4037};
4138
4239#if CONFIG_DISABLE_HAL_LOCKS
@@ -45,12 +42,12 @@ struct uart_struct_t {
4542#define UART_MUTEX_UNLOCK ()
4643
4744static uart_t _uart_bus_array [] = {
48- {0 , false, 0 , NULL , NULL , NULL },
45+ {0 , false, 0 },
4946#if SOC_UART_NUM > 1
50- {1 , false, 0 , NULL , NULL , NULL },
47+ {1 , false, 0 },
5148#endif
5249#if SOC_UART_NUM > 2
53- {2 , false, 0 , NULL , NULL , NULL },
50+ {2 , false, 0 },
5451#endif
5552};
5653
@@ -60,12 +57,12 @@ static uart_t _uart_bus_array[] = {
6057#define UART_MUTEX_UNLOCK () xSemaphoreGive(uart->lock)
6158
6259static uart_t _uart_bus_array [] = {
63- {NULL , 0 , false, 0 , NULL , NULL , NULL },
60+ {NULL , 0 , false, 0 },
6461#if SOC_UART_NUM > 1
65- {NULL , 1 , false, 0 , NULL , NULL , NULL },
62+ {NULL , 1 , false, 0 },
6663#endif
6764#if SOC_UART_NUM > 2
68- {NULL , 2 , false, 0 , NULL , NULL , NULL },
65+ {NULL , 2 , false, 0 },
6966#endif
7067};
7168
@@ -84,66 +81,7 @@ uint32_t _get_effective_baudrate(uint32_t baudrate)
8481 }
8582}
8683
87-
88- void uartOnReceive (uart_t * uart , void (* function )(void ))
89- {
90- if (uart == NULL || function == NULL ) {
91- return ;
92- }
93- UART_MUTEX_LOCK ();
94- uart -> onReceive = function ;
95- UART_MUTEX_UNLOCK ();
96- }
97-
98-
99- static void uart_event_task (void * args )
100- {
101- uart_t * uart = (uart_t * )args ;
102- uart_event_t event ;
103- for (;;) {
104- //Waiting for UART event.
105- if (xQueueReceive (uart -> uart_event_queue , (void * )& event , (portTickType )portMAX_DELAY )) {
106- switch (event .type ) {
107- //Event of UART receving data
108- case UART_DATA :
109- if (uart -> onReceive ) uart -> onReceive ();
110- break ;
111- //Event of HW FIFO overflow detected
112- case UART_FIFO_OVF :
113- log_w ("UART%d FIFO Overflow. Flushing data. Consider adding Flow Control to your Application." , uart -> num );
114- uart_flush_input (uart -> num );
115- xQueueReset (uart -> uart_event_queue );
116- break ;
117- //Event of UART ring buffer full
118- case UART_BUFFER_FULL :
119- log_w ("UART%d Buffer Full. Flushing data. Consider encreasing your buffer size of your Application." , uart -> num );
120- uart_flush_input (uart -> num );
121- xQueueReset (uart -> uart_event_queue );
122- break ;
123- //Event of UART RX break detected
124- case UART_BREAK :
125- log_w ("UART%d RX break." , uart -> num );
126- break ;
127- //Event of UART parity check error
128- case UART_PARITY_ERR :
129- log_w ("UART%d parity error." , uart -> num );
130- break ;
131- //Event of UART frame error
132- case UART_FRAME_ERR :
133- log_w ("UART%d frame error." , uart -> num );
134- break ;
135- //Others
136- default :
137- log_w ("UART%d unknown event type %d." , uart -> num , event .type );
138- break ;
139- }
140- }
141- }
142- vTaskDelete (NULL );
143- }
144-
145-
146- bool uartIsDriverInstalled (uart_t * uart )
84+ bool uartIsDriverInstalled (uart_t * uart )
14785{
14886 if (uart == NULL ) {
14987 return 0 ;
@@ -204,20 +142,14 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
204142 uart_config .source_clk = UART_SCLK_APB ;
205143
206144
207- ESP_ERROR_CHECK (uart_driver_install (uart_nr , 2 * queueLen , 0 , 20 , & ( uart -> uart_event_queue ) , 0 ));
145+ ESP_ERROR_CHECK (uart_driver_install (uart_nr , 2 * queueLen , 0 , 0 , NULL , 0 ));
208146 ESP_ERROR_CHECK (uart_param_config (uart_nr , & uart_config ));
209147 ESP_ERROR_CHECK (uart_set_pin (uart_nr , txPin , rxPin , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE ));
210148
211149 // Is it right or the idea is to swap rx and tx pins?
212150 if (inverted ) {
213151 // invert signal for both Rx and Tx
214- ESP_ERROR_CHECK (uart_set_line_inverse (uart_nr , UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV ));
215- }
216-
217- // Creating UART event Task
218- xTaskCreate (uart_event_task , "uart_event_task" , 2048 , uart , configMAX_PRIORITIES - 1 , & (uart -> envent_task ));
219- if (!uart -> envent_task ) {
220- log_e (" -- UART%d Event Task not Created!" , uart_nr );
152+ ESP_ERROR_CHECK (uart_set_line_inverse (uart_nr , UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV ));
221153 }
222154
223155 UART_MUTEX_UNLOCK ();
@@ -234,11 +166,6 @@ void uartEnd(uart_t* uart)
234166
235167 UART_MUTEX_LOCK ();
236168 uart_driver_delete (uart -> num );
237- if (uart -> envent_task ) {
238- vTaskDelete (uart -> envent_task );
239- uart -> envent_task = NULL ;
240- uart -> onReceive = NULL ;
241- }
242169 UART_MUTEX_UNLOCK ();
243170}
244171
@@ -263,7 +190,7 @@ void uartSetRxInvert(uart_t* uart, bool invert)
263190 hw -> conf0 .rxd_inv = 1 ;
264191 else
265192 hw -> conf0 .rxd_inv = 0 ;
266- #endif
193+ #endif
267194}
268195
269196
@@ -289,7 +216,7 @@ uint32_t uartAvailableForWrite(uart_t* uart)
289216 return 0 ;
290217 }
291218 UART_MUTEX_LOCK ();
292- uint32_t available = uart_ll_get_txfifo_len (UART_LL_GET_HW (uart -> num ));
219+ uint32_t available = uart_ll_get_txfifo_len (UART_LL_GET_HW (uart -> num ));
293220 UART_MUTEX_UNLOCK ();
294221 return available ;
295222}
@@ -373,7 +300,7 @@ void uartFlushTxOnly(uart_t* uart, bool txOnly)
373300 if (uart == NULL ) {
374301 return ;
375302 }
376-
303+
377304 UART_MUTEX_LOCK ();
378305 while (!uart_ll_is_tx_idle (UART_LL_GET_HW (uart -> num )));
379306
@@ -486,7 +413,7 @@ int log_printf(const char *format, ...)
486413 xSemaphoreTake (_uart_bus_array [s_uart_debug_nr ].lock , portMAX_DELAY );
487414 }
488415#endif
489-
416+
490417 vsnprintf (temp , len + 1 , format , arg );
491418 ets_printf ("%s" , temp );
492419
@@ -592,10 +519,10 @@ void uartStartDetectBaudrate(uart_t *uart) {
592519 uart_dev_t * hw = UART_LL_GET_HW (uart -> num );
593520
594521#ifdef CONFIG_IDF_TARGET_ESP32C3
595-
522+
596523 // ESP32-C3 requires further testing
597- // Baud rate detection returns wrong values
598-
524+ // Baud rate detection returns wrong values
525+
599526 log_e ("ESP32-C3 baud rate detection is not supported." );
600527 return ;
601528
@@ -611,7 +538,7 @@ void uartStartDetectBaudrate(uart_t *uart) {
611538 hw -> auto_baud .en = 1 ;
612539#endif
613540}
614-
541+
615542unsigned long
616543uartDetectBaudrate (uart_t * uart )
617544{
@@ -669,4 +596,4 @@ uartDetectBaudrate(uart_t *uart)
669596 log_e ("ESP32-C3 baud rate detection is not supported." );
670597 return 0 ;
671598#endif
672- }
599+ }
0 commit comments