Skip to content

Commit 61e2146

Browse files
authored
Merge pull request #2867 from entr0p1/feature/sx1262-ldo-support
SX1262 LDO Support
2 parents acdf4e5 + 2cb3a29 commit 61e2146

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/helpers/radiolib/CustomSX1262.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <RadioLib.h>
4+
#include "MeshCore.h"
45

56
#define SX126X_IRQ_HEADER_VALID 0b0000010000 // 4 4 valid LoRa header received
67
#define SX126X_IRQ_PREAMBLE_DETECTED 0x04
@@ -27,6 +28,14 @@ class CustomSX1262 : public SX1262 {
2728
uint8_t cr = 5;
2829
#endif
2930

31+
#ifdef SX126X_USE_REGULATOR_LDO
32+
constexpr bool useRegulatorLDO = SX126X_USE_REGULATOR_LDO;
33+
#else
34+
constexpr bool useRegulatorLDO = false;
35+
#endif
36+
37+
MESH_DEBUG_PRINTLN("SX1262 regulator requested: %s", useRegulatorLDO ? "LDO" : "DC-DC");
38+
3039
#if defined(P_LORA_SCLK)
3140
#ifdef NRF52_PLATFORM
3241
if (spi) { spi->setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); spi->begin(); }
@@ -42,11 +51,12 @@ class CustomSX1262 : public SX1262 {
4251
if (spi) spi->begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
4352
#endif
4453
#endif
45-
int status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo);
54+
int status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo, useRegulatorLDO);
4655
// if radio init fails with -707/-706, try again with tcxo voltage set to 0.0f
4756
if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) {
57+
MESH_DEBUG_PRINTLN("SX1262 init failed with error %d, retrying with TCXO at 0.0V", status);
4858
tcxo = 0.0f;
49-
status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo);
59+
status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo, useRegulatorLDO);
5060
}
5161
if (status != RADIOLIB_ERR_NONE) {
5262
Serial.print("ERROR: radio init failed: ");
@@ -83,6 +93,8 @@ class CustomSX1262 : public SX1262 {
8393
writeRegister(0x8B5, &r_data, 1);
8494
#endif
8595

96+
MESH_DEBUG_PRINTLN("SX1262 status=0x%02X device_errors=0x%04X", getStatus(), getDeviceErrors());
97+
8698
return true; // success
8799
}
88100

0 commit comments

Comments
 (0)