Fix nrf52 USB (don't call delay() in loop() if connected via usb)

This commit is contained in:
Kevin Hester 2021-04-28 15:11:55 +08:00
parent a42bb80cf4
commit 28b7bd347a
3 changed files with 13 additions and 2 deletions

View File

@ -435,7 +435,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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

View File

@ -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");
}

View File

@ -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)
{