* added CustomSX1262::std_init()
* refactored variants to use std_init(): heltec_v3, t114, xiao_c3
This commit is contained in:
@@ -9,6 +9,48 @@ class CustomSX1262 : public SX1262 {
|
|||||||
public:
|
public:
|
||||||
CustomSX1262(Module *mod) : SX1262(mod) { }
|
CustomSX1262(Module *mod) : SX1262(mod) { }
|
||||||
|
|
||||||
|
bool std_init(SPIClass* spi = NULL) {
|
||||||
|
#ifdef SX126X_DIO3_TCXO_VOLTAGE
|
||||||
|
float tcxo = SX126X_DIO3_TCXO_VOLTAGE;
|
||||||
|
#else
|
||||||
|
float tcxo = 1.6f;
|
||||||
|
#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(); }
|
||||||
|
#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, tcxo);
|
||||||
|
if (status != RADIOLIB_ERR_NONE) {
|
||||||
|
Serial.print("ERROR: radio init failed: ");
|
||||||
|
Serial.println(status);
|
||||||
|
return false; // fail
|
||||||
|
}
|
||||||
|
|
||||||
|
setCRC(1);
|
||||||
|
|
||||||
|
#ifdef SX126X_CURRENT_LIMIT
|
||||||
|
setCurrentLimit(SX126X_CURRENT_LIMIT);
|
||||||
|
#endif
|
||||||
|
#ifdef SX126X_DIO2_AS_RF_SWITCH
|
||||||
|
setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH);
|
||||||
|
#endif
|
||||||
|
#ifdef SX126X_RX_BOOSTED_GAIN
|
||||||
|
setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true; // success
|
||||||
|
}
|
||||||
|
|
||||||
bool isReceiving() {
|
bool isReceiving() {
|
||||||
uint16_t irq = getIrqFlags();
|
uint16_t irq = getIrqFlags();
|
||||||
bool detected = (irq & SX126X_IRQ_HEADER_VALID) || (irq & SX126X_IRQ_PREAMBLE_DETECTED);
|
bool detected = (irq & SX126X_IRQ_HEADER_VALID) || (irq & SX126X_IRQ_PREAMBLE_DETECTED);
|
||||||
|
|||||||
@@ -20,43 +20,16 @@ EnvironmentSensorManager 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);
|
||||||
|
|
||||||
#ifdef SX126X_DIO3_TCXO_VOLTAGE
|
|
||||||
float tcxo = SX126X_DIO3_TCXO_VOLTAGE;
|
|
||||||
#else
|
|
||||||
float tcxo = 1.6f;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#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, tcxo);
|
|
||||||
if (status != RADIOLIB_ERR_NONE) {
|
|
||||||
Serial.print("ERROR: radio init failed: ");
|
|
||||||
Serial.println(status);
|
|
||||||
return false; // fail
|
|
||||||
}
|
|
||||||
|
|
||||||
radio.setCRC(1);
|
|
||||||
|
|
||||||
#ifdef SX126X_CURRENT_LIMIT
|
|
||||||
radio.setCurrentLimit(SX126X_CURRENT_LIMIT);
|
|
||||||
#endif
|
|
||||||
#ifdef SX126X_DIO2_AS_RF_SWITCH
|
|
||||||
radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH);
|
|
||||||
#endif
|
|
||||||
#ifdef SX126X_RX_BOOSTED_GAIN
|
|
||||||
radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true; // success
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t radio_get_rng_seed() {
|
uint32_t radio_get_rng_seed() {
|
||||||
|
|||||||
@@ -18,41 +18,10 @@ T114SensorManager sensors = T114SensorManager(nmea);
|
|||||||
DISPLAY_CLASS display;
|
DISPLAY_CLASS display;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LORA_CR
|
|
||||||
#define LORA_CR 5
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool radio_init() {
|
bool radio_init() {
|
||||||
rtc_clock.begin(Wire);
|
rtc_clock.begin(Wire);
|
||||||
|
|
||||||
#ifdef SX126X_DIO3_TCXO_VOLTAGE
|
|
||||||
float tcxo = SX126X_DIO3_TCXO_VOLTAGE;
|
|
||||||
#else
|
|
||||||
float tcxo = 1.6f;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);
|
return radio.std_init(&SPI);
|
||||||
SPI.begin();
|
|
||||||
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
|
|
||||||
if (status != RADIOLIB_ERR_NONE) {
|
|
||||||
Serial.print("ERROR: radio init failed: ");
|
|
||||||
Serial.println(status);
|
|
||||||
return false; // fail
|
|
||||||
}
|
|
||||||
|
|
||||||
radio.setCRC(1);
|
|
||||||
|
|
||||||
#ifdef SX126X_CURRENT_LIMIT
|
|
||||||
radio.setCurrentLimit(SX126X_CURRENT_LIMIT);
|
|
||||||
#endif
|
|
||||||
#ifdef SX126X_DIO2_AS_RF_SWITCH
|
|
||||||
radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH);
|
|
||||||
#endif
|
|
||||||
#ifdef SX126X_RX_BOOSTED_GAIN
|
|
||||||
radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true; // success
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t radio_get_rng_seed() {
|
uint32_t radio_get_rng_seed() {
|
||||||
|
|||||||
@@ -16,43 +16,16 @@ ESP32RTCClock fallback_clock;
|
|||||||
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||||
SensorManager sensors;
|
SensorManager sensors;
|
||||||
|
|
||||||
#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);
|
||||||
|
|
||||||
#ifdef SX126X_DIO3_TCXO_VOLTAGE
|
|
||||||
float tcxo = SX126X_DIO3_TCXO_VOLTAGE;
|
|
||||||
#else
|
|
||||||
float tcxo = 1.6f;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#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, tcxo);
|
|
||||||
if (status != RADIOLIB_ERR_NONE) {
|
|
||||||
Serial.print("ERROR: radio init failed: ");
|
|
||||||
Serial.println(status);
|
|
||||||
return false; // fail
|
|
||||||
}
|
|
||||||
|
|
||||||
radio.setCRC(1);
|
|
||||||
|
|
||||||
#ifdef SX126X_CURRENT_LIMIT
|
|
||||||
radio.setCurrentLimit(SX126X_CURRENT_LIMIT);
|
|
||||||
#endif
|
|
||||||
#ifdef SX126X_DIO2_AS_RF_SWITCH
|
|
||||||
radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH);
|
|
||||||
#endif
|
|
||||||
#ifdef SX126X_RX_BOOSTED_GAIN
|
|
||||||
radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true; // success
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t radio_get_rng_seed() {
|
uint32_t radio_get_rng_seed() {
|
||||||
|
|||||||
Reference in New Issue
Block a user