Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/helpers/ESP32Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include <driver/rtc_io.h>
#include <helpers/KeyValueStore.h>

#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE
#include "esp32-hal-tinyusb.h" // for tud_mounted(), used below
#endif

class ESP32Board : public mesh::MainBoard {
protected:
uint8_t startup_reason;
Expand Down Expand Up @@ -167,6 +171,20 @@ class ESP32Board : public mesh::MainBoard {
return esp_reset_reason();
}

#if ARDUINO_USB_CDC_ON_BOOT
#if ARDUINO_USB_MODE
// Native USB-Serial-JTAG (HWCDC), e.g. Heltec V4.3.
bool isExternalPowered() override {
return Serial.isPlugged();
}
#else
// External USB-OTG via TinyUSB (USBCDC), e.g. Wireless Tracker V2.
bool isExternalPowered() override {
return tud_mounted();
}
#endif
#endif

// https://docs.espressif.com/projects/esp-idf/en/v4.4.7/esp32/api-reference/system/system.html
const char* getResetReasonString(uint32_t reason) {
switch (reason) {
Expand Down