Skip to content

Commit c84ce7e

Browse files
authored
Merge pull request arduino#122 from hathach/tinyusb
run usb background when checking for Serial.available() if needed
2 parents d787240 + 3438949 commit c84ce7e

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

cores/arduino/Adafruit_TinyUSB_Core/Adafruit_TinyUSB_Core.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ extern "C"
138138
{
139139

140140
void yield(void)
141-
142141
{
143142
tud_task();
144143
tud_cdc_write_flush();

cores/arduino/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp

Lines changed: 10 additions & 7 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)
@@ -107,11 +113,8 @@ size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size)
107113
remain -= wrcount;
108114
buffer += wrcount;
109115

110-
// Write FIFO is full, flush and re-try
111-
if ( remain )
112-
{
113-
tud_cdc_write_flush();
114-
}
116+
// Write FIFO is full, run usb background to flush
117+
if ( remain ) yield();
115118
}
116119

117120
return size - remain;

0 commit comments

Comments
 (0)