Skip to content

Commit

Permalink
[LR11x0] Fix RF swtich table handling (#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes committed Oct 27, 2024
1 parent 334b5fd commit 9f4d4ea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
25 changes: 22 additions & 3 deletions src/modules/LR11x0/LR11x0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/modules/LR11x0/LR11x0.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9f4d4ea

Please sign in to comment.