RadioLibSmol/src/modules/SX126x/SX1261.cpp
StevenCellist 1b2b8bd67b
[LoRaWAN] Improve PHY behaviour, update beginABP, bugfixes (#1080)
* [LoRaWAN] Add getter for ToA, prevent MAC queue overflow

* [LoRaWAN] Permute arguments to beginABP

* Implement & split off checkOutputPower

* [LoRaWAN] Configure physical layer on each up/downlink

* [LoRaWAN] Remove unnecessary dynamic array

* [LoRaWAN] Improve downlink handling

* Resolve return-warnings in checkOutputPower()

* [LoRaWAN] Improve buffer definition

* [LoRaWAN] Prevent requesting repeated MAC commands

* Update keywords.txt

* [CC1101] Resolve unused variable warning

* [CC1101] Update checkOutputPower

* [SX1278] Fix variable assignment

* Update keywords.txt

* [CC1101] Added checkOutputPower override for PHY compatibility

* [LR11x0] Added checkOutputPower override for PHY compatibility

* [SX127x] Added checkOutputPower override for PHY compatibility

---------

Co-authored-by: jgromes <jan.gromes@gmail.com>
2024-05-01 13:35:22 +02:00

38 lines
1.1 KiB
C++

#include "SX1261.h"
#if !RADIOLIB_EXCLUDE_SX126X
SX1261::SX1261(Module* mod): SX1262(mod) {
chipType = RADIOLIB_SX1261_CHIP_TYPE;
}
int16_t SX1261::setOutputPower(int8_t power) {
// check if power value is configurable
int16_t state = checkOutputPower(power, NULL);
RADIOLIB_ASSERT(state);
// get current OCP configuration
uint8_t ocp = 0;
state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
RADIOLIB_ASSERT(state);
// set PA config
state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1261, 0x00);
RADIOLIB_ASSERT(state);
// set output power with default 200us ramp
state = SX126x::setTxParams(power, RADIOLIB_SX126X_PA_RAMP_200U);
RADIOLIB_ASSERT(state);
// restore OCP configuration
return(writeRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1));
}
int16_t SX1261::checkOutputPower(int8_t power, int8_t* clipped) {
if(clipped) {
*clipped = RADIOLIB_MAX(-17, RADIOLIB_MIN(14, power));
}
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
return(RADIOLIB_ERR_NONE);
}
#endif