Skip to content

Commit a899505

Browse files
committed
run usb background when checking for Serial.available() if needed
1 parent d787240 commit a899505

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cores/arduino/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,21 @@ Adafruit_USBD_CDC::operator bool()
6767
bool ret = tud_cdc_connected();
6868

6969
// Add an yield to run usb background in case sketch block wait as follows
70-
// while(!Serial) {}
70+
// while( !Serial ) {}
7171
if ( !ret ) yield();
7272

7373
return ret;
7474
}
7575

7676
int Adafruit_USBD_CDC::available(void)
7777
{
78-
return tud_cdc_available();
78+
uint32_t count = tud_cdc_available();
79+
80+
// Add an yield to run usb background in case sketch block wait as follows
81+
// while( !Serial.available() ) {}
82+
if (!count) yield();
83+
84+
return count;
7985
}
8086

8187
int Adafruit_USBD_CDC::peek(void)

0 commit comments

Comments
 (0)