Skip to content

Commit cea16ba

Browse files
authored
Merge pull request #453 from recrof/dev
sx1276 boards: migrate to std_init()
2 parents 3bd1dc3 + 5fa6533 commit cea16ba

File tree

7 files changed

+74
-81
lines changed

7 files changed

+74
-81
lines changed

src/helpers/CustomSX1276.h

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,71 @@ class CustomSX1276 : public SX1276 {
1212
public:
1313
CustomSX1276(Module *mod) : SX1276(mod) { }
1414

15+
#ifdef RP2040_PLATFORM
16+
bool std_init(SPIClassRP2040* spi = NULL)
17+
#else
18+
bool std_init(SPIClass* spi = NULL)
19+
#endif
20+
{
21+
#ifdef LORA_CR
22+
uint8_t cr = LORA_CR;
23+
#else
24+
uint8_t cr = 5;
25+
#endif
26+
27+
#if defined(P_LORA_SCLK)
28+
#ifdef NRF52_PLATFORM
29+
if (spi) { spi->setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); spi->begin(); }
30+
#elif defined(RP2040_PLATFORM)
31+
if (spi) {
32+
spi->setMISO(P_LORA_MISO);
33+
//spi->setCS(P_LORA_NSS); // Setting CS results in freeze
34+
spi->setSCK(P_LORA_SCLK);
35+
spi->setMOSI(P_LORA_MOSI);
36+
spi->begin();
37+
}
38+
#else
39+
if (spi) spi->begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
40+
#endif
41+
#endif
42+
int status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8);
43+
// if radio init fails with -707/-706, try again with tcxo voltage set to 0.0f
44+
if (status != RADIOLIB_ERR_NONE) {
45+
Serial.print("ERROR: radio init failed: ");
46+
Serial.println(status);
47+
return false; // fail
48+
}
49+
#ifdef SX127X_CURRENT_LIMIT
50+
setCurrentLimit(SX127X_CURRENT_LIMIT);
51+
#endif
52+
53+
#if defined(SX176X_RXEN) || defined(SX176X_TXEN)
54+
#ifndef SX176X_RXEN
55+
#define SX176X_RXEN RADIOLIB_NC
56+
#endif
57+
#ifndef SX176X_TXEN
58+
#define SX176X_TXEN RADIOLIB_NC
59+
#endif
60+
setRfSwitchPins(SX176X_RXEN, SX176X_TXEN);
61+
#endif
62+
63+
setCRC(1);
64+
65+
return true; // success
66+
}
67+
1568
bool isReceiving() {
1669
return (getModemStatus() &
17-
(RH_RF95_MODEM_STATUS_SIGNAL_DETECTED
18-
| RH_RF95_MODEM_STATUS_SIGNAL_SYNCHRONIZED
70+
(RH_RF95_MODEM_STATUS_SIGNAL_DETECTED
71+
| RH_RF95_MODEM_STATUS_SIGNAL_SYNCHRONIZED
1972
| RH_RF95_MODEM_STATUS_HEADER_INFO_VALID)) != 0;
2073
}
2174

2275
int tryScanChannel() {
2376
// start CAD
2477
int16_t state = startChannelScan();
2578
RADIOLIB_ASSERT(state);
26-
79+
2780
// wait for channel activity detected or timeout
2881
unsigned long timeout = millis() + 16;
2982
while(!this->mod->hal->digitalRead(this->mod->getIrq()) && millis() < timeout) {

variants/heltec_v2/target.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,15 @@ SensorManager sensors;
2020
DISPLAY_CLASS display;
2121
#endif
2222

23-
#ifndef LORA_CR
24-
#define LORA_CR 5
25-
#endif
26-
2723
bool radio_init() {
2824
fallback_clock.begin();
2925
rtc_clock.begin(Wire);
3026

3127
#if defined(P_LORA_SCLK)
32-
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
33-
#endif
34-
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8);
35-
if (status != RADIOLIB_ERR_NONE) {
36-
Serial.print("ERROR: radio init failed: ");
37-
Serial.println(status);
38-
return false; // fail
39-
}
40-
41-
#ifdef SX127X_CURRENT_LIMIT
42-
radio.setCurrentLimit(SX127X_CURRENT_LIMIT);
28+
return radio.std_init(&spi);
29+
#else
30+
return radio.std_init();
4331
#endif
44-
45-
radio.setCRC(1);
46-
47-
return true; // success
4832
}
4933

5034
uint32_t radio_get_rng_seed() {

variants/lilygo_t3s3_sx1276/platformio.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ build_flags =
2121
-D RADIO_CLASS=CustomSX1276
2222
-D WRAPPER_CLASS=CustomSX1276Wrapper
2323
-D SX127X_CURRENT_LIMIT=120
24+
-D SX176X_RXEN=21
25+
-D SX176X_TXEN=10
2426
-D LORA_TX_POWER=20
2527
build_src_filter = ${esp32_base.build_src_filter}
2628
+<../variants/lilygo_t3s3_sx1276>

variants/lilygo_t3s3_sx1276/target.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,16 @@ SensorManager sensors;
2020
DISPLAY_CLASS display;
2121
#endif
2222

23-
#ifndef LORA_CR
24-
#define LORA_CR 5
25-
#endif
26-
2723
bool radio_init() {
2824
fallback_clock.begin();
2925
rtc_clock.begin(Wire);
3026

3127
#if defined(P_LORA_SCLK)
3228
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
29+
return radio.std_init(&spi);
30+
#else
31+
return radio.std_init();
3332
#endif
34-
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8);
35-
if (status != RADIOLIB_ERR_NONE) {
36-
Serial.print("ERROR: radio init failed: ");
37-
Serial.println(status);
38-
return false; // fail
39-
}
40-
41-
#ifdef SX127X_CURRENT_LIMIT
42-
radio.setCurrentLimit(SX127X_CURRENT_LIMIT);
43-
#endif
44-
45-
radio.setCRC(1);
46-
47-
radio.setRfSwitchPins(21, 10);
48-
49-
return true; // success
5033
}
5134

5235
uint32_t radio_get_rng_seed() {

variants/lilygo_tbeam_SX1276/target.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,15 @@ AutoDiscoverRTCClock rtc_clock(fallback_clock);
2727
DISPLAY_CLASS display;
2828
#endif
2929

30-
#ifndef LORA_CR
31-
#define LORA_CR 5
32-
#endif
33-
3430
bool radio_init() {
3531
fallback_clock.begin();
3632
rtc_clock.begin(Wire);
3733

3834
#if defined(P_LORA_SCLK)
39-
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
40-
#endif
41-
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8);
42-
if (status != RADIOLIB_ERR_NONE) {
43-
Serial.print("ERROR: radio init failed: ");
44-
Serial.println(status);
45-
return false; // fail
46-
}
47-
48-
#ifdef SX127X_CURRENT_LIMIT
49-
radio.setCurrentLimit(SX127X_CURRENT_LIMIT);
35+
return radio.std_init(&spi);
36+
#else
37+
return radio.std_init();
5038
#endif
51-
52-
radio.setCRC(1);
53-
54-
return true; // success
5539
}
5640

5741
uint32_t radio_get_rng_seed() {

variants/lilygo_tlora_v2_1/target.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,21 @@ WRAPPER_CLASS radio_driver(radio, board);
1010

1111
ESP32RTCClock fallback_clock;
1212
AutoDiscoverRTCClock rtc_clock(fallback_clock);
13-
SensorManager sensors;
13+
EnvironmentSensorManager sensors;
1414

1515
#ifdef DISPLAY_CLASS
1616
DISPLAY_CLASS display;
1717
#endif
1818

19-
#ifndef LORA_CR
20-
#define LORA_CR 5
21-
#endif
22-
2319
bool radio_init() {
2420
fallback_clock.begin();
2521
rtc_clock.begin(Wire);
2622

27-
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
28-
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8);
29-
if (status != RADIOLIB_ERR_NONE) {
30-
Serial.print("ERROR: radio init failed: ");
31-
Serial.println(status);
32-
return false; // fail
33-
}
34-
35-
#ifdef SX127X_CURRENT_LIMIT
36-
radio.setCurrentLimit(SX127X_CURRENT_LIMIT);
23+
#if defined(P_LORA_SCLK)
24+
return radio.std_init(&spi);
25+
#else
26+
return radio.std_init();
3727
#endif
38-
39-
radio.setCRC(1);
40-
41-
return true; // success
4228
}
4329

4430
uint32_t radio_get_rng_seed() {

variants/lilygo_tlora_v2_1/target.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
#include <helpers/CustomSX1276Wrapper.h>
88
#include <helpers/AutoDiscoverRTCClock.h>
99
#include <helpers/SensorManager.h>
10+
#include <helpers/sensors/EnvironmentSensorManager.h>
1011
#ifdef DISPLAY_CLASS
1112
#include <helpers/ui/SSD1306Display.h>
1213
#endif
1314

1415
extern LilyGoTLoraBoard board;
1516
extern WRAPPER_CLASS radio_driver;
1617
extern AutoDiscoverRTCClock rtc_clock;
17-
extern SensorManager sensors;
18+
extern EnvironmentSensorManager sensors;
1819

1920
#ifdef DISPLAY_CLASS
2021
extern DISPLAY_CLASS display;

0 commit comments

Comments
 (0)