Skip to content

Commit 93c34f3

Browse files
committed
add weak funtion tinyusb_task for use tinyusb with freertos.
1 parent 91bfc64 commit 93c34f3

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

cores/arduino/main.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,36 @@
2222
// Weak empty variant initialization function.
2323
// May be redefined by variant files.
2424
void initVariant() __attribute__((weak));
25-
void initVariant() { }
25+
void initVariant() {}
26+
#if defined(USE_TINYUSB)
27+
// run TinyUSB background task auto This method will be overridden when running in FreeRTOS
28+
void __attribute__((weak)) tinyusb_task(void)
29+
{
30+
}
31+
#endif
2632

2733
/*
2834
* _real_body(),_wrap_body() is a compiler trick,
2935
* user could overwrite the arduino setup/loop function by re-implement _wrap_body(),
3036
* calling of _real_body() in _wrap_body() is optional.
3137
*/
32-
void _real_body(){
38+
void _real_body()
39+
{
3340
setup();
34-
41+
#if defined(USE_TINYUSB)
42+
tinyusb_task();
43+
#endif
3544
for (;;)
3645
{
3746
loop();
3847
yield(); // yield run usb background task
39-
40-
if (serialEventRun) serialEventRun();
48+
if (serialEventRun)
49+
serialEventRun();
4150
}
4251
}
4352

44-
void __attribute__((weak)) _wrap_body(){
53+
void __attribute__((weak)) _wrap_body()
54+
{
4555
_real_body();
4656
}
4757

@@ -51,7 +61,7 @@ extern "C" void __libc_init_array(void);
5161
/*
5262
* \brief Main entry point of Arduino application
5363
*/
54-
int main( void )
64+
int main(void)
5565
{
5666
init();
5767

@@ -70,14 +80,3 @@ int main( void )
7080
_wrap_body();
7181
return 0;
7282
}
73-
74-
#if defined(USE_TINYUSB)
75-
76-
// run TinyUSB background task when yield()
77-
extern "C" void yield(void)
78-
{
79-
tud_task();
80-
tud_cdc_write_flush();
81-
}
82-
83-
#endif

0 commit comments

Comments
 (0)