Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LR112x] enabled higher bandwidth settings for 2.4G lora #1235

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 5 additions & 2 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 @@ -775,7 +778,7 @@ class LR11x0: public PhysicalLayer {
\param tcxoVoltage TCXO reference voltage to be set.
\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 @@ -997,7 +1000,7 @@ class LR11x0: public PhysicalLayer {
\param bw LoRa bandwidth to be set in kHz.
\returns \ref status_codes
*/
int16_t setBandwidth(float bw);
int16_t setBandwidth(float bw, bool high = false);
caveman99 marked this conversation as resolved.
Show resolved Hide resolved

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