@@ -34,9 +34,6 @@ struct uart_struct_t {
34
34
uint8_t num ;
35
35
bool has_peek ;
36
36
uint8_t peek_byte ;
37
- QueueHandle_t uart_event_queue ;
38
- void (* onReceive )(void );
39
- TaskHandle_t envent_task ;
40
37
};
41
38
42
39
#if CONFIG_DISABLE_HAL_LOCKS
@@ -45,12 +42,12 @@ struct uart_struct_t {
45
42
#define UART_MUTEX_UNLOCK ()
46
43
47
44
static uart_t _uart_bus_array [] = {
48
- {0 , false, 0 , NULL , NULL , NULL },
45
+ {0 , false, 0 },
49
46
#if SOC_UART_NUM > 1
50
- {1 , false, 0 , NULL , NULL , NULL },
47
+ {1 , false, 0 },
51
48
#endif
52
49
#if SOC_UART_NUM > 2
53
- {2 , false, 0 , NULL , NULL , NULL },
50
+ {2 , false, 0 },
54
51
#endif
55
52
};
56
53
@@ -60,12 +57,12 @@ static uart_t _uart_bus_array[] = {
60
57
#define UART_MUTEX_UNLOCK () xSemaphoreGive(uart->lock)
61
58
62
59
static uart_t _uart_bus_array [] = {
63
- {NULL , 0 , false, 0 , NULL , NULL , NULL },
60
+ {NULL , 0 , false, 0 },
64
61
#if SOC_UART_NUM > 1
65
- {NULL , 1 , false, 0 , NULL , NULL , NULL },
62
+ {NULL , 1 , false, 0 },
66
63
#endif
67
64
#if SOC_UART_NUM > 2
68
- {NULL , 2 , false, 0 , NULL , NULL , NULL },
65
+ {NULL , 2 , false, 0 },
69
66
#endif
70
67
};
71
68
@@ -84,66 +81,7 @@ uint32_t _get_effective_baudrate(uint32_t baudrate)
84
81
}
85
82
}
86
83
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 )
147
85
{
148
86
if (uart == NULL ) {
149
87
return 0 ;
@@ -204,20 +142,14 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
204
142
uart_config .source_clk = UART_SCLK_APB ;
205
143
206
144
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 ));
208
146
ESP_ERROR_CHECK (uart_param_config (uart_nr , & uart_config ));
209
147
ESP_ERROR_CHECK (uart_set_pin (uart_nr , txPin , rxPin , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE ));
210
148
211
149
// Is it right or the idea is to swap rx and tx pins?
212
150
if (inverted ) {
213
151
// 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 ));
221
153
}
222
154
223
155
UART_MUTEX_UNLOCK ();
@@ -234,11 +166,6 @@ void uartEnd(uart_t* uart)
234
166
235
167
UART_MUTEX_LOCK ();
236
168
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
- }
242
169
UART_MUTEX_UNLOCK ();
243
170
}
244
171
@@ -263,7 +190,7 @@ void uartSetRxInvert(uart_t* uart, bool invert)
263
190
hw -> conf0 .rxd_inv = 1 ;
264
191
else
265
192
hw -> conf0 .rxd_inv = 0 ;
266
- #endif
193
+ #endif
267
194
}
268
195
269
196
@@ -289,7 +216,7 @@ uint32_t uartAvailableForWrite(uart_t* uart)
289
216
return 0 ;
290
217
}
291
218
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 ));
293
220
UART_MUTEX_UNLOCK ();
294
221
return available ;
295
222
}
@@ -373,7 +300,7 @@ void uartFlushTxOnly(uart_t* uart, bool txOnly)
373
300
if (uart == NULL ) {
374
301
return ;
375
302
}
376
-
303
+
377
304
UART_MUTEX_LOCK ();
378
305
while (!uart_ll_is_tx_idle (UART_LL_GET_HW (uart -> num )));
379
306
@@ -486,7 +413,7 @@ int log_printf(const char *format, ...)
486
413
xSemaphoreTake (_uart_bus_array [s_uart_debug_nr ].lock , portMAX_DELAY );
487
414
}
488
415
#endif
489
-
416
+
490
417
vsnprintf (temp , len + 1 , format , arg );
491
418
ets_printf ("%s" , temp );
492
419
@@ -592,10 +519,10 @@ void uartStartDetectBaudrate(uart_t *uart) {
592
519
uart_dev_t * hw = UART_LL_GET_HW (uart -> num );
593
520
594
521
#ifdef CONFIG_IDF_TARGET_ESP32C3
595
-
522
+
596
523
// ESP32-C3 requires further testing
597
- // Baud rate detection returns wrong values
598
-
524
+ // Baud rate detection returns wrong values
525
+
599
526
log_e ("ESP32-C3 baud rate detection is not supported." );
600
527
return ;
601
528
@@ -611,7 +538,7 @@ void uartStartDetectBaudrate(uart_t *uart) {
611
538
hw -> auto_baud .en = 1 ;
612
539
#endif
613
540
}
614
-
541
+
615
542
unsigned long
616
543
uartDetectBaudrate (uart_t * uart )
617
544
{
@@ -669,4 +596,4 @@ uartDetectBaudrate(uart_t *uart)
669
596
log_e ("ESP32-C3 baud rate detection is not supported." );
670
597
return 0 ;
671
598
#endif
672
- }
599
+ }
0 commit comments