@@ -93,15 +93,27 @@ bool uartIsDriverInstalled(uart_t* uart)
93
93
return false;
94
94
}
95
95
96
- void uartSetPins (uart_t * uart , uint8_t rxPin , uint8_t txPin )
96
+ // Valid pin UART_PIN_NO_CHANGE is defined to (-1)
97
+ // Negative Pin Number will keep it unmodified, thus this function can set individual pins
98
+ void uartSetPins (uart_t * uart , int8_t rxPin , int8_t txPin , int8_t ctsPin , int8_t rtsPin )
97
99
{
98
- if (uart == NULL || rxPin >= SOC_GPIO_PIN_COUNT || txPin >= SOC_GPIO_PIN_COUNT ) {
100
+ if (uart == NULL ) {
99
101
return ;
100
102
}
101
103
UART_MUTEX_LOCK ();
102
- ESP_ERROR_CHECK (uart_set_pin (uart -> num , txPin , rxPin , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE ));
103
- UART_MUTEX_UNLOCK ();
104
+ // IDF uart_set_pin() will issue necessary Error Message and take care of all GPIO Number validation.
105
+ uart_set_pin (uart -> num , txPin , rxPin , ctsPin , rtsPin );
106
+ UART_MUTEX_UNLOCK ();
107
+ }
104
108
109
+ //
110
+ void uartSetHwFlowCtrlMode (uart_t * uart , uint8_t mode , uint8_t threshold ) {
111
+ if (uart == NULL ) {
112
+ return ;
113
+ }
114
+ // IDF will issue corresponding error message when mode or threshold are wrong and prevent crashing
115
+ // IDF will check (mode > HW_FLOWCTRL_CTS_RTS || threshold >= SOC_UART_FIFO_LEN)
116
+ uart_set_hw_flow_ctrl (uart -> num , (uart_hw_flowcontrol_t ) mode , threshold );
105
117
}
106
118
107
119
@@ -111,10 +123,6 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
111
123
return NULL ;
112
124
}
113
125
114
- if (rxPin == -1 && txPin == -1 ) {
115
- return NULL ;
116
- }
117
-
118
126
uart_t * uart = & _uart_bus_array [uart_nr ];
119
127
120
128
if (uart_is_driver_installed (uart_nr )) {
@@ -175,13 +183,13 @@ void uartSetRxInvert(uart_t* uart, bool invert)
175
183
if (uart == NULL )
176
184
return ;
177
185
#if 0
178
- // POTENTIAL ISSUE :: original code only set/reset rxd_inv bit
186
+ // POTENTIAL ISSUE :: original code only set/reset rxd_inv bit
179
187
// IDF or LL set/reset the whole inv_mask!
180
188
if (invert )
181
189
ESP_ERROR_CHECK (uart_set_line_inverse (uart -> num , UART_SIGNAL_RXD_INV ));
182
190
else
183
191
ESP_ERROR_CHECK (uart_set_line_inverse (uart -> num , UART_SIGNAL_INV_DISABLE ));
184
-
192
+
185
193
#else
186
194
// this implementation is better over IDF API because it only affects RXD
187
195
// this is supported in ESP32, ESP32-S2 and ESP32-C3
@@ -466,7 +474,6 @@ void log_print_buf(const uint8_t *b, size_t len){
466
474
*/
467
475
unsigned long uartBaudrateDetect (uart_t * uart , bool flg )
468
476
{
469
- #ifndef CONFIG_IDF_TARGET_ESP32S3
470
477
if (uart == NULL ) {
471
478
return 0 ;
472
479
}
@@ -484,32 +491,29 @@ unsigned long uartBaudrateDetect(uart_t *uart, bool flg)
484
491
UART_MUTEX_UNLOCK ();
485
492
486
493
return ret ;
487
- #else
488
- return 0 ;
489
- #endif
490
494
}
491
495
492
496
493
497
/*
494
498
* To start detection of baud rate with the uart the auto_baud.en bit needs to be cleared and set. The bit period is
495
499
* detected calling uartBadrateDetect(). The raw baudrate is computed using the UART_CLK_FREQ. The raw baudrate is
496
500
* rounded to the closed real baudrate.
497
- *
501
+ *
498
502
* ESP32-C3 reports wrong baud rate detection as shown below:
499
- *
503
+ *
500
504
* This will help in a future recall for the C3.
501
505
* Baud Sent: Baud Read:
502
506
* 300 --> 19536
503
507
* 2400 --> 19536
504
- * 4800 --> 19536
505
- * 9600 --> 28818
508
+ * 4800 --> 19536
509
+ * 9600 --> 28818
506
510
* 19200 --> 57678
507
511
* 38400 --> 115440
508
512
* 57600 --> 173535
509
513
* 115200 --> 347826
510
514
* 230400 --> 701754
511
- *
512
- *
515
+ *
516
+ *
513
517
*/
514
518
void uartStartDetectBaudrate (uart_t * uart ) {
515
519
if (uart == NULL ) {
@@ -531,7 +535,7 @@ void uartStartDetectBaudrate(uart_t *uart) {
531
535
//hw->rx_filt.glitch_filt_en = 1;
532
536
//hw->conf0.autobaud_en = 0;
533
537
//hw->conf0.autobaud_en = 1;
534
- #elif CONFIG_IDF_TARGET_ESP32S3
538
+
535
539
#else
536
540
hw -> auto_baud .glitch_filt = 0x08 ;
537
541
hw -> auto_baud .en = 0 ;
@@ -568,7 +572,6 @@ uartDetectBaudrate(uart_t *uart)
568
572
569
573
#ifdef CONFIG_IDF_TARGET_ESP32C3
570
574
//hw->conf0.autobaud_en = 0;
571
- #elif CONFIG_IDF_TARGET_ESP32S3
572
575
#else
573
576
hw -> auto_baud .en = 0 ;
574
577
#endif
0 commit comments