Skip to content

Commit ff9e38a

Browse files
committed
unify debuging CFG_TUSB_DEBUG with Serial1 using serial1_printf()
1 parent aa255c8 commit ff9e38a

File tree

6 files changed

+27
-35
lines changed

6 files changed

+27
-35
lines changed

src/arduino/Adafruit_TinyUSB_API.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#if CFG_TUD_ENABLED && !defined(ARDUINO_ARCH_ESP32)
2929

3030
#include "Adafruit_TinyUSB.h"
31+
#include "Arduino.h"
3132

3233
//--------------------------------------------------------------------+
3334
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
@@ -54,6 +55,26 @@ void TinyUSB_Device_FlushCDC(void) {
5455
}
5556
}
5657

58+
// Debug log with Serial1
59+
#if CFG_TUSB_DEBUG && defined(CFG_TUSB_DEBUG_PRINTF)
60+
int CFG_TUSB_DEBUG_PRINTF(const char *__restrict format, ...) {
61+
static bool ser1_inited = false;
62+
if (!ser1_inited) {
63+
ser1_inited = true;
64+
Serial1.begin(115200);
65+
}
66+
67+
char buf[256];
68+
int len;
69+
va_list ap;
70+
va_start(ap, format);
71+
len = vsnprintf(buf, sizeof(buf), format, ap);
72+
Serial1.write(buf);
73+
va_end(ap);
74+
return len;
75+
}
76+
#endif
77+
5778
} // extern C
5879

5980
#endif

src/arduino/ports/rp2040/Adafruit_TinyUSB_rp2040.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,6 @@ void TinyUSB_Device_Task(void) {
138138
mutex_exit(&__usb_mutex);
139139
}
140140
}
141-
142-
// Debug log with Serial1
143-
#if CFG_TUSB_DEBUG
144-
int serial1_printf(const char *__restrict format, ...) {
145-
char buf[256];
146-
int len;
147-
va_list ap;
148-
va_start(ap, format);
149-
len = vsnprintf(buf, sizeof(buf), format, ap);
150-
Serial1.write(buf);
151-
va_end(ap);
152-
return len;
153-
}
154-
#endif
155141
}
156142

157143
#endif

src/arduino/ports/rp2040/tusb_config_rp2040.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ extern "C" {
5252
#define CFG_TUSB_DEBUG 0
5353
#endif
5454

55-
#if CFG_TUSB_DEBUG
56-
#define CFG_TUSB_DEBUG_PRINTF serial1_printf
57-
extern int serial1_printf(const char *__restrict __format, ...);
58-
#endif
59-
6055
#define CFG_TUSB_MEM_SECTION
6156
#define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
6257

src/arduino/ports/samd/Adafruit_TinyUSB_samd.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,6 @@ void USB_Handler(void) { tud_int_handler(0); }
5252

5353
#endif
5454

55-
// Debug log with Serial1
56-
#if CFG_TUSB_DEBUG
57-
int serial1_printf(const char *__restrict format, ...) {
58-
char buf[256];
59-
int len;
60-
va_list ap;
61-
va_start(ap, format);
62-
len = vsnprintf(buf, sizeof(buf), format, ap);
63-
Serial1.write(buf);
64-
va_end(ap);
65-
return len;
66-
}
67-
#endif
68-
6955
} // extern C
7056

7157
//--------------------------------------------------------------------+

src/arduino/ports/samd/tusb_config_samd.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ extern "C" {
4646

4747
#define CFG_TUSB_OS OPT_OS_NONE
4848

49+
#ifndef CFG_TUSB_DEBUG
4950
#define CFG_TUSB_DEBUG 0
50-
#if CFG_TUSB_DEBUG
51-
#define CFG_TUSB_DEBUG_PRINTF serial1_printf
5251
#endif
5352

5453
#define CFG_TUSB_MEM_SECTION

src/tusb_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
#error TinyUSB Arduino Library does not support your core yet
4747
#endif
4848

49+
// Debug TinyUSB with Serial1
50+
#if CFG_TUSB_DEBUG
51+
#define CFG_TUSB_DEBUG_PRINTF serial1_printf
52+
#endif
53+
4954
#ifdef __cplusplus
5055
}
5156
#endif

0 commit comments

Comments
 (0)