From c4517656021a352ca5e845bfae31b34044cb264a Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 2 May 2023 21:04:49 +0200 Subject: [PATCH] [SX128x] Added force wakeup to standby --- src/modules/SX128x/SX128x.cpp | 15 ++++++--------- src/modules/SX128x/SX128x.h | 3 ++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index d03175f6..a9643834 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -455,20 +455,17 @@ int16_t SX128x::standby() { return(SX128x::standby(RADIOLIB_SX128X_STANDBY_RC)); } -int16_t SX128x::standby(uint8_t mode) { +int16_t SX128x::standby(uint8_t mode, bool wakeup) { // set RF switch (if present) this->mod->setRfSwitchState(Module::MODE_IDLE); - uint8_t data[] = { mode }; - int16_t state = this->mod->SPIwriteStream(RADIOLIB_SX128X_CMD_SET_STANDBY, data, 1); - if(state == RADIOLIB_ERR_NONE) { - return(state); - } else if(state == RADIOLIB_ERR_SPI_CMD_TIMEOUT) { - // the device might be in sleep mode, pull NSS low to wake up and try again + if(wakeup) { + // pull NSS low to wake up this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelLow); - return(this->mod->SPIwriteStream(RADIOLIB_SX128X_CMD_SET_STANDBY, data, 1)); } - return(state); + + uint8_t data[] = { mode }; + return(this->mod->SPIwriteStream(RADIOLIB_SX128X_CMD_SET_STANDBY, data, 1)); } void SX128x::setDio1Action(void (*func)(void)) { diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index 97dea036..6b8f6467 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -477,9 +477,10 @@ class SX128x: public PhysicalLayer { \brief Sets the module to standby mode. \param mode Oscillator to be used in standby mode. Can be set to RADIOLIB_SX128X_STANDBY_RC (13 MHz RC oscillator) or RADIOLIB_SX128X_STANDBY_XOSC (52 MHz external crystal oscillator). + \param wakeup Whether to force the module to wake up. Setting to true will immediately attempt to wake up the module. \returns \ref status_codes */ - int16_t standby(uint8_t mode); + int16_t standby(uint8_t mode, bool wakeup = false); // interrupt methods