From 28b7bd347a9ff80bace964cd01cf1e934c36e7ca Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 28 Apr 2021 15:11:55 +0800 Subject: [PATCH] Fix nrf52 USB (don't call delay() in loop() if connected via usb) --- src/configuration.h | 2 +- src/main.cpp | 9 ++++++++- src/nrf52/main-nrf52.cpp | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index 661c85a18..6a72a286f 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -435,7 +435,7 @@ along with this program. If not, see . #define RF95_NSS RADIOLIB_NC // the ch341f spi controller does CS for us #define LORA_DIO0 26 // a No connect on the SX1262 module -#define LORA_RESET RADIOLIB_NC +#define LORA_RESET 14 #define LORA_DIO1 33 // SX1262 IRQ, called DIO0 on pinelora schematic, pin 7 on ch341f "ack" - FIXME, enable hwints in linux #define LORA_DIO2 32 // SX1262 BUSY, actually connected to "DIO5" on pinelora schematic, pin 8 on ch341f "slct" #define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled diff --git a/src/main.cpp b/src/main.cpp index 11a52156c..68d92fc3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -299,6 +299,13 @@ uint32_t ButtonThread::longPressTime = 0; RadioInterface *rIf = NULL; +/** + * Some platforms (nrf52) might provide an alterate version that supresses calling delay from sleep. + */ +__attribute__ ((weak, noinline)) bool loopCanSleep() { + return true; +} + void setup() { concurrency::hasBeenSetup = true; @@ -640,7 +647,7 @@ void loop() mainController.nextThread->tillRun(millis())); */ // We want to sleep as long as possible here - because it saves power - if (!runASAP) + if (!runASAP && loopCanSleep()) mainDelay.delay(delayMsec); // if (didWake) DEBUG_MSG("wake!\n"); } diff --git a/src/nrf52/main-nrf52.cpp b/src/nrf52/main-nrf52.cpp index abb99042c..ef99c9f49 100644 --- a/src/nrf52/main-nrf52.cpp +++ b/src/nrf52/main-nrf52.cpp @@ -19,6 +19,10 @@ static inline void debugger_break(void) "mov pc, lr\n\t"); } +bool loopCanSleep() { + return !tud_cdc_connected(); +} + // handle standard gcc assert failures void __attribute__((noreturn)) __assert_func(const char *file, int line, const char *func, const char *failedexpr) {