From 0eb987a83cbf6d12f0f7307a60bff0afad9a2fe2 Mon Sep 17 00:00:00 2001 From: StevenCellist Date: Fri, 16 Aug 2024 00:04:34 +0200 Subject: [PATCH] [LR11x0] Generalize IRQ checks --- src/modules/LR11x0/LR11x0.cpp | 35 ++++++++++++++++++++++++++++++----- src/modules/LR11x0/LR11x0.h | 6 +++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/modules/LR11x0/LR11x0.cpp b/src/modules/LR11x0/LR11x0.cpp index d1e1c0aa..52c270cc 100644 --- a/src/modules/LR11x0/LR11x0.cpp +++ b/src/modules/LR11x0/LR11x0.cpp @@ -1328,12 +1328,37 @@ int16_t LR11x0::irqRxDoneRxTimeout(uint32_t &irqFlags, uint32_t &irqMask) { return(RADIOLIB_ERR_NONE); } -bool LR11x0::isRxTimeout() { - uint32_t irq = getIrqStatus(); - bool rxTimedOut = irq & RADIOLIB_LR11X0_IRQ_TIMEOUT; - return(rxTimedOut); +bool LR11x0::isIrqSet(uint8_t irq) { + uint16_t flags = getIrqStatus(); + switch(irq) { + case RADIOLIB_IRQ_TX_DONE: + return(flags & RADIOLIB_LR11X0_IRQ_TX_DONE); + case RADIOLIB_IRQ_RX_DONE: + return(flags & RADIOLIB_LR11X0_IRQ_RX_DONE); + case RADIOLIB_IRQ_PREAMBLE_DETECTED: + return(flags & RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED); + case RADIOLIB_IRQ_SYNC_WORD_VALID: + return(flags & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID); + case RADIOLIB_IRQ_HEADER_VALID: + return(flags & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID); + case RADIOLIB_IRQ_HEADER_ERR: + return(flags & RADIOLIB_LR11X0_IRQ_HEADER_ERR); + case RADIOLIB_IRQ_CRC_ERR: + return(flags & RADIOLIB_LR11X0_IRQ_CRC_ERR); + case RADIOLIB_IRQ_CAD_DONE: + return(flags & RADIOLIB_LR11X0_IRQ_CAD_DONE); + case RADIOLIB_IRQ_CAD_DETECTED: + return(flags & RADIOLIB_LR11X0_IRQ_CAD_DETECTED); + case RADIOLIB_IRQ_TIMEOUT: + return(flags & RADIOLIB_LR11X0_IRQ_TIMEOUT); + case RADIOLIB_IRQ_LR_FHSS_HOP: + return(flags & RADIOLIB_LR11X0_IRQ_LR_FHSS_HOP); + default: + return(false); + } + return(false); } - + uint8_t LR11x0::randomByte() { uint32_t num = 0; (void)getRandomNumber(&num); diff --git a/src/modules/LR11x0/LR11x0.h b/src/modules/LR11x0/LR11x0.h index 741e8623..1f9fedbc 100644 --- a/src/modules/LR11x0/LR11x0.h +++ b/src/modules/LR11x0/LR11x0.h @@ -1229,10 +1229,10 @@ class LR11x0: public PhysicalLayer { int16_t irqRxDoneRxTimeout(uint32_t &irqFlags, uint32_t &irqMask) override; /*! - \brief Check whether the IRQ bit for RxTimeout is set - \returns Whether RxTimeout IRQ is set + \brief Check whether a specific IRQ bit is set (e.g. RxTimeout, CadDone). + \returns Whether requested IRQ is set. */ - bool isRxTimeout() override; + bool isIrqSet(uint8_t irq) override; /*! \brief Get one truly random byte from RSSI noise.