diff --git a/src/modules/LR11x0/LR11x0.cpp b/src/modules/LR11x0/LR11x0.cpp index 06686be2..6d41e3e2 100644 --- a/src/modules/LR11x0/LR11x0.cpp +++ b/src/modules/LR11x0/LR11x0.cpp @@ -1445,17 +1445,36 @@ void LR11x0::setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], // find which pins are used uint8_t enable = 0; for(size_t i = 0; i < Module::RFSWITCH_MAX_PINS; i++) { - if((pins[i] == RADIOLIB_NC) || (pins[i] > RADIOLIB_LR11X0_DIO10)) { + // check if this pin is unused + if(pins[i] == RADIOLIB_NC) { continue; } - enable |= 1UL << pins[i]; + + // only keep DIO pins, there may be some GPIOs in the switch tabke + if(pins[i] & RFSWITCH_PIN_FLAG) { + enable |= 1UL << RADIOLIB_LR11X0_DIOx_VAL(pins[i]); + } + } // now get the configuration uint8_t modes[7] = { 0 }; for(size_t i = 0; i < 7; i++) { + // check end of table + if(table[i].mode == LR11x0::MODE_END_OF_TABLE) { + break; + } + + // get the mode ID in case the modes are out-of-order + uint8_t index = table[i].mode - LR11x0::MODE_STBY; + + // iterate over the pins for(size_t j = 0; j < Module::RFSWITCH_MAX_PINS; j++) { - modes[i] |= (table[i].values[j] > 0) ? (1UL << j) : 0; + // only process modes for the DIOx pins, skip GPIO pins + if(!(pins[j] & RFSWITCH_PIN_FLAG)) { + continue; + } + modes[index] |= (table[i].values[j] == this->mod->hal->GpioLevelHigh) ? (1UL << j) : 0; } } diff --git a/src/modules/LR11x0/LR11x0.h b/src/modules/LR11x0/LR11x0.h index 68a3f5de..974e8e3b 100644 --- a/src/modules/LR11x0/LR11x0.h +++ b/src/modules/LR11x0/LR11x0.h @@ -250,11 +250,13 @@ #define RADIOLIB_LR11X0_RFSW_DIO8_DISABLED (0x00UL << 3) // 4 0 DIO8 disabled (default) #define RADIOLIB_LR11X0_RFSW_DIO10_ENABLED (0x01UL << 4) // 4 0 RF switch: DIO10 enabled #define RADIOLIB_LR11X0_RFSW_DIO10_DISABLED (0x00UL << 4) // 4 0 DIO10 disabled (default) -#define RADIOLIB_LR11X0_DIO5 (0) -#define RADIOLIB_LR11X0_DIO6 (1) -#define RADIOLIB_LR11X0_DIO7 (2) -#define RADIOLIB_LR11X0_DIO8 (3) -#define RADIOLIB_LR11X0_DIO10 (4) +#define RADIOLIB_LR11X0_DIOx(X) ((X) | RFSWITCH_PIN_FLAG) +#define RADIOLIB_LR11X0_DIOx_VAL(X) ((X) & ~RFSWITCH_PIN_FLAG) +#define RADIOLIB_LR11X0_DIO5 (RADIOLIB_LR11X0_DIOx(0)) +#define RADIOLIB_LR11X0_DIO6 (RADIOLIB_LR11X0_DIOx(1)) +#define RADIOLIB_LR11X0_DIO7 (RADIOLIB_LR11X0_DIOx(2)) +#define RADIOLIB_LR11X0_DIO8 (RADIOLIB_LR11X0_DIOx(3)) +#define RADIOLIB_LR11X0_DIO10 (RADIOLIB_LR11X0_DIOx(4)) // RADIOLIB_LR11X0_CMD_SET_DIO_IRQ_PARAMS #define RADIOLIB_LR11X0_IRQ_TX_DONE (0x01UL << 2) // 31 0 interrupt: packet transmitted