Return bytes written from RP2040 UART.write()

This commit is contained in:
Dan Halbert 2021-04-21 18:38:35 -04:00
parent 71576932a3
commit b3ffb3ab1f
1 changed files with 4 additions and 3 deletions

View File

@ -191,12 +191,13 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
mp_raise_ValueError(translate("No TX pin"));
}
while (len > 0) {
while (uart_is_writable(self->uart) && len > 0) {
size_t left_to_write = len;
while (left_to_write > 0) {
while (uart_is_writable(self->uart) && left_to_write > 0) {
// Write and advance.
uart_get_hw(self->uart)->dr = *data++;
// Decrease how many chars left to write.
len--;
left_to_write--;
}
RUN_BACKGROUND_TASKS;
}