Skip to content

Commit 2056248

Browse files
author
Scott Powell
committed
* added std_init() to CustomSX1268
1 parent 80d2b6c commit 2056248

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

src/helpers/CustomSX1268.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,76 @@ class CustomSX1268 : public SX1268 {
99
public:
1010
CustomSX1268(Module *mod) : SX1268(mod) { }
1111

12+
#ifdef RP2040_PLATFORM
13+
bool std_init(SPIClassRP2040* spi = NULL)
14+
#else
15+
bool std_init(SPIClass* spi = NULL)
16+
#endif
17+
{
18+
#ifdef SX126X_DIO3_TCXO_VOLTAGE
19+
float tcxo = SX126X_DIO3_TCXO_VOLTAGE;
20+
#else
21+
float tcxo = 1.6f;
22+
#endif
23+
24+
#ifdef LORA_CR
25+
uint8_t cr = LORA_CR;
26+
#else
27+
uint8_t cr = 5;
28+
#endif
29+
30+
#if defined(P_LORA_SCLK)
31+
#ifdef NRF52_PLATFORM
32+
if (spi) { spi->setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); spi->begin(); }
33+
#elif defined(RP2040_PLATFORM)
34+
if (spi) {
35+
spi->setMISO(P_LORA_MISO);
36+
//spi->setCS(P_LORA_NSS); // Setting CS results in freeze
37+
spi->setSCK(P_LORA_SCLK);
38+
spi->setMOSI(P_LORA_MOSI);
39+
spi->begin();
40+
}
41+
#else
42+
if (spi) spi->begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
43+
#endif
44+
#endif
45+
int status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
46+
// if radio init fails with -707/-706, try again with tcxo voltage set to 0.0f
47+
if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) {
48+
#define SX126X_DIO3_TCXO_VOLTAGE (0.0f);
49+
tcxo = SX126X_DIO3_TCXO_VOLTAGE;
50+
status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
51+
}
52+
if (status != RADIOLIB_ERR_NONE) {
53+
Serial.print("ERROR: radio init failed: ");
54+
Serial.println(status);
55+
return false; // fail
56+
}
57+
58+
setCRC(1);
59+
60+
#ifdef SX126X_CURRENT_LIMIT
61+
setCurrentLimit(SX126X_CURRENT_LIMIT);
62+
#endif
63+
#ifdef SX126X_DIO2_AS_RF_SWITCH
64+
setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH);
65+
#endif
66+
#ifdef SX126X_RX_BOOSTED_GAIN
67+
setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN);
68+
#endif
69+
#if defined(SX126X_RXEN) || defined(SX126X_TXEN)
70+
#ifndef SX1262X_RXEN
71+
#define SX1262X_RXEN RADIOLIB_NC
72+
#endif
73+
#ifndef SX1262X_TXEN
74+
#define SX1262X_TXEN RADIOLIB_NC
75+
#endif
76+
setRfSwitchPins(SX126X_RXEN, SX126X_TXEN);
77+
#endif
78+
79+
return true; // success
80+
}
81+
1282
bool isReceiving() {
1383
uint16_t irq = getIrqFlags();
1484
bool detected = (irq & SX126X_IRQ_HEADER_VALID) || (irq & SX126X_IRQ_PREAMBLE_DETECTED);

0 commit comments

Comments
 (0)