Skip to content

Commit

Permalink
[LR112x] enabled higher bandwidth settings for 2.4G lora (#1235)
Browse files Browse the repository at this point in the history
* enabled higher bandwidth settings for 2.4G lora

* document new parameters

* use the same cutoff as this->highFreq
  • Loading branch information
caveman99 authored Sep 27, 2024
1 parent 56bf7c8 commit 42ae7c9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/modules/LR11x0/LR1120.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LR1120::LR1120(Module* mod) : LR11x0(mod) {

int16_t LR1120::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage) {
// execute common part
int16_t state = LR11x0::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage);
int16_t state = LR11x0::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage, freq > 1000.0);
RADIOLIB_ASSERT(state);

// configure publicly accessible settings
Expand Down
56 changes: 35 additions & 21 deletions src/modules/LR11x0/LR11x0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ LR11x0::LR11x0(Module* mod) : PhysicalLayer(RADIOLIB_LR11X0_FREQUENCY_STEP_SIZE,
this->irqMap[RADIOLIB_IRQ_TIMEOUT] = RADIOLIB_LR11X0_IRQ_TIMEOUT;
}

int16_t LR11x0::begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage) {
int16_t LR11x0::begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool high) {
// set module properties and perform initial setup
int16_t state = this->modSetup(tcxoVoltage, RADIOLIB_LR11X0_PACKET_TYPE_LORA);
RADIOLIB_ASSERT(state);

// configure publicly accessible settings
state = setBandwidth(bw);
state = setBandwidth(bw, high);
RADIOLIB_ASSERT(state);

state = setSpreadingFactor(sf);
Expand Down Expand Up @@ -623,7 +623,7 @@ int16_t LR11x0::getChannelScanResult() {
return(RADIOLIB_ERR_UNKNOWN);
}

int16_t LR11x0::setBandwidth(float bw) {
int16_t LR11x0::setBandwidth(float bw, bool high) {
// check active modem
uint8_t type = RADIOLIB_LR11X0_PACKET_TYPE_NONE;
int16_t state = getPacketType(&type);
Expand All @@ -633,25 +633,39 @@ int16_t LR11x0::setBandwidth(float bw) {
}

// ensure byte conversion doesn't overflow
RADIOLIB_CHECK_RANGE(bw, 0.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);

// check allowed bandwidth values
uint8_t bw_div2 = bw / 2 + 0.01;
switch (bw_div2) {
case 31: // 62.5:
this->bandwidth = RADIOLIB_LR11X0_LORA_BW_62_5;
break;
case 62: // 125.0:
this->bandwidth = RADIOLIB_LR11X0_LORA_BW_125_0;
break;
case 125: // 250.0
this->bandwidth = RADIOLIB_LR11X0_LORA_BW_250_0;
break;
case 250: // 500.0
this->bandwidth = RADIOLIB_LR11X0_LORA_BW_500_0;
break;
default:
if (high) {
RADIOLIB_CHECK_RANGE(bw, 203.125, 815.0, RADIOLIB_ERR_INVALID_BANDWIDTH);

if(fabsf(bw - 203.125) <= 0.001) {
this->bandwidth = RADIOLIB_LR11X0_LORA_BW_203_125;
} else if(fabsf(bw - 406.25) <= 0.001) {
this->bandwidth = RADIOLIB_LR11X0_LORA_BW_406_25;
} else if(fabsf(bw - 812.5) <= 0.001) {
this->bandwidth = RADIOLIB_LR11X0_LORA_BW_812_50;
} else {
return(RADIOLIB_ERR_INVALID_BANDWIDTH);
}
} else {
RADIOLIB_CHECK_RANGE(bw, 0.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);

// check allowed bandwidth values
uint8_t bw_div2 = bw / 2 + 0.01;
switch (bw_div2) {
case 31: // 62.5:
this->bandwidth = RADIOLIB_LR11X0_LORA_BW_62_5;
break;
case 62: // 125.0:
this->bandwidth = RADIOLIB_LR11X0_LORA_BW_125_0;
break;
case 125: // 250.0
this->bandwidth = RADIOLIB_LR11X0_LORA_BW_250_0;
break;
case 250: // 500.0
this->bandwidth = RADIOLIB_LR11X0_LORA_BW_500_0;
break;
default:
return(RADIOLIB_ERR_INVALID_BANDWIDTH);
}
}

// update modulation parameters
Expand Down
11 changes: 8 additions & 3 deletions src/modules/LR11x0/LR11x0.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@
#define RADIOLIB_LR11X0_LORA_BW_125_0 (0x04UL << 0) // 7 0 125.0 kHz
#define RADIOLIB_LR11X0_LORA_BW_250_0 (0x05UL << 0) // 7 0 250.0 kHz
#define RADIOLIB_LR11X0_LORA_BW_500_0 (0x06UL << 0) // 7 0 500.0 kHz
#define RADIOLIB_LR11X0_LORA_BW_203_125 (0x0DUL << 0) // 7 0 203.0 kHz (2.4GHz only)
#define RADIOLIB_LR11X0_LORA_BW_406_25 (0x0EUL << 0) // 7 0 406.0 kHz (2.4GHz only)
#define RADIOLIB_LR11X0_LORA_BW_812_50 (0x0FUL << 0) // 7 0 812.0 kHz (2.4GHz only)
#define RADIOLIB_LR11X0_LORA_CR_4_5_SHORT (0x01UL << 0) // 7 0 coding rate: 4/5 with short interleaver
#define RADIOLIB_LR11X0_LORA_CR_4_6_SHORT (0x02UL << 0) // 7 0 4/6 with short interleaver
#define RADIOLIB_LR11X0_LORA_CR_4_7_SHORT (0x03UL << 0) // 7 0 4/7 with short interleaver
Expand Down Expand Up @@ -773,9 +776,10 @@ class LR11x0: public PhysicalLayer {
\param syncWord 1-byte LoRa sync word.
\param preambleLength LoRa preamble length in symbols
\param tcxoVoltage TCXO reference voltage to be set.
\param high defaults to false for Sub-GHz band, true for frequencies above 1GHz
\returns \ref status_codes
*/
int16_t begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage);
int16_t begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool high = false);

/*!
\brief Initialization method for FSK modem.
Expand Down Expand Up @@ -993,11 +997,12 @@ class LR11x0: public PhysicalLayer {
// configuration methods

/*!
\brief Sets LoRa bandwidth. Allowed values are 62.5, 125.0, 250.0 and 500.0 kHz.
\brief Sets LoRa bandwidth. Allowed values are 62.5, 125.0, 250.0 and 500.0 kHz. (default, high = false)
\param bw LoRa bandwidth to be set in kHz.
\param high if set to true, allowed bandwidth is 203.125, 406.25 and 812.5 kHz, frequency must be above 1GHz
\returns \ref status_codes
*/
int16_t setBandwidth(float bw);
int16_t setBandwidth(float bw, bool high = false);

/*!
\brief Sets LoRa spreading factor. Allowed values range from 5 to 12.
Expand Down

0 comments on commit 42ae7c9

Please sign in to comment.