|
|
|
@ -19,22 +19,27 @@ class CustomSX1262 : public SX1262 { |
|
|
|
#endif |
|
|
|
{ |
|
|
|
#ifdef SX126X_DIO3_TCXO_VOLTAGE |
|
|
|
float tcxo = SX126X_DIO3_TCXO_VOLTAGE; |
|
|
|
tcxoVoltage = SX126X_DIO3_TCXO_VOLTAGE; |
|
|
|
#else |
|
|
|
float tcxo = 1.6f; |
|
|
|
tcxoVoltage = 1.6f; |
|
|
|
#endif |
|
|
|
|
|
|
|
#ifdef LORA_CR |
|
|
|
uint8_t cr = LORA_CR; |
|
|
|
#else |
|
|
|
uint8_t cr = 5; |
|
|
|
#ifdef SX126X_USE_REGULATOR_LDO |
|
|
|
useRegulatorLDO = SX126X_USE_REGULATOR_LDO; |
|
|
|
#endif |
|
|
|
|
|
|
|
#ifdef SX126X_USE_REGULATOR_LDO |
|
|
|
constexpr bool useRegulatorLDO = SX126X_USE_REGULATOR_LDO; |
|
|
|
ConfigLoRa_t cfg; |
|
|
|
cfg.frequency = LORA_FREQ; |
|
|
|
cfg.bandwidth = LORA_BW; |
|
|
|
cfg.spreadingFactor = LORA_SF; |
|
|
|
#ifdef LORA_CR |
|
|
|
cfg.codingRate = LORA_CR; |
|
|
|
#else |
|
|
|
constexpr bool useRegulatorLDO = false; |
|
|
|
cfg.codingRate = 5; |
|
|
|
#endif |
|
|
|
cfg.syncWord = RADIOLIB_LORA_SYNC_WORD_PRIVATE; |
|
|
|
cfg.power = LORA_TX_POWER; |
|
|
|
cfg.preambleLength = 16; |
|
|
|
|
|
|
|
MESH_DEBUG_PRINTLN("SX1262 regulator requested: %s", useRegulatorLDO ? "LDO" : "DC-DC"); |
|
|
|
|
|
|
|
@ -53,12 +58,12 @@ class CustomSX1262 : public SX1262 { |
|
|
|
if (spi) spi->begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
int status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo, useRegulatorLDO); |
|
|
|
int status = begin(cfg); |
|
|
|
// if radio init fails with -707/-706, try again with tcxo voltage set to 0.0f
|
|
|
|
if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) { |
|
|
|
MESH_DEBUG_PRINTLN("SX1262 init failed with error %d, retrying with TCXO at 0.0V", status); |
|
|
|
tcxo = 0.0f; |
|
|
|
status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo, useRegulatorLDO); |
|
|
|
tcxoVoltage = 0.0f; |
|
|
|
status = begin(cfg); |
|
|
|
} |
|
|
|
if (status != RADIOLIB_ERR_NONE) { |
|
|
|
Serial.print("ERROR: radio init failed: "); |
|
|
|
|