Skip to content

Commit 23f49f3

Browse files
committed
[LR11X0] Add support for specifying PA ramp time
1 parent 5b38ce9 commit 23f49f3

File tree

6 files changed

+121
-52
lines changed

6 files changed

+121
-52
lines changed

src/modules/LR11x0/LR1110.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int16_t LR1110::setFrequency(float freq) {
5252

5353
int16_t LR1110::setFrequency(float freq, bool skipCalibration, float band) {
5454
RADIOLIB_CHECK_RANGE(freq, 150.0f, 960.0f, RADIOLIB_ERR_INVALID_FREQUENCY);
55-
55+
5656
// check if we need to recalibrate image
5757
int16_t state;
5858
if(!skipCalibration && (fabsf(freq - this->freqMHz) >= RADIOLIB_LR11X0_CAL_IMG_FREQ_TRIG_MHZ)) {
@@ -71,22 +71,22 @@ 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);
7878

7979
// determine whether to use HP or LP PA and check range accordingly
8080
bool useHp = forceHighPower || (power > 14);
81-
81+
8282
// TODO how and when to configure OCP?
8383

8484
// update PA config - always use VBAT for high-power PA
8585
state = setPaConfig((uint8_t)useHp, (uint8_t)useHp, 0x04, 0x07);
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

@@ -100,13 +100,13 @@ int16_t LR1110::checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPo
100100
*clipped = RADIOLIB_MAX(-9, RADIOLIB_MIN(22, power));
101101
}
102102
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
103-
103+
104104
} else {
105105
if(clipped) {
106106
*clipped = RADIOLIB_MAX(-17, RADIOLIB_MIN(14, power));
107107
}
108108
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
109-
109+
110110
}
111111
return(RADIOLIB_ERR_NONE);
112112
}

src/modules/LR11x0/LR1110.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class LR1110: public LR11x0 {
5252
\returns \ref status_codes
5353
*/
5454
int16_t beginGFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6);
55-
55+
5656
/*!
5757
\brief Initialization method for LR-FHSS modem.
5858
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
@@ -90,7 +90,7 @@ class LR1110: public LR11x0 {
9090
\returns \ref status_codes
9191
*/
9292
int16_t setFrequency(float freq, bool skipCalibration, float band = 4);
93-
93+
9494
/*!
9595
\brief Sets output power. Allowed values are in range from -9 to 22 dBm (high-power PA) or -17 to 14 dBm (low-power PA).
9696
\param power Output power to be set in dBm, output PA is determined automatically preferring the low-power PA.
@@ -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: 5 additions & 5 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);
@@ -92,15 +92,15 @@ int16_t LR1120::setOutputPower(int8_t power, bool forceHighPower) {
9292
paSel = 1;
9393
paSupply = 1;
9494
}
95-
95+
9696
// TODO how and when to configure OCP?
9797

9898
// update PA config - always use VBAT for high-power PA
9999
state = setPaConfig(paSel, paSupply, 0x04, 0x07);
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

@@ -122,13 +122,13 @@ int16_t LR1120::checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPo
122122
*clipped = RADIOLIB_MAX(-9, RADIOLIB_MIN(22, power));
123123
}
124124
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
125-
125+
126126
} else {
127127
if(clipped) {
128128
*clipped = RADIOLIB_MAX(-17, RADIOLIB_MIN(14, power));
129129
}
130130
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
131-
131+
132132
}
133133
return(RADIOLIB_ERR_NONE);
134134
}

src/modules/LR11x0/LR1120.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class LR1120: public LR11x0 {
5252
\returns \ref status_codes
5353
*/
5454
int16_t beginGFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6);
55-
55+
5656
/*!
5757
\brief Initialization method for LR-FHSS modem.
5858
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
@@ -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: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@
264264
#define RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED (0x01UL << 4) // 31 0 preamble detected
265265
#define RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID (0x01UL << 5) // 31 0 sync word or LoRa header valid
266266
#define RADIOLIB_LR11X0_IRQ_HEADER_ERR (0x01UL << 6) // 31 0 LoRa header CRC error
267-
#define RADIOLIB_LR11X0_IRQ_CRC_ERR (0x01UL << 7) // 31 0 packet CRC error
267+
#define RADIOLIB_LR11X0_IRQ_CRC_ERR (0x01UL << 7) // 31 0 packet CRC error
268268
#define RADIOLIB_LR11X0_IRQ_CAD_DONE (0x01UL << 8) // 31 0 CAD completed
269269
#define RADIOLIB_LR11X0_IRQ_CAD_DETECTED (0x01UL << 9) // 31 0 CAD detected
270270
#define RADIOLIB_LR11X0_IRQ_TIMEOUT (0x01UL << 10) // 31 0 Rx or Tx timeout
@@ -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
@@ -760,22 +775,22 @@ struct LR11x0VersionInfo_t {
760775

761776
/*! \brief Which device this is - one of RADIOLIB_LR11X0_DEVICE_* macros. */
762777
uint8_t device;
763-
778+
764779
/*! \brief Major revision of the base firmware. */
765780
uint8_t fwMajor;
766-
781+
767782
/*! \brief Minor revision of the base firmware. */
768783
uint8_t fwMinor;
769784

770785
/*! \brief Major revision of the WiFi firmware. */
771786
uint8_t fwMajorWiFi;
772-
787+
773788
/*! \brief Minor revision of the WiFi firmware. */
774789
uint8_t fwMinorWiFi;
775790

776791
/*! \brief Revision of the GNSS firmware. */
777792
uint8_t fwGNSS;
778-
793+
779794
/*! \brief Almanac revision of the GNSS firmware. */
780795
uint8_t almanacGNSS;
781796
};
@@ -787,7 +802,7 @@ struct LR11x0VersionInfo_t {
787802
struct LR11x0GnssResult_t {
788803
/*! \brief Demodulator status. One of RADIOLIB_LR11X0_GNSS_DEMOD_STATUS_* */
789804
int8_t demodStat;
790-
805+
791806
/*! \brief Number of satellites detected during the scan. */
792807
uint8_t numSatsDet;
793808

@@ -913,7 +928,7 @@ class LR11x0: public PhysicalLayer {
913928
\brief Whether the module has an XTAL (true) or TCXO (false). Defaults to false.
914929
*/
915930
bool XTAL;
916-
931+
917932
/*!
918933
\brief Initialization method for LoRa modem.
919934
\param bw LoRa bandwidth in kHz.
@@ -1038,7 +1053,7 @@ class LR11x0: public PhysicalLayer {
10381053
\returns \ref status_codes
10391054
*/
10401055
int16_t sleep(bool retainConfig, uint32_t sleepTime);
1041-
1056+
10421057
// interrupt methods
10431058

10441059
/*!
@@ -1103,7 +1118,7 @@ class LR11x0: public PhysicalLayer {
11031118
\returns \ref status_codes
11041119
*/
11051120
int16_t readData(uint8_t* data, size_t len) override;
1106-
1121+
11071122
/*!
11081123
\brief Interrupt-driven channel activity detection method. IRQ1 will be activated
11091124
when LoRa preamble is detected, or upon timeout. Defaults to CAD parameter values recommended by AN1200.48.
@@ -1180,7 +1195,7 @@ class LR11x0: public PhysicalLayer {
11801195
\returns \ref status_codes
11811196
*/
11821197
int16_t setRxBandwidth(float rxBw);
1183-
1198+
11841199
/*!
11851200
\brief Sets GFSK sync word in the form of array of up to 8 bytes.
11861201
\param syncWord GFSK sync word to be set.
@@ -1443,7 +1458,7 @@ class LR11x0: public PhysicalLayer {
14431458
\returns \ref status_codes
14441459
*/
14451460
int16_t setLrFhssConfig(uint8_t bw, uint8_t cr, uint8_t hdrCount = 3, uint16_t hopSeed = 0x13A);
1446-
1461+
14471462
/*!
14481463
\brief Start passive WiFi scan. BUSY pin will be de-activated when the scan is finished.
14491464
\param wifiType Type of WiFi (802.11) signals to scan, 'b', 'n', 'g' or '*' for all signals.
@@ -1488,7 +1503,7 @@ class LR11x0: public PhysicalLayer {
14881503
\returns \ref status_codes
14891504
*/
14901505
int16_t getWifiScanResult(LR11x0WifiResult_t* result, uint8_t index, bool brief = false);
1491-
1506+
14921507
/*!
14931508
\brief Blocking WiFi scan method. Performs a full passive WiFi scan.
14941509
This method may block for several seconds!
@@ -1506,14 +1521,14 @@ class LR11x0: public PhysicalLayer {
15061521
\returns \ref status_codes
15071522
*/
15081523
int16_t wifiScan(uint8_t wifiType, uint8_t* count, uint8_t mode = RADIOLIB_LR11X0_WIFI_ACQ_MODE_FULL_BEACON, uint16_t chanMask = RADIOLIB_LR11X0_WIFI_ALL_CHANNELS, uint8_t numScans = 16, uint16_t timeout = 100);
1509-
1524+
15101525
/*!
15111526
\brief Retrieve LR11x0 hardware, device and firmware version information.
15121527
\param info Pointer to LR11x0VersionInfo_t structure to populate.
15131528
\returns \ref status_codes
15141529
*/
15151530
int16_t getVersionInfo(LR11x0VersionInfo_t* info);
1516-
1531+
15171532
/*!
15181533
\brief Method to upload new firmware image to the device.
15191534
The device will be automatically erased, a new firmware will be uploaded,
@@ -1525,7 +1540,7 @@ class LR11x0: public PhysicalLayer {
15251540
\returns \ref status_codes
15261541
*/
15271542
int16_t updateFirmware(const uint32_t* image, size_t size, bool nonvolatile = true);
1528-
1543+
15291544
/*!
15301545
\brief Method to check whether the device is capable of performing a GNSS scan.
15311546
\returns \ref status_codes
@@ -1566,7 +1581,7 @@ class LR11x0: public PhysicalLayer {
15661581
\returns \ref status_codes
15671582
*/
15681583
int16_t updateGnssAlmanac(uint8_t constellation);
1569-
1584+
15701585
/*!
15711586
\brief Get GNSS position. Called after gnssScan to retrieve the position calculated by the internal solver.
15721587
\param pos Pointer to LR11x0GnssPosition_t structure to populate.
@@ -1598,18 +1613,26 @@ class LR11x0: public PhysicalLayer {
15981613
\returns \ref status_codes
15991614
*/
16001615
int16_t calibrateImageRejection(float freqMin, float freqMax);
1601-
1616+
16021617
/*! \copydoc PhysicalLayer::stageMode */
16031618
int16_t stageMode(RadioModeType_t mode, RadioModeConfig_t* cfg) override;
16041619

16051620
/*! \copydoc PhysicalLayer::launchMode */
16061621
int16_t launchMode() override;
1607-
1622+
16081623
#if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL
16091624
protected:
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);
@@ -1777,9 +1800,9 @@ class LR11x0: public PhysicalLayer {
17771800
int16_t bootGetPin(uint8_t* pin);
17781801
int16_t bootGetChipEui(uint8_t* eui);
17791802
int16_t bootGetJoinEui(uint8_t* eui);
1780-
1803+
17811804
int16_t SPIcommand(uint16_t cmd, bool write, uint8_t* data, size_t len, const uint8_t* out = NULL, size_t outLen = 0);
1782-
1805+
17831806
#if !RADIOLIB_GODMODE
17841807
protected:
17851808
#endif

0 commit comments

Comments
 (0)