kopia lustrzana https://github.com/jgromes/RadioLib
[SX126x] Add support for ::begin without reseting the module
Enables resuming from deep sleep without losing the packet buffer.pull/1608/head
rodzic
e0fc757dc0
commit
ec7e8c720c
|
|
@ -6,14 +6,14 @@ LLCC68::LLCC68(Module* mod) : SX1262(mod) {
|
|||
this->XTAL = true;
|
||||
}
|
||||
|
||||
int16_t LLCC68::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t pwr, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
|
||||
int16_t LLCC68::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t pwr, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO, bool resetModule) {
|
||||
// execute common part
|
||||
int16_t state = SX126x::begin(cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO);
|
||||
int16_t state = SX126x::begin(cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO, resetModule);
|
||||
if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
|
||||
// bit of a hack, but some LLCC68 chips report as "SX1261", try that
|
||||
// for full discussion, see https://github.com/jgromes/RadioLib/issues/1329
|
||||
chipType = RADIOLIB_SX1261_CHIP_TYPE;
|
||||
state = SX126x::begin(cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO);
|
||||
state = SX126x::begin(cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO, resetModule);
|
||||
RADIOLIB_DEBUG_PRINTLN("LLCC68 version string not found, using SX1261 instead");
|
||||
}
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
|
|
|||
|
|
@ -38,10 +38,12 @@ class LLCC68: public SX1262 {
|
|||
If you are seeing -706/-707 error codes, it likely means you are using a module with TCXO.
|
||||
To use TCXO, either set this value to its reference voltage, or set SX126x::XTAL to false.
|
||||
\param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false.
|
||||
\param resetModule Whether to perform a module reset during initialization. Defaults to true.
|
||||
Setting this to false assumes that the module is already in a known state.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 0, bool useRegulatorLDO = false) override;
|
||||
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 0, bool useRegulatorLDO = false, bool resetModule = true) override;
|
||||
|
||||
/*!
|
||||
\brief Initialization method for FSK modem.
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ SX1262::SX1262(Module* mod) : SX126x(mod) {
|
|||
chipType = RADIOLIB_SX1262_CHIP_TYPE;
|
||||
}
|
||||
|
||||
int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
|
||||
int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO, bool resetModule) {
|
||||
// execute common part
|
||||
int16_t state = SX126x::begin(cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO);
|
||||
int16_t state = SX126x::begin(cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO, resetModule);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
|
|
|
|||
|
|
@ -43,9 +43,11 @@ class SX1262: public SX126x {
|
|||
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
|
||||
To use XTAL, either set this value to 0, or set SX126x::XTAL to true.
|
||||
\param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false.
|
||||
\param resetModule Whether to perform a module reset during initialization. Defaults to true.
|
||||
Setting this to false assumes that the module is already in a known state.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false);
|
||||
virtual int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false, bool resetModule = true);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for FSK modem.
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ SX126x::SX126x(Module* mod) : PhysicalLayer() {
|
|||
this->irqMap[RADIOLIB_IRQ_TIMEOUT] = RADIOLIB_SX126X_IRQ_TIMEOUT;
|
||||
}
|
||||
|
||||
int16_t SX126x::begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
|
||||
int16_t SX126x::begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO, bool resetModule) {
|
||||
// BW in kHz and SF are required in order to calculate LDRO for setModulationParams
|
||||
// set the defaults, this will get overwritten later anyway
|
||||
this->bandwidthKhz = 500.0;
|
||||
|
|
@ -38,7 +38,7 @@ int16_t SX126x::begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, flo
|
|||
this->implicitLen = 0xFF;
|
||||
|
||||
// set module properties and perform initial setup
|
||||
int16_t state = this->modSetup(tcxoVoltage, useRegulatorLDO, RADIOLIB_SX126X_PACKET_TYPE_LORA);
|
||||
int16_t state = this->modSetup(tcxoVoltage, useRegulatorLDO, RADIOLIB_SX126X_PACKET_TYPE_LORA, resetModule);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
|
|
@ -1352,7 +1352,7 @@ Module* SX126x::getMod() {
|
|||
return(this->mod);
|
||||
}
|
||||
|
||||
int16_t SX126x::modSetup(float tcxoVoltage, bool useRegulatorLDO, uint8_t modem) {
|
||||
int16_t SX126x::modSetup(float tcxoVoltage, bool useRegulatorLDO, uint8_t modem, bool resetModule) {
|
||||
// set module properties
|
||||
this->mod->init();
|
||||
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
|
||||
|
|
@ -1367,8 +1367,8 @@ int16_t SX126x::modSetup(float tcxoVoltage, bool useRegulatorLDO, uint8_t modem)
|
|||
this->mod->spiConfig.stream = true;
|
||||
this->mod->spiConfig.parseStatusCb = SPIparseStatus;
|
||||
|
||||
// find the SX126x chip - this will also reset the module and verify the module
|
||||
if(!SX126x::findChip(this->chipType)) {
|
||||
// try to find the SX126x chip
|
||||
if(!SX126x::findChip(this->chipType, resetModule)) {
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("No SX126x found!");
|
||||
this->mod->term();
|
||||
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
|
||||
|
|
@ -1408,12 +1408,13 @@ int16_t SX126x::SPIparseStatus(uint8_t in) {
|
|||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
bool SX126x::findChip(const char* verStr) {
|
||||
bool SX126x::findChip(const char* verStr, bool resetModule) {
|
||||
uint8_t i = 0;
|
||||
bool flagFound = false;
|
||||
while((i < 10) && !flagFound) {
|
||||
do {
|
||||
// reset the module
|
||||
reset(true);
|
||||
if (resetModule) {
|
||||
reset(true);
|
||||
}
|
||||
|
||||
// read the version string
|
||||
char version[16] = { 0 };
|
||||
|
|
@ -1424,19 +1425,18 @@ bool SX126x::findChip(const char* verStr) {
|
|||
RADIOLIB_DEBUG_BASIC_PRINTLN("Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:");
|
||||
RADIOLIB_DEBUG_BASIC_HEXDUMP(reinterpret_cast<uint8_t*>(version), 16, RADIOLIB_SX126X_REG_VERSION_STRING);
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN();
|
||||
flagFound = true;
|
||||
} else {
|
||||
#if RADIOLIB_DEBUG_BASIC
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("SX126x not found! (%d of 10 tries) RADIOLIB_SX126X_REG_VERSION_STRING:", i + 1);
|
||||
RADIOLIB_DEBUG_BASIC_HEXDUMP(reinterpret_cast<uint8_t*>(version), 16, RADIOLIB_SX126X_REG_VERSION_STRING);
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("Expected string: %s", verStr);
|
||||
#endif
|
||||
this->mod->hal->delay(10);
|
||||
i++;
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
|
||||
return(flagFound);
|
||||
#if RADIOLIB_DEBUG_BASIC
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("SX126x not found! (%d of %d tries) RADIOLIB_SX126X_REG_VERSION_STRING:", i + 1, resetModule ? 10 : 1);
|
||||
RADIOLIB_DEBUG_BASIC_HEXDUMP(reinterpret_cast<uint8_t*>(version), 16, RADIOLIB_SX126X_REG_VERSION_STRING);
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("Expected string: %s", verStr);
|
||||
#endif
|
||||
this->mod->hal->delay(10);
|
||||
} while (resetModule && ++i < 10);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -69,9 +69,10 @@ class SX126x: public PhysicalLayer {
|
|||
\param preambleLength LoRa preamble length in symbols. Allowed values range from 1 to 65535.
|
||||
\param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip.
|
||||
\param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false.
|
||||
\param resetModule Whether to perform a module reset during initialization. Defaults to true.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false);
|
||||
int16_t begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false, bool resetModule = true);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for FSK modem.
|
||||
|
|
@ -881,9 +882,9 @@ class SX126x: public PhysicalLayer {
|
|||
size_t lrFhssFrameHopsRem = 0;
|
||||
size_t lrFhssHopNum = 0;
|
||||
|
||||
int16_t modSetup(float tcxoVoltage, bool useRegulatorLDO, uint8_t modem);
|
||||
int16_t modSetup(float tcxoVoltage, bool useRegulatorLDO, uint8_t modem, bool resetModule = true);
|
||||
int16_t config(uint8_t modem);
|
||||
bool findChip(const char* verStr);
|
||||
bool findChip(const char* verStr, bool resetModule = true);
|
||||
int16_t startReceiveCommon(uint32_t timeout = RADIOLIB_SX126X_RX_TIMEOUT_INF, RadioLibIrqFlags_t irqFlags = RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RadioLibIrqFlags_t irqMask = RADIOLIB_IRQ_RX_DEFAULT_MASK);
|
||||
int16_t setPacketMode(uint8_t mode, uint8_t len);
|
||||
int16_t setHeaderType(uint8_t hdrType, size_t len = 0xFF);
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue