From 8fe6ba86ab9c27f80e429daef51b8b763df909f3 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 25 Aug 2024 18:16:15 +0200 Subject: [PATCH] [SX128x] Rework generic IRQ to allow multiple flags --- src/modules/SX128x/SX128x.cpp | 17 +++++++++-------- src/modules/SX128x/SX128x.h | 7 +++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 7fae6712..1279b571 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -428,7 +428,8 @@ int16_t SX128x::scanChannel() { .detMin = 0, .exitMode = 0, .timeout = 0, - .irqFlags = RADIOLIB_IRQ_NOT_SUPPORTED, + .irqFlags = RADIOLIB_IRQ_CAD_DEFAULT_FLAGS, + .irqMask = RADIOLIB_IRQ_CAD_DEFAULT_MASK, }, }; return(this->scanChannel(config)); @@ -582,10 +583,10 @@ int16_t SX128x::finishTransmit() { } int16_t SX128x::startReceive() { - return(this->startReceive(RADIOLIB_SX128X_RX_TIMEOUT_INF, RADIOLIB_SX128X_IRQ_RX_DEFAULT, RADIOLIB_SX128X_IRQ_RX_DONE, 0)); + return(this->startReceive(RADIOLIB_SX128X_RX_TIMEOUT_INF, RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RADIOLIB_IRQ_RX_DEFAULT_MASK, 0)); } -int16_t SX128x::startReceive(uint16_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) { +int16_t SX128x::startReceive(uint16_t timeout, RadioLibIrqFlags_t irqFlags, RadioLibIrqFlags_t irqMask, size_t len) { (void)len; // check active modem @@ -595,10 +596,10 @@ int16_t SX128x::startReceive(uint16_t timeout, uint32_t irqFlags, uint32_t irqMa // set DIO mapping if(timeout != RADIOLIB_SX128X_RX_TIMEOUT_INF) { - irqMask |= RADIOLIB_SX128X_IRQ_RX_TX_TIMEOUT; + irqMask |= (1UL << RADIOLIB_IRQ_TIMEOUT); } - int16_t state = setDioIrqParams(irqFlags, irqMask); + int16_t state = setDioIrqParams(getIrqMapped(irqFlags), getIrqMapped(irqMask)); RADIOLIB_ASSERT(state); // set buffer pointers @@ -682,7 +683,8 @@ int16_t SX128x::startChannelScan() { .detMin = 0, .exitMode = 0, .timeout = 0, - .irqFlags = RADIOLIB_IRQ_NOT_SUPPORTED, + .irqFlags = RADIOLIB_IRQ_CAD_DEFAULT_FLAGS, + .irqMask = RADIOLIB_IRQ_CAD_DEFAULT_MASK, }, }; return(this->startChannelScan(config)); @@ -699,8 +701,7 @@ int16_t SX128x::startChannelScan(ChannelScanConfig_t config) { RADIOLIB_ASSERT(state); // set DIO pin mapping - uint16_t irqFlags = (config.cad.irqFlags == RADIOLIB_IRQ_NOT_SUPPORTED) ? RADIOLIB_SX128X_IRQ_CAD_DETECTED | RADIOLIB_SX128X_IRQ_CAD_DONE : config.cad.irqFlags; - state = setDioIrqParams(irqFlags, irqFlags); + state = setDioIrqParams(getIrqMapped(config.cad.irqFlags), getIrqMapped(config.cad.irqMask)); RADIOLIB_ASSERT(state); // clear interrupt flags diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index cadc7909..03d87e68 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -328,7 +328,6 @@ #define RADIOLIB_SX128X_IRQ_SYNC_WORD_VALID 0x0004 // 2 2 sync word valid #define RADIOLIB_SX128X_IRQ_RX_DONE 0x0002 // 1 1 Rx done #define RADIOLIB_SX128X_IRQ_TX_DONE 0x0001 // 0 0 Tx done -#define RADIOLIB_SX128X_IRQ_RX_DEFAULT 0x4062 // 15 0 default for Rx (RX_DONE, RX_TX_TIMEOUT, CRC_ERROR and HEADER_ERROR) #define RADIOLIB_SX128X_IRQ_NONE 0x0000 // 15 0 none #define RADIOLIB_SX128X_IRQ_ALL 0xFFFF // 15 0 all @@ -561,12 +560,12 @@ class SX128x: public PhysicalLayer { set to RADIOLIB_SX128X_RX_TIMEOUT_NONE for no timeout (Rx single mode). If timeout other than infinite is set, signal will be generated on DIO1. - \param irqFlags Sets the IRQ flags, defaults to RADIOLIB_SX128X_IRQ_RX_DEFAULT. - \param irqMask Sets the mask of IRQ flags that will trigger DIO1, defaults to RADIOLIB_SX128X_IRQ_RX_DONE. + \param irqFlags Sets the IRQ flags, defaults to RX done, RX timeout, CRC error and header error. + \param irqMask Sets the mask of IRQ flags that will trigger DIO1, defaults to RX done. \param len Only for PhysicalLayer compatibility, not used. \returns \ref status_codes */ - int16_t startReceive(uint16_t timeout, uint32_t irqFlags = RADIOLIB_SX128X_IRQ_RX_DEFAULT, uint32_t irqMask = RADIOLIB_SX128X_IRQ_RX_DONE, size_t len = 0); + int16_t startReceive(uint16_t timeout, RadioLibIrqFlags_t irqFlags = RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RadioLibIrqFlags_t irqMask = RADIOLIB_IRQ_RX_DEFAULT_MASK, size_t len = 0); /*! \brief Reads the current IRQ status.