Skip to content

Commit b3ffb3a

Browse files
committed
Return bytes written from RP2040 UART.write()
1 parent 7157693 commit b3ffb3a

File tree

1 file changed

+4
-3
lines changed
  • ports/raspberrypi/common-hal/busio

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,13 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
191191
mp_raise_ValueError(translate("No TX pin"));
192192
}
193193

194-
while (len > 0) {
195-
while (uart_is_writable(self->uart) && len > 0) {
194+
size_t left_to_write = len;
195+
while (left_to_write > 0) {
196+
while (uart_is_writable(self->uart) && left_to_write > 0) {
196197
// Write and advance.
197198
uart_get_hw(self->uart)->dr = *data++;
198199
// Decrease how many chars left to write.
199-
len--;
200+
left_to_write--;
200201
}
201202
RUN_BACKGROUND_TASKS;
202203
}

0 commit comments

Comments
 (0)