@@ -42,13 +42,19 @@ void never_reset_uart(uint8_t num) {
42
42
uart_status [num ] = STATUS_NEVER_RESET ;
43
43
}
44
44
45
- static uint8_t pin_init (const uint8_t uart , const mcu_pin_obj_t * pin , const uint8_t pin_type ) {
45
+ static void pin_check (const uint8_t uart , const mcu_pin_obj_t * pin , const uint8_t pin_type ) {
46
46
if (pin == NULL ) {
47
- return NO_PIN ;
47
+ return ;
48
48
}
49
49
if (!(((pin -> number % 4 ) == pin_type ) && ((((pin -> number + 4 ) / 8 ) % NUM_UARTS ) == uart ))) {
50
50
raise_ValueError_invalid_pins ();
51
51
}
52
+ }
53
+
54
+ static uint8_t pin_init (const uint8_t uart , const mcu_pin_obj_t * pin , const uint8_t pin_type ) {
55
+ if (pin == NULL ) {
56
+ return NO_PIN ;
57
+ }
52
58
claim_pin (pin );
53
59
gpio_set_function (pin -> number , GPIO_FUNC_UART );
54
60
return pin -> number ;
@@ -90,10 +96,15 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
90
96
91
97
uint8_t uart_id = ((((tx != NULL ) ? tx -> number : rx -> number ) + 4 ) / 8 ) % NUM_UARTS ;
92
98
99
+ pin_check (uart_id , tx , 0 );
100
+ pin_check (uart_id , rx , 1 );
101
+ pin_check (uart_id , cts , 2 );
102
+ pin_check (uart_id , rts , 3 );
103
+
93
104
if (uart_status [uart_id ] != STATUS_FREE ) {
94
105
mp_raise_ValueError (MP_ERROR_TEXT ("UART peripheral in use" ));
95
106
}
96
- // These may raise exceptions if pins are already in use.
107
+
97
108
self -> tx_pin = pin_init (uart_id , tx , 0 );
98
109
self -> rx_pin = pin_init (uart_id , rx , 1 );
99
110
self -> cts_pin = pin_init (uart_id , cts , 2 );
0 commit comments