Skip to content

Commit f5aeb38

Browse files
committed
move tud cdc write flush to yield(), add yield() to Stream timeRead(), timePeek()
1 parent 36f5be1 commit f5aeb38

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ int Adafruit_USBD_CDC::read(void)
8282
return (int) tud_cdc_read_char();
8383
}
8484

85-
size_t Adafruit_USBD_CDC::readBytes(char *buffer, size_t length)
86-
{
87-
return tud_cdc_read(buffer, length);
88-
}
89-
9085
void Adafruit_USBD_CDC::flush(void)
9186
{
9287
tud_cdc_write_flush();

cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ class Adafruit_USBD_CDC : public Stream, Adafruit_USBD_Interface
5151
return write((const uint8_t *)buffer, size);
5252
}
5353
operator bool();
54-
55-
size_t readBytes(char *buffer, size_t length);
56-
size_t readBytes(uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
5754
};
5855

5956
extern Adafruit_USBD_CDC Serial;

cores/nRF5/Stream.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ int Stream::timedRead()
3535
do {
3636
c = read();
3737
if (c >= 0) return c;
38+
yield(); // running TinyUSB task
3839
} while(millis() - _startMillis < _timeout);
3940
return -1; // -1 indicates timeout
4041
}
@@ -47,6 +48,7 @@ int Stream::timedPeek()
4748
do {
4849
c = peek();
4950
if (c >= 0) return c;
51+
yield(); // running TinyUSB task
5052
} while(millis() - _startMillis < _timeout);
5153
return -1; // -1 indicates timeout
5254
}

cores/nRF5/main.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ static void loop_task(void* arg)
5656
while (1)
5757
{
5858
loop();
59-
60-
#ifdef USE_TINYUSB
61-
tud_cdc_write_flush();
62-
#endif
59+
yield(); // yield run usb background task
6360

6461
// Serial events
6562
if (serialEvent && serialEventRun) serialEventRun();

cores/nRF5/rtos.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838

3939
SchedulerRTOS Scheduler;
4040

41-
void yield(void)
42-
{
43-
taskYIELD();
44-
}
45-
4641
static void _redirect_task(void* arg)
4742
{
4843
SchedulerRTOS::taskfunc_t taskfunc = (SchedulerRTOS::taskfunc_t) arg;
@@ -81,12 +76,21 @@ bool SchedulerRTOS::startLoop(taskfunc_t task, const char* name, uint32_t stack_
8176

8277

8378
//--------------------------------------------------------------------+
84-
// FreeRTOS Hooks
79+
// Hooks
8580
//--------------------------------------------------------------------+
8681

8782
extern "C"
8883
{
8984

85+
void yield(void)
86+
{
87+
#ifdef USE_TINYUSB
88+
tud_cdc_write_flush();
89+
#endif
90+
91+
taskYIELD();
92+
}
93+
9094
void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
9195
{
9296
LOG_LV1("RTOS", "%s Stack Overflow !!!", pcTaskName);

0 commit comments

Comments
 (0)