Skip to content

Commit 70b0a89

Browse files
committed
[LR11X0] Add support for specifying PA ramp time
- `setOutputPower()` now accepts a `rampTimeUs` argument - `roundRampTime()` rounds up the ramp time to a discerte register value supported by the LR11X0 module.
1 parent 5b38ce9 commit 70b0a89

File tree

6 files changed

+76
-7
lines changed

6 files changed

+76
-7
lines changed

src/modules/LR11x0/LR1110.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int16_t LR1110::setOutputPower(int8_t power) {
7171
return(this->setOutputPower(power, false));
7272
}
7373

74-
int16_t LR1110::setOutputPower(int8_t power, bool forceHighPower) {
74+
int16_t LR1110::setOutputPower(int8_t power, bool forceHighPower, uint32_t rampTimeUs) {
7575
// check if power value is configurable
7676
int16_t state = this->checkOutputPower(power, NULL, forceHighPower);
7777
RADIOLIB_ASSERT(state);
@@ -86,7 +86,7 @@ int16_t LR1110::setOutputPower(int8_t power, bool forceHighPower) {
8686
RADIOLIB_ASSERT(state);
8787

8888
// set output power
89-
state = setTxParams(power, RADIOLIB_LR11X0_PA_RAMP_48U);
89+
state = setTxParams(power, roundRampTime(rampTimeUs));
9090
return(state);
9191
}
9292

src/modules/LR11x0/LR1110.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ class LR1110: public LR11x0 {
103103
\param power Output power to be set in dBm.
104104
\param forceHighPower Force using the high-power PA. If set to false, PA will be determined automatically
105105
based on configured output power, preferring the low-power PA. If set to true, only high-power PA will be used.
106+
\param rampTimeUs PA power ramping time in microseconds. Provided value is rounded up to the
107+
nearest discrete ramp time supported by the PA. Defaults to 48 us.
106108
\returns \ref status_codes
107109
*/
108-
int16_t setOutputPower(int8_t power, bool forceHighPower);
110+
int16_t setOutputPower(int8_t power, bool forceHighPower, uint32_t rampTimeUs = 48);
109111

110112
/*!
111113
\brief Check if output power is configurable.

src/modules/LR11x0/LR1120.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int16_t LR1120::setOutputPower(int8_t power) {
7878
return(this->setOutputPower(power, false));
7979
}
8080

81-
int16_t LR1120::setOutputPower(int8_t power, bool forceHighPower) {
81+
int16_t LR1120::setOutputPower(int8_t power, bool forceHighPower, uint32_t rampTimeUs) {
8282
// check if power value is configurable
8383
int16_t state = this->checkOutputPower(power, NULL, forceHighPower);
8484
RADIOLIB_ASSERT(state);
@@ -100,7 +100,7 @@ int16_t LR1120::setOutputPower(int8_t power, bool forceHighPower) {
100100
RADIOLIB_ASSERT(state);
101101

102102
// set output power
103-
state = setTxParams(power, RADIOLIB_LR11X0_PA_RAMP_48U);
103+
state = setTxParams(power, roundRampTime(rampTimeUs));
104104
return(state);
105105
}
106106

src/modules/LR11x0/LR1120.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ class LR1120: public LR11x0 {
112112
If set to false, PA will be determined automatically based on configured output power and frequency,
113113
preferring the low-power PA but always using high-frequency PA in 2.4 GHz band.
114114
Ignored when operating in 2.4 GHz band.
115+
\param rampTimeUs PA power ramping time in microseconds. Provided value is rounded up to the
116+
nearest discrete ramp time supported by the PA. Defaults to 48 us.
115117
\returns \ref status_codes
116118
*/
117-
int16_t setOutputPower(int8_t power, bool forceHighPower);
119+
int16_t setOutputPower(int8_t power, bool forceHighPower, uint32_t rampTimeUs = 48);
118120

119121
/*!
120122
\brief Check if output power is configurable.

src/modules/LR11x0/LR11x0.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,22 @@
443443
#define RADIOLIB_LR11X0_GFSK_WHITENING_ENABLED (0x01UL << 0) // 7 0 enabled
444444

445445
// RADIOLIB_LR11X0_CMD_SET_TX_PARAMS
446-
#define RADIOLIB_LR11X0_PA_RAMP_48U (0x02UL << 0) // 7 0 PA ramp time: 48 us
446+
#define RADIOLIB_LR11X0_PA_RAMP_16U (0x00UL << 0) // 7 0 PA ramp time: 16 us
447+
#define RADIOLIB_LR11X0_PA_RAMP_32U (0x01UL << 0) // 7 0 32 us
448+
#define RADIOLIB_LR11X0_PA_RAMP_48U (0x02UL << 0) // 7 0 48 us
449+
#define RADIOLIB_LR11X0_PA_RAMP_64U (0x03UL << 0) // 7 0 64 us
450+
#define RADIOLIB_LR11X0_PA_RAMP_80U (0x04UL << 0) // 7 0 80 us
451+
#define RADIOLIB_LR11X0_PA_RAMP_96U (0x05UL << 0) // 7 0 96 us
452+
#define RADIOLIB_LR11X0_PA_RAMP_112U (0x06UL << 0) // 7 0 112 us
453+
#define RADIOLIB_LR11X0_PA_RAMP_128U (0x07UL << 0) // 7 0 128 us
454+
#define RADIOLIB_LR11X0_PA_RAMP_144U (0x08UL << 0) // 7 0 144 us
455+
#define RADIOLIB_LR11X0_PA_RAMP_160U (0x09UL << 0) // 7 0 160 us
456+
#define RADIOLIB_LR11X0_PA_RAMP_176U (0x0AUL << 0) // 7 0 176 us
457+
#define RADIOLIB_LR11X0_PA_RAMP_192U (0x0BUL << 0) // 7 0 192 us
458+
#define RADIOLIB_LR11X0_PA_RAMP_208U (0x0CUL << 0) // 7 0 208 us
459+
#define RADIOLIB_LR11X0_PA_RAMP_240U (0x0DUL << 0) // 7 0 240 us
460+
#define RADIOLIB_LR11X0_PA_RAMP_272U (0x0EUL << 0) // 7 0 272 us
461+
#define RADIOLIB_LR11X0_PA_RAMP_304U (0x0FUL << 0) // 7 0 304 us
447462

448463
// RADIOLIB_LR11X0_CMD_SET_RX_TX_FALLBACK_MODE
449464
#define RADIOLIB_LR11X0_FALLBACK_MODE_STBY_RC (0x01UL << 0) // 1 0 fallback mode after Rx/Tx: standby with RC
@@ -1610,6 +1625,14 @@ class LR11x0: public PhysicalLayer {
16101625
#endif
16111626
Module* getMod() override;
16121627

1628+
// LR11x0 command helpers
1629+
/*!
1630+
\brief Round up a PA power ramp time to register value
1631+
\param rampTimeUs Ramp time in microseconds
1632+
\returns Register value of rounded ramp time
1633+
*/
1634+
uint8_t roundRampTime(uint32_t rampTimeUs);
1635+
16131636
// LR11x0 SPI command implementations
16141637
int16_t writeRegMem32(uint32_t addr, const uint32_t* data, size_t len);
16151638
int16_t readRegMem32(uint32_t addr, uint32_t* data, size_t len);

src/modules/LR11x0/LR11x0_commands.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,48 @@
88

99
#if !RADIOLIB_EXCLUDE_LR11X0
1010

11+
uint8_t LR11x0::roundRampTime(uint32_t rampTimeUs)
12+
{
13+
uint8_t regVal;
14+
15+
// Round up the ramp time to nearest discrete register value
16+
if(rampTimeUs <= 16) {
17+
regVal = RADIOLIB_LR11X0_PA_RAMP_16U;
18+
} else if(rampTimeUs <= 32) {
19+
regVal = RADIOLIB_LR11X0_PA_RAMP_32U;
20+
} else if(rampTimeUs <= 48) {
21+
regVal = RADIOLIB_LR11X0_PA_RAMP_48U;
22+
} else if(rampTimeUs <= 64) {
23+
regVal = RADIOLIB_LR11X0_PA_RAMP_64U;
24+
} else if(rampTimeUs <= 80) {
25+
regVal = RADIOLIB_LR11X0_PA_RAMP_80U;
26+
} else if(rampTimeUs <= 96) {
27+
regVal = RADIOLIB_LR11X0_PA_RAMP_96U;
28+
} else if(rampTimeUs <= 112) {
29+
regVal = RADIOLIB_LR11X0_PA_RAMP_112U;
30+
} else if(rampTimeUs <= 128) {
31+
regVal = RADIOLIB_LR11X0_PA_RAMP_128U;
32+
} else if(rampTimeUs <= 144) {
33+
regVal = RADIOLIB_LR11X0_PA_RAMP_144U;
34+
} else if(rampTimeUs <= 160) {
35+
regVal = RADIOLIB_LR11X0_PA_RAMP_160U;
36+
} else if(rampTimeUs <= 176) {
37+
regVal = RADIOLIB_LR11X0_PA_RAMP_176U;
38+
} else if(rampTimeUs <= 192) {
39+
regVal = RADIOLIB_LR11X0_PA_RAMP_192U;
40+
} else if(rampTimeUs <= 208) {
41+
regVal = RADIOLIB_LR11X0_PA_RAMP_208U;
42+
} else if(rampTimeUs <= 240) {
43+
regVal = RADIOLIB_LR11X0_PA_RAMP_240U;
44+
} else if(rampTimeUs <= 272) {
45+
regVal = RADIOLIB_LR11X0_PA_RAMP_272U;
46+
} else { // 304
47+
regVal = RADIOLIB_LR11X0_PA_RAMP_304U;
48+
}
49+
50+
return regVal;
51+
}
52+
1153
int16_t LR11x0::writeRegMem32(uint32_t addr, const uint32_t* data, size_t len) {
1254
// check maximum size
1355
if(len > (RADIOLIB_LR11X0_SPI_MAX_READ_WRITE_LEN/sizeof(uint32_t))) {

0 commit comments

Comments
 (0)