diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 80baff15..195bea1c 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -129,7 +129,7 @@ * Platform-specific configuration. * * RADIOLIB_PLATFORM - platform name, used in debugging to quickly check the correct platform is detected. - * RADIOLIB_NC - alias for unused pin, usually the largest possible value of uint8_t. + * RADIOLIB_NC - alias for unused pin, usually the largest possible value of uint32_t. * RADIOLIB_DEFAULT_SPI - default SPIClass instance to use. * RADIOLIB_NONVOLATILE - macro to place variable into program storage (usually Flash). * RADIOLIB_NONVOLATILE_READ_BYTE - function/macro to read variables saved in program storage (usually Flash). @@ -422,7 +422,7 @@ // generic non-Arduino platform #define RADIOLIB_PLATFORM "Generic" - #define RADIOLIB_NC (0xFF) + #define RADIOLIB_NC (0xFFFFFFFF) #define RADIOLIB_NONVOLATILE #define RADIOLIB_NONVOLATILE_READ_BYTE(addr) (*((uint8_t *)(void *)(addr))) #define RADIOLIB_NONVOLATILE_READ_DWORD(addr) (*((uint32_t *)(void *)(addr))) diff --git a/src/Module.cpp b/src/Module.cpp index 8cc308d2..7b3c59ae 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -489,15 +489,17 @@ void Module::setRfSwitchPins(uint32_t rxEn, uint32_t txEn) { void Module::setRfSwitchTable(const uint32_t (&pins)[RFSWITCH_MAX_PINS], const RfSwitchMode_t table[]) { memcpy(this->rfSwitchPins, pins, sizeof(this->rfSwitchPins)); this->rfSwitchTable = table; - for(size_t i = 0; i < RFSWITCH_MAX_PINS; i++) + for(size_t i = 0; i < RFSWITCH_MAX_PINS; i++) { this->hal->pinMode(pins[i], this->hal->GpioModeOutput); + } } const Module::RfSwitchMode_t *Module::findRfSwitchMode(uint8_t mode) const { const RfSwitchMode_t *row = this->rfSwitchTable; - while (row && row->mode != MODE_END_OF_TABLE) { - if (row->mode == mode) + while(row && row->mode != MODE_END_OF_TABLE) { + if(row->mode == mode) { return row; + } ++row; } return nullptr; @@ -514,8 +516,9 @@ void Module::setRfSwitchState(uint8_t mode) { const uint32_t *value = &row->values[0]; for(size_t i = 0; i < RFSWITCH_MAX_PINS; i++) { uint32_t pin = this->rfSwitchPins[i]; - if (pin != RADIOLIB_NC) + if(!(pin & RFSWITCH_PIN_FLAG)) { this->hal->digitalWrite(pin, *value); + } ++value; } } diff --git a/src/Module.h b/src/Module.h index 5d5072bf..946c42e4 100644 --- a/src/Module.h +++ b/src/Module.h @@ -19,6 +19,13 @@ */ #define END_OF_MODE_TABLE { Module::MODE_END_OF_TABLE, {} } +/*! + \def RFSWITCH_PIN_FLAG Bit flag used to mark unused pins in RF switch pin map. This can be either + unconnected pin marked with RADIOLIB_NC, or a pin controlled by the radio (e.g. DIOx pins on LR11x0), + as opposed to an MCU-controlled GPIO pin. +*/ +#define RFSWITCH_PIN_FLAG (0x01UL << 31) + /*! \defgroup module_spi_command_pos Position of commands in Module::spiConfig command array. \{