Skip to content

Commit

Permalink
[SX126x] Added public method to set PA ramp time (#1054)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes committed Apr 5, 2024
1 parent 263f788 commit f61be0d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ spectralScanStart KEYWORD2
spectralScanAbort KEYWORD2
spectralScanGetStatus KEYWORD2
spectralScanGetResult KEYWORD2
setPaRampTime KEYWORD2

# nRF24
setIrqAction KEYWORD2
Expand Down
5 changes: 2 additions & 3 deletions src/modules/SX126x/SX1261.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ int16_t SX1261::setOutputPower(int8_t power) {
state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1261, 0x00);
RADIOLIB_ASSERT(state);

// set output power
/// \todo power ramp time configuration
state = SX126x::setTxParams(power);
// set output power with default 200us ramp
state = SX126x::setTxParams(power, RADIOLIB_SX126X_PA_RAMP_200U);
RADIOLIB_ASSERT(state);

// restore OCP configuration
Expand Down
5 changes: 2 additions & 3 deletions src/modules/SX126x/SX1262.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ int16_t SX1262::setOutputPower(int8_t power) {
state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1262);
RADIOLIB_ASSERT(state);

// set output power
/// \todo power ramp time configuration
state = SX126x::setTxParams(power);
// set output power with default 200us ramp
state = SX126x::setTxParams(power, RADIOLIB_SX126X_PA_RAMP_200U);
RADIOLIB_ASSERT(state);

// restore OCP configuration
Expand Down
5 changes: 2 additions & 3 deletions src/modules/SX126x/SX1268.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ int16_t SX1268::setOutputPower(int8_t power) {
state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1268);
RADIOLIB_ASSERT(state);

// set output power
/// \todo power ramp time configuration
state = SX126x::setTxParams(power);
// set output power with default 200us ramp
state = SX126x::setTxParams(power, RADIOLIB_SX126X_PA_RAMP_200U);
RADIOLIB_ASSERT(state);

// restore OCP configuration
Expand Down
10 changes: 9 additions & 1 deletion src/modules/SX126x/SX126x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,10 @@ int16_t SX126x::calibrateImageRejection(float freqMin, float freqMax) {
return(this->calibrateImage(data));
}

int16_t SX126x::setPaRampTime(uint8_t rampTime) {
return(this->setTxParams(this->pwr, rampTime));
}

int16_t SX126x::calibrateImage(uint8_t* data) {
int16_t state = this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE, data, 2);

Expand All @@ -1870,7 +1874,11 @@ uint8_t SX126x::getPacketType() {

int16_t SX126x::setTxParams(uint8_t pwr, uint8_t rampTime) {
uint8_t data[] = { pwr, rampTime };
return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_TX_PARAMS, data, 2));
int16_t state = this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_TX_PARAMS, data, 2);
if(state == RADIOLIB_ERR_NONE) {
this->pwr = pwr;
}
return(state);
}

int16_t SX126x::setPacketMode(uint8_t mode, uint8_t len) {
Expand Down
9 changes: 8 additions & 1 deletion src/modules/SX126x/SX126x.h
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,12 @@ class SX126x: public PhysicalLayer {
*/
int16_t calibrateImageRejection(float freqMin, float freqMax);

/*!
\brief Set PA ramp-up time. Set to 200us by default.
\returns \ref status_codes
*/
int16_t setPaRampTime(uint8_t rampTime);

#if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL
protected:
#endif
Expand All @@ -1142,7 +1148,7 @@ class SX126x: public PhysicalLayer {
int16_t setRfFrequency(uint32_t frf);
int16_t calibrateImage(uint8_t* data);
uint8_t getPacketType();
int16_t setTxParams(uint8_t power, uint8_t rampTime = RADIOLIB_SX126X_PA_RAMP_200U);
int16_t setTxParams(uint8_t power, uint8_t rampTime);
int16_t setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro);
int16_t setModulationParamsFSK(uint32_t br, uint8_t sh, uint8_t rxBw, uint32_t freqDev);
int16_t setPacketParams(uint16_t preambleLen, uint8_t crcType, uint8_t payloadLen, uint8_t hdrType, uint8_t invertIQ);
Expand Down Expand Up @@ -1187,6 +1193,7 @@ class SX126x: public PhysicalLayer {
float dataRateMeasured = 0;

uint32_t tcxoDelay = 0;
uint8_t pwr = 0;

size_t implicitLen = 0;
uint8_t invertIQEnabled = RADIOLIB_SX126X_LORA_IQ_STANDARD;
Expand Down

0 comments on commit f61be0d

Please sign in to comment.