From 140d35af810806fccead2872233a4be504d4122a Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 12 Nov 2023 13:27:34 +0100 Subject: [PATCH] [SX127x] Updated startReceive interface to be more in line with SX126x --- src/modules/SX127x/SX127x.cpp | 21 ++++++++++++--------- src/modules/SX127x/SX127x.h | 7 +++++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index a00d6be7..cab32da9 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -409,13 +409,6 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) { state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_ADDR_PTR, RADIOLIB_SX127X_FIFO_RX_BASE_ADDR_MAX); RADIOLIB_ASSERT(state); - // timeout is only used in RxSingle, so when a packet length is defined, force mode to RxSingle - // and set the timeout value to the expected number of symbols (usually preamble + header) - if((len > 0) && (this->spreadingFactor > 6)) { - mode = RADIOLIB_SX127X_RXSINGLE; - state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYMB_TIMEOUT_LSB, len); - } - } else if(modem == RADIOLIB_SX127X_FSK_OOK) { // set DIO pin mapping state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_PACK_PAYLOAD_READY, 7, 6); @@ -439,10 +432,20 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) { return(setMode(mode)); } -int16_t SX127x::startReceive(uint32_t mode, uint16_t irqFlags, uint16_t irqMask, size_t len) { +int16_t SX127x::startReceive(uint32_t timeout, uint16_t irqFlags, uint16_t irqMask, size_t len) { (void)irqFlags; (void)irqMask; - return(startReceive((uint8_t)len, (uint8_t)mode)); + uint8_t mode = RADIOLIB_SX127X_RXCONTINUOUS; + if(timeout != 0) { + // for non-zero timeout value, change mode to Rx single and set the timeout + mode = RADIOLIB_SX127X_RXSINGLE; + uint8_t msb_sym = (timeout > 0x3FF) ? 0x3 : (uint8_t)(timeout >> 8); + uint8_t lsb_sym = (timeout > 0x3FF) ? 0xFF : (uint8_t)(timeout & 0xFF); + int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, msb_sym, 1, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYMB_TIMEOUT_LSB, lsb_sym); + RADIOLIB_ASSERT(state); + } + return(startReceive((uint8_t)len, mode)); } void SX127x::setDio0Action(void (*func)(void), uint32_t dir) { diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 4fb28d7b..ce82377f 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -826,13 +826,16 @@ class SX127x: public PhysicalLayer { /*! \brief Interrupt-driven receive method, implemented for compatibility with PhysicalLayer. - \param mode Receive mode to be used. + \param timeout Receive mode type and/or raw timeout value in symbols. + When set to 0, the timeout will be infinite and the device will remain + in Rx mode until explicitly commanded to stop (Rx continuous mode). + When non-zero (maximum 1023), the device will be set to Rx single mode and timeout will be set. \param irqFlags Ignored. \param irqMask Ignored. \param len Expected length of packet to be received. Required for LoRa spreading factor 6. \returns \ref status_codes */ - int16_t startReceive(uint32_t mode, uint16_t irqFlags, uint16_t irqMask, size_t len); + int16_t startReceive(uint32_t timeout, uint16_t irqFlags, uint16_t irqMask, size_t len); /*! \brief Reads data that was received after calling startReceive method. When the packet length is not known in advance,