Repository: raspberrypi/pico-sdk
File: src/rp2_common/pico_stdio_uart/stdio_uart.c (C)

Code before:
#endif
#ifdef PICO_DEFAULT_UART_RX_PIN
    rx_pin = PICO_DEFAULT_UART_RX_PIN;
#endif
    stdio_uart_deinit_full(uart_default, tx_pin, rx_pin);
#endif
}

void stdout_uart_deinit(void) {
#if defined(uart_default) && defined(PICO_DEFAULT_UART_TX_PIN)
    stdio_uart_deinit_full(uart_default, PICO_DEFAULT_UART_TX_PIN, -1);
#endif
}

void stdin_uart_deinit(void) {
#if defined(uart_default) && defined(PICO_DEFAULT_UART_RX_PIN)
    stdio_uart_deinit_full(uart_default, -1, PICO_DEFAULT_UART_RX_PIN);
#endif
}

void stdio_uart_deinit_full(struct uart_inst *uart, int tx_pin, int rx_pin) {
    uart_instance = uart;
    stdio_set_driver_enabled(&stdio_uart, false);
    uart_deinit(uart_instance);
#if HAS_PADS_BANK0_ISOLATION
// Leave pads isolated
    if (tx_pin >= 0) hw_set_bits(&pads_bank0_hw->io[tx_pin], PADS_BANK0_GPIO0_ISO_BITS);
    if (rx_pin >= 0) hw_set_bits(&pads_bank0_hw->io[rx_pin], PADS_BANK0_GPIO0_ISO_BITS);
#else
    ((void)tx_pin);
    ((void)rx_pin);
#endif
}

static void stdio_uart_out_chars(const char *buf, int length) {
    for (int i = 0; i <length; i++) {
        uart_putc(uart_instance, buf[i]);
    }
}

int stdio_uart_in_chars(char *buf, int length) {
    int i=0;
    while (i<length && uart_is_readable(uart_instance)) {
        buf[i++] = uart_getc(uart_instance);
    }
#if PICO_STDIO_UART_SUPPORT_CHARS_AVAILABLE_CALLBACK
    if (chars_available_callback) {
        // Re-enable interrupts after reading a character
        uart_set_irqs_enabled(uart_instance, true, false);
    }
#endif

Review comment (suggestion):
```suggestion
    // Leave pads isolated
```
(for consistency with the previous version)

Code after:
#endif
#ifdef PICO_DEFAULT_UART_RX_PIN
    rx_pin = PICO_DEFAULT_UART_RX_PIN;
#endif
    stdio_uart_deinit_full(uart_default, tx_pin, rx_pin);
#endif
}

void stdout_uart_deinit(void) {
#if defined(uart_default) && defined(PICO_DEFAULT_UART_TX_PIN)
    stdio_uart_deinit_full(uart_default, PICO_DEFAULT_UART_TX_PIN, -1);
#endif
}

void stdin_uart_deinit(void) {
#if defined(uart_default) && defined(PICO_DEFAULT_UART_RX_PIN)
    stdio_uart_deinit_full(uart_default, -1, PICO_DEFAULT_UART_RX_PIN);
#endif
}

void stdio_uart_deinit_full(struct uart_inst *uart, int tx_pin, int rx_pin) {
    uart_instance = uart;
    stdio_set_driver_enabled(&stdio_uart, false);
    uart_deinit(uart_instance);
#if HAS_PADS_BANK0_ISOLATION
    // Leave pads isolated
    if (tx_pin >= 0) hw_set_bits(&pads_bank0_hw->io[tx_pin], PADS_BANK0_GPIO0_ISO_BITS);
    if (rx_pin >= 0) hw_set_bits(&pads_bank0_hw->io[rx_pin], PADS_BANK0_GPIO0_ISO_BITS);
#else
    ((void)tx_pin);
    ((void)rx_pin);
#endif
}

static void stdio_uart_out_chars(const char *buf, int length) {
    for (int i = 0; i <length; i++) {
        uart_putc(uart_instance, buf[i]);
    }
}

int stdio_uart_in_chars(char *buf, int length) {
    int i=0;
    while (i<length && uart_is_readable(uart_instance)) {
        buf[i++] = uart_getc(uart_instance);
    }
#if PICO_STDIO_UART_SUPPORT_CHARS_AVAILABLE_CALLBACK
    if (chars_available_callback) {
        // Re-enable interrupts after reading a character
        uart_set_irqs_enabled(uart_instance, true, false);
    }
#endif