mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
sx1276 boards: migrate to std_init()
This commit is contained in:
parent
f15f32e138
commit
07f25ccac8
5 changed files with 69 additions and 60 deletions
|
|
@ -12,6 +12,59 @@ class CustomSX1276 : public SX1276 {
|
||||||
public:
|
public:
|
||||||
CustomSX1276(Module *mod) : SX1276(mod) { }
|
CustomSX1276(Module *mod) : SX1276(mod) { }
|
||||||
|
|
||||||
|
#ifdef RP2040_PLATFORM
|
||||||
|
bool std_init(SPIClassRP2040* spi = NULL)
|
||||||
|
#else
|
||||||
|
bool std_init(SPIClass* spi = NULL)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#ifdef LORA_CR
|
||||||
|
uint8_t cr = LORA_CR;
|
||||||
|
#else
|
||||||
|
uint8_t cr = 5;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(P_LORA_SCLK)
|
||||||
|
#ifdef NRF52_PLATFORM
|
||||||
|
if (spi) { spi->setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); spi->begin(); }
|
||||||
|
#elif defined(RP2040_PLATFORM)
|
||||||
|
if (spi) {
|
||||||
|
spi->setMISO(P_LORA_MISO);
|
||||||
|
//spi->setCS(P_LORA_NSS); // Setting CS results in freeze
|
||||||
|
spi->setSCK(P_LORA_SCLK);
|
||||||
|
spi->setMOSI(P_LORA_MOSI);
|
||||||
|
spi->begin();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
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, 8);
|
||||||
|
// if radio init fails with -707/-706, try again with tcxo voltage set to 0.0f
|
||||||
|
if (status != RADIOLIB_ERR_NONE) {
|
||||||
|
Serial.print("ERROR: radio init failed: ");
|
||||||
|
Serial.println(status);
|
||||||
|
return false; // fail
|
||||||
|
}
|
||||||
|
#ifdef SX127X_CURRENT_LIMIT
|
||||||
|
setCurrentLimit(SX127X_CURRENT_LIMIT);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(SX176X_RXEN) || defined(SX176X_TXEN)
|
||||||
|
#ifndef SX176X_RXEN
|
||||||
|
#define SX176X_RXEN RADIOLIB_NC
|
||||||
|
#endif
|
||||||
|
#ifndef SX176X_TXEN
|
||||||
|
#define SX176X_TXEN RADIOLIB_NC
|
||||||
|
#endif
|
||||||
|
setRfSwitchPins(SX176X_RXEN, SX176X_TXEN);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
setCRC(1);
|
||||||
|
|
||||||
|
return true; // success
|
||||||
|
}
|
||||||
|
|
||||||
bool isReceiving() {
|
bool isReceiving() {
|
||||||
return (getModemStatus() &
|
return (getModemStatus() &
|
||||||
(RH_RF95_MODEM_STATUS_SIGNAL_DETECTED
|
(RH_RF95_MODEM_STATUS_SIGNAL_DETECTED
|
||||||
|
|
|
||||||
|
|
@ -20,31 +20,16 @@ SensorManager sensors;
|
||||||
DISPLAY_CLASS display;
|
DISPLAY_CLASS display;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LORA_CR
|
|
||||||
#define LORA_CR 5
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool radio_init() {
|
bool radio_init() {
|
||||||
fallback_clock.begin();
|
fallback_clock.begin();
|
||||||
rtc_clock.begin(Wire);
|
rtc_clock.begin(Wire);
|
||||||
|
|
||||||
#if defined(P_LORA_SCLK)
|
#if defined(P_LORA_SCLK)
|
||||||
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
|
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
|
||||||
|
return radio.std_init(&spi);
|
||||||
|
#else
|
||||||
|
return radio.std_init();
|
||||||
#endif
|
#endif
|
||||||
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8);
|
|
||||||
if (status != RADIOLIB_ERR_NONE) {
|
|
||||||
Serial.print("ERROR: radio init failed: ");
|
|
||||||
Serial.println(status);
|
|
||||||
return false; // fail
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SX127X_CURRENT_LIMIT
|
|
||||||
radio.setCurrentLimit(SX127X_CURRENT_LIMIT);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
radio.setCRC(1);
|
|
||||||
|
|
||||||
return true; // success
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t radio_get_rng_seed() {
|
uint32_t radio_get_rng_seed() {
|
||||||
|
|
|
||||||
|
|
@ -20,33 +20,16 @@ SensorManager sensors;
|
||||||
DISPLAY_CLASS display;
|
DISPLAY_CLASS display;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LORA_CR
|
|
||||||
#define LORA_CR 5
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool radio_init() {
|
bool radio_init() {
|
||||||
fallback_clock.begin();
|
fallback_clock.begin();
|
||||||
rtc_clock.begin(Wire);
|
rtc_clock.begin(Wire);
|
||||||
|
|
||||||
#if defined(P_LORA_SCLK)
|
#if defined(P_LORA_SCLK)
|
||||||
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
|
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
|
||||||
|
return radio.std_init(&spi);
|
||||||
|
#else
|
||||||
|
return radio.std_init();
|
||||||
#endif
|
#endif
|
||||||
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8);
|
|
||||||
if (status != RADIOLIB_ERR_NONE) {
|
|
||||||
Serial.print("ERROR: radio init failed: ");
|
|
||||||
Serial.println(status);
|
|
||||||
return false; // fail
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SX127X_CURRENT_LIMIT
|
|
||||||
radio.setCurrentLimit(SX127X_CURRENT_LIMIT);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
radio.setCRC(1);
|
|
||||||
|
|
||||||
radio.setRfSwitchPins(21, 10);
|
|
||||||
|
|
||||||
return true; // success
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t radio_get_rng_seed() {
|
uint32_t radio_get_rng_seed() {
|
||||||
|
|
|
||||||
|
|
@ -10,35 +10,22 @@ WRAPPER_CLASS radio_driver(radio, board);
|
||||||
|
|
||||||
ESP32RTCClock fallback_clock;
|
ESP32RTCClock fallback_clock;
|
||||||
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||||
SensorManager sensors;
|
EnvironmentSensorManager sensors;
|
||||||
|
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
DISPLAY_CLASS display;
|
DISPLAY_CLASS display;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LORA_CR
|
|
||||||
#define LORA_CR 5
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool radio_init() {
|
bool radio_init() {
|
||||||
fallback_clock.begin();
|
fallback_clock.begin();
|
||||||
rtc_clock.begin(Wire);
|
rtc_clock.begin(Wire);
|
||||||
|
|
||||||
|
#if defined(P_LORA_SCLK)
|
||||||
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
|
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
|
||||||
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8);
|
return radio.std_init(&spi);
|
||||||
if (status != RADIOLIB_ERR_NONE) {
|
#else
|
||||||
Serial.print("ERROR: radio init failed: ");
|
return radio.std_init();
|
||||||
Serial.println(status);
|
|
||||||
return false; // fail
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SX127X_CURRENT_LIMIT
|
|
||||||
radio.setCurrentLimit(SX127X_CURRENT_LIMIT);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
radio.setCRC(1);
|
|
||||||
|
|
||||||
return true; // success
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t radio_get_rng_seed() {
|
uint32_t radio_get_rng_seed() {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include <helpers/CustomSX1276Wrapper.h>
|
#include <helpers/CustomSX1276Wrapper.h>
|
||||||
#include <helpers/AutoDiscoverRTCClock.h>
|
#include <helpers/AutoDiscoverRTCClock.h>
|
||||||
#include <helpers/SensorManager.h>
|
#include <helpers/SensorManager.h>
|
||||||
|
#include <helpers/sensors/EnvironmentSensorManager.h>
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
#include <helpers/ui/SSD1306Display.h>
|
#include <helpers/ui/SSD1306Display.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -14,7 +15,7 @@
|
||||||
extern LilyGoTLoraBoard board;
|
extern LilyGoTLoraBoard board;
|
||||||
extern WRAPPER_CLASS radio_driver;
|
extern WRAPPER_CLASS radio_driver;
|
||||||
extern AutoDiscoverRTCClock rtc_clock;
|
extern AutoDiscoverRTCClock rtc_clock;
|
||||||
extern SensorManager sensors;
|
extern EnvironmentSensorManager sensors;
|
||||||
|
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
extern DISPLAY_CLASS display;
|
extern DISPLAY_CLASS display;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue