Skip to content

Commit da8ab1e

Browse files
Return # of bytes written by SerialUSB::write (#662)
Before always returned 0 on a ::write. Now properly return the count of bytes that were sent to the USB port. Thanks to Terry Haas for the report.
1 parent baf65f5 commit da8ab1e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cores/rp2040/SerialUSB.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ size_t SerialUSB::write(const uint8_t *buf, size_t length) {
123123
}
124124

125125
static uint64_t last_avail_time;
126-
int i = 0;
126+
int written = 0;
127127
if (tud_cdc_connected()) {
128128
for (size_t i = 0; i < length;) {
129129
int n = length - i;
@@ -136,6 +136,7 @@ size_t SerialUSB::write(const uint8_t *buf, size_t length) {
136136
tud_task();
137137
tud_cdc_write_flush();
138138
i += n2;
139+
written += n2;
139140
last_avail_time = time_us_64();
140141
} else {
141142
tud_task();
@@ -150,7 +151,7 @@ size_t SerialUSB::write(const uint8_t *buf, size_t length) {
150151
// reset our timeout
151152
last_avail_time = 0;
152153
}
153-
return i;
154+
return written;
154155
}
155156

156157
SerialUSB::operator bool() {

0 commit comments

Comments
 (0)