Skip to content

Commit 5eb0847

Browse files
authored
Merge pull request #417 from oltaco/promicro-CustomSX1262
refactor: promicro with CustomSX1262::std_init()
2 parents b865ac6 + e7b0e9e commit 5eb0847

File tree

2 files changed

+7
-41
lines changed

2 files changed

+7
-41
lines changed

src/helpers/CustomSX1262.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class CustomSX1262 : public SX1262 {
3030
#endif
3131
#endif
3232
int status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
33+
// if radio init fails with -707/-706, try again with tcxo voltage set to 0.0f
34+
if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) {
35+
#define SX126X_DIO3_TCXO_VOLTAGE (0.0f);
36+
tcxo = SX126X_DIO3_TCXO_VOLTAGE;
37+
status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
38+
}
3339
if (status != RADIOLIB_ERR_NONE) {
3440
Serial.print("ERROR: radio init failed: ");
3541
Serial.println(status);

variants/promicro/target.cpp

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#include "target.h"
33
#include <helpers/ArduinoHelpers.h>
44

5-
#if ENV_INCLUDE_GPS
6-
#endif
7-
85
PromicroBoard board;
96

107
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
@@ -25,47 +22,10 @@ AutoDiscoverRTCClock rtc_clock(fallback_clock);
2522
DISPLAY_CLASS display;
2623
#endif
2724

28-
#ifndef LORA_CR
29-
#define LORA_CR 5
30-
#endif
31-
3225
bool radio_init() {
3326
rtc_clock.begin(Wire);
3427

35-
#ifdef SX126X_DIO3_TCXO_VOLTAGE
36-
float tcxo = SX126X_DIO3_TCXO_VOLTAGE;
37-
#else
38-
float tcxo = 1.6f;
39-
#endif
40-
41-
SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);
42-
SPI.begin();
43-
radio.setRfSwitchPins(SX126X_RXEN, SX126X_TXEN);
44-
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
45-
if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) {
46-
#define SX126X_DIO3_TCXO_VOLTAGE (0.0f);
47-
tcxo = SX126X_DIO3_TCXO_VOLTAGE;
48-
status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
49-
}
50-
if (status != RADIOLIB_ERR_NONE) {
51-
Serial.print("ERROR: radio init failed: ");
52-
Serial.println(status);
53-
return false; // fail
54-
}
55-
56-
radio.setCRC(1);
57-
58-
#ifdef SX126X_CURRENT_LIMIT
59-
radio.setCurrentLimit(SX126X_CURRENT_LIMIT);
60-
#endif
61-
#ifdef SX126X_DIO2_AS_RF_SWITCH
62-
radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH);
63-
#endif
64-
#ifdef SX126X_RX_BOOSTED_GAIN
65-
radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN);
66-
#endif
67-
68-
return true; // success
28+
return radio.std_init(&SPI);
6929
}
7030

7131
uint32_t radio_get_rng_seed() {

0 commit comments

Comments
 (0)