From b9cf1956e4f0ebd6083ce8793a9c579228058daa Mon Sep 17 00:00:00 2001 From: lewisxhe Date: Fri, 21 Jun 2024 17:05:23 +0800 Subject: [PATCH] [LR1121] Added dedicated power setting function --- src/modules/LR11x0/LR1121.cpp | 40 +++++++++++++++++++++++++++++++++++ src/modules/LR11x0/LR1121.h | 9 ++++++++ 2 files changed, 49 insertions(+) diff --git a/src/modules/LR11x0/LR1121.cpp b/src/modules/LR11x0/LR1121.cpp index 6292a3be..71481bfa 100644 --- a/src/modules/LR11x0/LR1121.cpp +++ b/src/modules/LR11x0/LR1121.cpp @@ -5,4 +5,44 @@ LR1121::LR1121(Module* mod) : LR1120(mod) { chipType = RADIOLIB_LR11X0_DEVICE_LR1121; } +int16_t LR1121::setOutputPower(int8_t power, bool useHighFreqPa) +{ + + int16_t state = RADIOLIB_ERR_INVALID_OUTPUT_POWER; + + if (useHighFreqPa) { + if ((-18 <= power ) && ( power <= 13 )) { + state = setPaConfig(0x02, // High-frequency Power Amplifier + 0x00, // Power amplifier supplied by the main regulator + 0x04, // Power Amplifier duty cycle (Default 0x04) + 0x07 // Number of slices for HPA (Default 0x07) + ); + } else { + return RADIOLIB_ERR_INVALID_OUTPUT_POWER; + } + } else { + if (( -17 <= power ) && (power <= 22 )) { + if (power == 22) { + state = setPaConfig(0x01, // High-power Power Amplifier + 0x01, // Power amplifier supplied by the battery + 0x04, // Power Amplifier duty cycle (Default 0x04) + 0x07 // Number of slices for HPA (Default 0x07) + ); + } else { + state = setPaConfig(0x00, // Low-power Power Amplifier + 0x00, // Power amplifier supplied by the main regulator + 0x04, // Power Amplifier duty cycle (Default 0x04) + 0x07 // Number of slices for HPA (Default 0x07) + ); + } + } else { + return RADIOLIB_ERR_INVALID_OUTPUT_POWER; + } + } + RADIOLIB_ASSERT(state); + + // set output power + state = setTxParams(power, RADIOLIB_LR11X0_PA_RAMP_48U); + return (state); +} #endif \ No newline at end of file diff --git a/src/modules/LR11x0/LR1121.h b/src/modules/LR11x0/LR1121.h index 2dc0242b..e61735ea 100644 --- a/src/modules/LR11x0/LR1121.h +++ b/src/modules/LR11x0/LR1121.h @@ -21,6 +21,15 @@ class LR1121: public LR1120 { */ LR1121(Module* mod); // cppcheck-suppress noExplicitConstructor + /*! + \brief Sets output power. Allowed values are in range from -17 to 22 dBm (high-power PA) or -18 to 13 dBm (High-frequency PA). + \param power Output power to be set in dBm. + \param useHighFreqPa When using 2.4G frequency, need to switch to High-frequency PA + \returns \ref status_codes + */ + int16_t setOutputPower(int8_t power,bool useHighFreqPa = false); + + // TODO this is where overrides to disable GNSS+WiFi scanning methods on LR1121 // will be put once those are implemented