Implemented power scaling in setOutputPower, in accordance with datasheet.
This commit is contained in:
parent
fedbbcf931
commit
5b04badb36
1 changed files with 17 additions and 7 deletions
|
@ -85,27 +85,37 @@ int16_t SX1262::setFrequency(float freq, bool calibrate) {
|
|||
|
||||
int16_t SX1262::setOutputPower(int8_t power) {
|
||||
// check allowed power range
|
||||
if(!((power >= -9) && (power <= 22))) {
|
||||
if (!((power >= -17) && (power <= 22))) {
|
||||
return(ERR_INVALID_OUTPUT_POWER);
|
||||
}
|
||||
|
||||
// get current OCP configuration
|
||||
uint8_t ocp = 0;
|
||||
int16_t state = readRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
|
||||
if(state != ERR_NONE) {
|
||||
if (state != ERR_NONE) {
|
||||
return(state);
|
||||
}
|
||||
|
||||
int8_t scaledPower;
|
||||
// set PA config for optimal consumption as described in section 13-21 of the datasheet:
|
||||
// the final column of Table 13-21 suggests that the value passed in SetTxParams is actually scaled depending on the parameters of setPaConfig. However, testing suggests this isn't the case.
|
||||
// the final column of Table 13-21 suggests that the value passed in SetTxParams
|
||||
// is actually scaled depending on the parameters of setPaConfig.
|
||||
// Testing confirms this is approximately right
|
||||
if (power >= 21) {
|
||||
state = SX126x::setPaConfig(0x04, SX126X_PA_CONFIG_SX1262, SX126X_PA_CONFIG_HP_MAX/*0x07*/);
|
||||
} else if (power >= 18) {
|
||||
scaledPower = power;
|
||||
}
|
||||
else if (power >= 18) {
|
||||
state = SX126x::setPaConfig(0x03, SX126X_PA_CONFIG_SX1262, 0x05);
|
||||
} else if (power >= 15) {
|
||||
scaledPower = power + 2;
|
||||
}
|
||||
else if (power >= 15) {
|
||||
state = SX126x::setPaConfig(0x02, SX126X_PA_CONFIG_SX1262, 0x03);
|
||||
} else {
|
||||
scaledPower = power + 5;
|
||||
}
|
||||
else {
|
||||
state = SX126x::setPaConfig(0x02, SX126X_PA_CONFIG_SX1262, 0x02);
|
||||
scaledPower = power + 8;
|
||||
}
|
||||
if (state != ERR_NONE) {
|
||||
return(state);
|
||||
|
@ -116,7 +126,7 @@ int16_t SX1262::setOutputPower(int8_t power) {
|
|||
|
||||
// set output power
|
||||
// TODO power ramp time configuration
|
||||
state = SX126x::setTxParams(power);
|
||||
state = SX126x::setTxParams(scaledPower);
|
||||
if (state != ERR_NONE) {
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue