Skip to content

Commit a2e0e2e

Browse files
committed
Support UART_AUX pin function
This can put TX and RX on additional pins!
1 parent 4349a2b commit a2e0e2e

File tree

1 file changed

+20
-2
lines changed
  • ports/raspberrypi/common-hal/busio

1 file changed

+20
-2
lines changed

ports/raspberrypi/common-hal/busio/UART.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ static void pin_check(const uint8_t uart, const mcu_pin_obj_t *pin, const uint8_
4646
if (pin == NULL) {
4747
return;
4848
}
49-
if (!(((pin->number % 4) == pin_type) && ((((pin->number + 4) / 8) % NUM_UARTS) == uart))) {
49+
uint8_t pins_uart = (pin->number + 4) / 8 % NUM_UARTS;
50+
if (pins_uart != uart) {
51+
raise_ValueError_invalid_pins();
52+
}
53+
#ifdef PICO_RP2350
54+
if ((pin_type == 0 && pin->number % 4 == 2) ||
55+
(pin_type == 1 && pin->number % 4 == 3)) {
56+
return;
57+
}
58+
#endif
59+
if ((pin->number % 4) != pin_type) {
5060
raise_ValueError_invalid_pins();
5161
}
5262
}
@@ -56,7 +66,15 @@ static uint8_t pin_init(const uint8_t uart, const mcu_pin_obj_t *pin, const uint
5666
return NO_PIN;
5767
}
5868
claim_pin(pin);
59-
gpio_set_function(pin->number, GPIO_FUNC_UART);
69+
gpio_function_t function = GPIO_FUNC_UART;
70+
#ifdef PICO_RP2350
71+
if ((pin_type == 0 && pin->number % 4 == 2) ||
72+
(pin_type == 1 && pin->number % 4 == 3)) {
73+
function = GPIO_FUNC_UART_AUX;
74+
}
75+
#endif
76+
77+
gpio_set_function(pin->number, function);
6078
return pin->number;
6179
}
6280

0 commit comments

Comments
 (0)