Fix companion display behavior on USB hosts

This commit is contained in:
mikecarper committed 2026-07-19 22:18:26 -07:00
1 parent ccce0c8d75
commit 67cfc30588
9 files changed
+59 -7

No files matched your search

+4
View File
@@ -101,6 +101,10 @@ public:
// Power management interface (boards with power management override these)
virtual bool isExternalPowered() { return false; }
virtual bool isUsbDataConnected() { return false; }
// True when the device is enumerated by a USB host, even if its serial port
// is not open. Defaults to the stricter data-connection signal on boards
// that cannot distinguish a computer from USB power.
virtual bool isUsbHostConnected() { return isUsbDataConnected(); }
virtual uint16_t getBootVoltage() { return 0; }
virtual uint32_t getResetReason() const { return 0; }
virtual const char* getResetReasonString(uint32_t reason) { return "Not available"; }
+19
View File
@@ -16,6 +16,11 @@
#include "esp_system.h"
#include <driver/rtc_io.h>
#if defined(ARDUINO_USB_CDC_ON_BOOT) && ARDUINO_USB_CDC_ON_BOOT && \
(!defined(ARDUINO_USB_MODE) || !ARDUINO_USB_MODE)
#include <USB.h>
#endif
#if !defined(LIGHTWEIGHT_WIFI_OTA)
class AsyncWebServer;
#endif
@@ -192,6 +197,20 @@ public:
#endif
}
bool isUsbHostConnected() override {
#if defined(ARDUINO_USB_CDC_ON_BOOT) && ARDUINO_USB_CDC_ON_BOOT
#if defined(ARDUINO_USB_MODE) && ARDUINO_USB_MODE
return Serial.isPlugged();
#elif defined(CONFIG_TINYUSB_ENABLED) && CONFIG_TINYUSB_ENABLED
return (bool)USB;
#else
return (bool)Serial;
#endif
#else
return false;
#endif
}
void setInhibitSleep(bool inhibit) {
inhibit_sleep = inhibit;
}
+8
View File
@@ -282,6 +282,14 @@ bool NRF52Board::isUsbDataConnected() {
#endif
}
bool NRF52Board::isUsbHostConnected() {
#if defined(USE_TINYUSB)
return tud_mounted();
#else
return false;
#endif
}
void NRF52Board::sleep(uint32_t secs) {
// Clear FPU interrupt flags to avoid insomnia
// see errata 87 for details https://docs.nordicsemi.com/bundle/errata_nRF52840_Rev3/page/ERR/nRF52840/Rev3/latest/anomaly_840_87.html
+1
View File
@@ -58,6 +58,7 @@ public:
virtual void sleep(uint32_t secs) override;
bool isExternalPowered() override;
bool isUsbDataConnected() override;
bool isUsbHostConnected() override;
#ifdef NRF52_POWER_MANAGEMENT
uint16_t getBootVoltage() override { return boot_voltage_mv; }