Skip to content

Commit cd57c19

Browse files
ci(pre-commit): Apply automatic fixes
1 parent 8943e27 commit cd57c19

File tree

3 files changed

+58
-56
lines changed

3 files changed

+58
-56
lines changed

cores/esp32/HardwareSerial.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
360360
txPin = _txPin < 0 ? (int8_t)TX1 : _txPin;
361361
}
362362
break;
363-
#endif // UART_NUM_1
363+
#endif // UART_NUM_1
364364
#if SOC_UART_HP_NUM > 2
365365
case UART_NUM_2:
366366
if (rxPin < 0 && txPin < 0) {
@@ -386,7 +386,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
386386
#endif
387387
}
388388
break;
389-
#endif // UART_NUM_3
389+
#endif // UART_NUM_3
390390
#if SOC_UART_HP_NUM > 4
391391
case UART_NUM_4:
392392
if (rxPin < 0 && txPin < 0) {
@@ -405,14 +405,14 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
405405
if (rxPin < 0 && txPin < 0) {
406406
// do not change RX0_LP/TX0_LP if it has already been set before
407407
#ifdef LP_RX0
408-
rxPin = _rxPin < 0 ? (int8_t)LP_RX0 : _rxPin;
408+
rxPin = _rxPin < 0 ? (int8_t)LP_RX0 : _rxPin;
409409
#endif
410410
#ifdef LP_TX0
411411
txPin = _txPin < 0 ? (int8_t)LP_TX0 : _txPin;
412412
#endif
413413
}
414414
break;
415-
#endif // LP_UART_NUM_0
415+
#endif // LP_UART_NUM_0
416416
}
417417
}
418418

@@ -628,7 +628,7 @@ size_t HardwareSerial::setRxBufferSize(size_t new_size) {
628628
return 0;
629629
}
630630
uint8_t FIFOLen = UART_HW_FIFO_LEN(_uart_nr);
631-
// Valid value is higher than the FIFO length
631+
// Valid value is higher than the FIFO length
632632
if (new_size <= FIFOLen) {
633633
new_size = FIFOLen + 1;
634634
log_w("RX Buffer set to minimum value: %d.", new_size);
@@ -648,7 +648,7 @@ size_t HardwareSerial::setTxBufferSize(size_t new_size) {
648648
}
649649
uint8_t FIFOLen = UART_HW_FIFO_LEN(_uart_nr);
650650
// Valid values are zero or higher than the FIFO length
651-
if (new_size > 0 && new_size <= FIFOLen) {
651+
if (new_size > 0 && new_size <= FIFOLen) {
652652
new_size = FIFOLen + 1;
653653
log_w("TX Buffer set to minimum value: %d.", new_size);
654654
}

cores/esp32/HardwareSerial.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ typedef enum {
214214

215215
#if SOC_UART_LP_NUM >= 1
216216
#ifndef LP_RX0
217-
#define LP_RX0 (gpio_num_t)LP_U0RXD_GPIO_NUM
217+
#define LP_RX0 (gpio_num_t) LP_U0RXD_GPIO_NUM
218218
#endif
219219

220220
#ifndef LP_TX0
221-
#define LP_TX0 (gpio_num_t)LP_U0TXD_GPIO_NUM
221+
#define LP_TX0 (gpio_num_t) LP_U0TXD_GPIO_NUM
222222
#endif
223223
#endif /* SOC_UART_LP_NUM >= 1 */
224224

cores/esp32/esp32-hal-uart.c

+50-48
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct uart_struct_t {
6767

6868
static uart_t _uart_bus_array[] = {
6969
{0, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0},
70-
#if SOC_UART_NUM > 1
70+
#if SOC_UART_NUM > 1
7171
{1, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0},
7272
#endif
7373
#if SOC_UART_NUM > 2
@@ -117,8 +117,7 @@ static uart_t _uart_bus_array[] = {
117117

118118
#if SOC_UART_LP_NUM >= 1
119119
// LP UART enable pins routine
120-
static bool lp_uart_config_io(uint8_t uart_num, int8_t pin, rtc_gpio_mode_t direction, uint32_t idx)
121-
{
120+
static bool lp_uart_config_io(uint8_t uart_num, int8_t pin, rtc_gpio_mode_t direction, uint32_t idx) {
122121
/* Skip configuration if the LP_IO is -1 */
123122
if (pin < 0) {
124123
return true;
@@ -138,21 +137,21 @@ static bool lp_uart_config_io(uint8_t uart_num, int8_t pin, rtc_gpio_mode_t dire
138137

139138
// Connect pins
140139
const uart_periph_sig_t *upin = &uart_periph_signal[uart_num].pins[idx];
141-
#if !SOC_LP_GPIO_MATRIX_SUPPORTED // ESP32-C6/C61/C5
140+
#if !SOC_LP_GPIO_MATRIX_SUPPORTED // ESP32-C6/C61/C5
142141
// When LP_IO Matrix is not support, LP_IO Mux must be connected to the pins
143142
if (rtc_gpio_iomux_func_sel(pin, upin->iomux_func) != ESP_OK) {
144143
log_e("Failed to set LP_IO pin %d into Mux function", pin);
145144
return false;
146145
}
147-
#else // So far, only ESP32-P4
146+
#else // So far, only ESP32-P4
148147
// If the configured pin is the default LP_IO Mux pin for LP UART, then set the LP_IO MUX function
149148
if (upin->default_gpio == pin) {
150149
if (rtc_gpio_iomux_func_sel(pin, upin->iomux_func) != ESP_OK) {
151150
log_e("Failed to set LP_IO pin %d into Mux function", pin);
152151
return false;
153152
}
154153
} else {
155-
// Otherwise, set the LP_IO Matrix and select FUNC1
154+
// Otherwise, set the LP_IO Matrix and select FUNC1
156155
if (rtc_gpio_iomux_func_sel(pin, 1) != ESP_OK) {
157156
log_e("Failed to set LP_IO pin %d into Mux function GPIO", pin);
158157
return false;
@@ -169,43 +168,43 @@ static bool lp_uart_config_io(uint8_t uart_num, int8_t pin, rtc_gpio_mode_t dire
169168
return false;
170169
}
171170
}
172-
#endif // SOC_LP_GPIO_MATRIX_SUPPORTED
171+
#endif // SOC_LP_GPIO_MATRIX_SUPPORTED
173172

174173
return true;
175174
}
176175

177176
// When LP UART needs the RTC IO MUX to set the pin, it will always have fixed pins for RX, TX, CTS and RTS
178177
static bool lpuartCheckPins(int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin, uint8_t uart_nr) {
179-
// check if LP UART is being used and if the pins are valid
180-
#if !SOC_LP_GPIO_MATRIX_SUPPORTED // ESP32-C6/C61/C5
181-
uint16_t lp_uart_fixed_pin = uart_periph_signal[uart_nr].pins[SOC_UART_RX_PIN_IDX].default_gpio;
182-
if (uart_nr >= SOC_UART_HP_NUM) { // it is a LP UART NUM
183-
if (rxPin > 0 && rxPin != lp_uart_fixed_pin) {
184-
log_e("UART%d LP UART requires RX pin to be set to %d.", uart_nr, lp_uart_fixed_pin);
185-
return false;
186-
}
187-
lp_uart_fixed_pin = uart_periph_signal[uart_nr].pins[SOC_UART_TX_PIN_IDX].default_gpio;
188-
if (txPin > 0 && txPin != lp_uart_fixed_pin) {
189-
log_e("UART%d LP UART requires TX pin to be set to %d.", uart_nr, lp_uart_fixed_pin);
190-
return false;
191-
}
192-
lp_uart_fixed_pin = uart_periph_signal[uart_nr].pins[SOC_UART_CTS_PIN_IDX].default_gpio;
193-
if (ctsPin > 0 && ctsPin != lp_uart_fixed_pin) {
194-
log_e("UART%d LP UART requires CTS pin to be set to %d.", uart_nr, lp_uart_fixed_pin);
195-
return false;
196-
}
197-
lp_uart_fixed_pin = uart_periph_signal[uart_nr].pins[SOC_UART_RTS_PIN_IDX].default_gpio;
198-
if (rtsPin > 0 && rtsPin != lp_uart_fixed_pin) {
199-
log_e("UART%d LP UART requires RTS pin to be set to %d.", uart_nr, lp_uart_fixed_pin);
200-
return false;
201-
}
178+
// check if LP UART is being used and if the pins are valid
179+
#if !SOC_LP_GPIO_MATRIX_SUPPORTED // ESP32-C6/C61/C5
180+
uint16_t lp_uart_fixed_pin = uart_periph_signal[uart_nr].pins[SOC_UART_RX_PIN_IDX].default_gpio;
181+
if (uart_nr >= SOC_UART_HP_NUM) { // it is a LP UART NUM
182+
if (rxPin > 0 && rxPin != lp_uart_fixed_pin) {
183+
log_e("UART%d LP UART requires RX pin to be set to %d.", uart_nr, lp_uart_fixed_pin);
184+
return false;
185+
}
186+
lp_uart_fixed_pin = uart_periph_signal[uart_nr].pins[SOC_UART_TX_PIN_IDX].default_gpio;
187+
if (txPin > 0 && txPin != lp_uart_fixed_pin) {
188+
log_e("UART%d LP UART requires TX pin to be set to %d.", uart_nr, lp_uart_fixed_pin);
189+
return false;
190+
}
191+
lp_uart_fixed_pin = uart_periph_signal[uart_nr].pins[SOC_UART_CTS_PIN_IDX].default_gpio;
192+
if (ctsPin > 0 && ctsPin != lp_uart_fixed_pin) {
193+
log_e("UART%d LP UART requires CTS pin to be set to %d.", uart_nr, lp_uart_fixed_pin);
194+
return false;
195+
}
196+
lp_uart_fixed_pin = uart_periph_signal[uart_nr].pins[SOC_UART_RTS_PIN_IDX].default_gpio;
197+
if (rtsPin > 0 && rtsPin != lp_uart_fixed_pin) {
198+
log_e("UART%d LP UART requires RTS pin to be set to %d.", uart_nr, lp_uart_fixed_pin);
199+
return false;
200+
}
202201
}
203202
return true;
204-
#else // ESP32-P4 can set any pin for LP UART
203+
#else // ESP32-P4 can set any pin for LP UART
205204
return true;
206-
#endif // SOC_LP_GPIO_MATRIX_SUPPORTED
205+
#endif // SOC_LP_GPIO_MATRIX_SUPPORTED
207206
}
208-
#endif // SOC_UART_LP_NUM >= 1
207+
#endif // SOC_UART_LP_NUM >= 1
209208

210209
// Negative Pin Number will keep it unmodified, thus this function can detach individual pins
211210
// This function will also unset the pins in the Peripheral Manager and set the pin to -1 after detaching
@@ -305,7 +304,7 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
305304
uart_t *uart = &_uart_bus_array[uart_num];
306305
//log_v("attaching UART%d pins: prev,new RX(%d,%d) TX(%d,%d) CTS(%d,%d) RTS(%d,%d)", uart_num,
307306
// uart->_rxPin, rxPin, uart->_txPin, txPin, uart->_ctsPin, ctsPin, uart->_rtsPin, rtsPin); vTaskDelay(10);
308-
307+
309308
// IDF uart_set_pin() checks if the pin is used within LP UART and if it is a valid RTC IO pin
310309
// No need for Arduino Layer to check it again
311310
bool retCode = true;
@@ -317,7 +316,7 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
317316
// connect RX Pad
318317
bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
319318
#if SOC_UART_LP_NUM >= 1
320-
if (ret && uart_num >= SOC_UART_HP_NUM) { // it is a LP UART NUM
319+
if (ret && uart_num >= SOC_UART_HP_NUM) { // it is a LP UART NUM
321320
ret &= lp_uart_config_io(uart->num, rxPin, RTC_GPIO_MODE_INPUT_ONLY, SOC_UART_RX_PIN_IDX);
322321
}
323322
#endif
@@ -340,7 +339,7 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
340339
// connect TX Pad
341340
bool ret = ESP_OK == uart_set_pin(uart->num, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
342341
#if SOC_UART_LP_NUM >= 1
343-
if (ret && uart_num >= SOC_UART_HP_NUM) { // it is a LP UART NUM
342+
if (ret && uart_num >= SOC_UART_HP_NUM) { // it is a LP UART NUM
344343
ret &= lp_uart_config_io(uart->num, txPin, RTC_GPIO_MODE_OUTPUT_ONLY, SOC_UART_TX_PIN_IDX);
345344
}
346345
#endif
@@ -363,7 +362,7 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
363362
// connect CTS Pad
364363
bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, ctsPin);
365364
#if SOC_UART_LP_NUM >= 1
366-
if (ret && uart_num >= SOC_UART_HP_NUM) { // it is a LP UART NUM
365+
if (ret && uart_num >= SOC_UART_HP_NUM) { // it is a LP UART NUM
367366
ret &= lp_uart_config_io(uart->num, ctsPin, RTC_GPIO_MODE_INPUT_ONLY, SOC_UART_CTS_PIN_IDX);
368367
}
369368
#endif
@@ -386,7 +385,7 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
386385
// connect RTS Pad
387386
bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, rtsPin, UART_PIN_NO_CHANGE);
388387
#if SOC_UART_LP_NUM >= 1
389-
if (ret && uart_num >= SOC_UART_HP_NUM) { // it is a LP UART NUM
388+
if (ret && uart_num >= SOC_UART_HP_NUM) { // it is a LP UART NUM
390389
ret &= lp_uart_config_io(uart->num, rtsPin, RTC_GPIO_MODE_OUTPUT_ONLY, SOC_UART_RTS_PIN_IDX);
391390
}
392391
#endif
@@ -551,7 +550,7 @@ uart_t *uartBegin(
551550
}
552551
uart_t *uart = &_uart_bus_array[uart_nr];
553552
log_v("UART%d baud(%ld) Mode(%x) rxPin(%d) txPin(%d)", uart_nr, baudrate, config, rxPin, txPin);
554-
553+
555554
#if SOC_UART_LP_NUM >= 1
556555
// check if LP UART is being used and if the pins are valid
557556
if (!lpuartCheckPins(rxPin, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, uart_nr)) {
@@ -664,14 +663,17 @@ uart_t *uartBegin(
664663
uart_config.stop_bits = (config & 0x30) >> 4;
665664
uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
666665
uart_config.rx_flow_ctrl_thresh = rxfifo_full_thrhd >= UART_HW_FIFO_LEN(uart_nr) ? UART_HW_FIFO_LEN(uart_nr) - 6 : rxfifo_full_thrhd;
667-
log_v("UART%d RX FIFO full threshold set to %d (value requested: %d || FIFO Max = %d)", uart_nr, uart_config.rx_flow_ctrl_thresh, rxfifo_full_thrhd, UART_HW_FIFO_LEN(uart_nr));
668-
rxfifo_full_thrhd = uart_config.rx_flow_ctrl_thresh; // makes sure that it will be set correctly in the struct
666+
log_v(
667+
"UART%d RX FIFO full threshold set to %d (value requested: %d || FIFO Max = %d)", uart_nr, uart_config.rx_flow_ctrl_thresh, rxfifo_full_thrhd,
668+
UART_HW_FIFO_LEN(uart_nr)
669+
);
670+
rxfifo_full_thrhd = uart_config.rx_flow_ctrl_thresh; // makes sure that it will be set correctly in the struct
669671
uart_config.baud_rate = baudrate;
670672
#if SOC_UART_LP_NUM >= 1
671-
if (uart_nr >= SOC_UART_HP_NUM) { // it is a LP UART NUM
673+
if (uart_nr >= SOC_UART_HP_NUM) { // it is a LP UART NUM
672674
uart_config.lp_source_clk = LP_UART_SCLK_DEFAULT; // use default LP clock
673675
log_v("Setting UART%d to use LP clock", uart_nr);
674-
} else
676+
} else
675677
#endif
676678
{
677679
// there is an issue when returning from light sleep with the C6 and H2: the uart baud rate is not restored
@@ -982,11 +984,11 @@ void uartSetBaudRate(uart_t *uart, uint32_t baud_rate) {
982984
newClkSrc = LP_UART_SCLK_DEFAULT; // use default LP clock
983985
}
984986
#endif
985-
// ESP32-P4 demands an atomic operation for setting the clock source
986-
HP_UART_SRC_CLK_ATOMIC() {
987-
uart_ll_set_sclk(UART_LL_GET_HW(uart->num), newClkSrc);
988-
}
989-
#else // ESP32, ESP32-S2
987+
// ESP32-P4 demands an atomic operation for setting the clock source
988+
HP_UART_SRC_CLK_ATOMIC() {
989+
uart_ll_set_sclk(UART_LL_GET_HW(uart->num), newClkSrc);
990+
}
991+
#else // ESP32, ESP32-S2
990992
soc_module_clk_t newClkSrc = baud_rate <= REF_TICK_BAUDRATE_LIMIT ? SOC_MOD_CLK_REF_TICK : SOC_MOD_CLK_APB;
991993
uart_ll_set_sclk(UART_LL_GET_HW(uart->num), newClkSrc);
992994
#endif

0 commit comments

Comments
 (0)