'module esp32_usblog.bas
'v.1.3
Private Sub Process_Globals
End Sub
Public Sub EnableUSB_CDC_Logs(BaudRate As ULong)
RunNative("InitUniversalUSB", BaudRate)
End Sub
#If C
#include <Arduino.h>
// Explicitly include USB.h if compiling for chips with USB CDC
#ifdef USB
#include "USB.h"
#endif
void InitUniversalUSB(B4R::Object* o) {
// Activate USB CDC on chips that support it, note - CONFIG_IDF_TARGET_ESP32C3 is NOT included !
#ifdef CONFIG_IDF_TARGET_ESP32S2 || \
defined(CONFIG_IDF_TARGET_ESP32S3) || \
defined(CONFIG_IDF_TARGET_ESP32C6) || \
defined(CONFIG_IDF_TARGET_ESP32H2)
#ifdef USB
USB.begin(); // Start USB stack
#endif
#endif
//Initialize Serial — it will be USB CDC or UART
Serial.begin(o->toLong());
Serial.setTimeout(0);
//Against freezing: wait for Serial no more than 100 ms
uint32_t timeout = millis() + 100;
while (!Serial && millis() < timeout) {
delay(1);
}
}
#End If