mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-09-14 15:16:40 +00:00
add Meshnology W12 support and LR2021 wrapper
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#include <RadioLib.h>
|
||||
#include "MeshCore.h"
|
||||
|
||||
class CustomLR2021 : public LR2021 {
|
||||
bool _rx_boosted = false;
|
||||
|
||||
public:
|
||||
CustomLR2021(Module *mod) : LR2021(mod) { irqDioNum = LR2021_IRQ_DIO; }
|
||||
|
||||
bool std_init(SPIClass* spi = NULL)
|
||||
{
|
||||
|
||||
#ifdef LR2021_TCXO_VOLTAGE
|
||||
float tcxo = LR2021_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(); }
|
||||
#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_LR2021_LORA_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo);
|
||||
// if radio init fails with -707/-706, try again with tcxo voltage set to 0.0f
|
||||
if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) {
|
||||
tcxo = 0.0f;
|
||||
status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_LR2021_LORA_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo);
|
||||
}
|
||||
if (status != RADIOLIB_ERR_NONE) {
|
||||
Serial.print("ERROR: radio init failed: ");
|
||||
Serial.println(status);
|
||||
return false; // fail
|
||||
}
|
||||
|
||||
setCRC(2);
|
||||
explicitHeader();
|
||||
|
||||
|
||||
#ifdef LR2021_RX_BOOSTED_GAIN
|
||||
setRxBoostedGainMode(LR2021_RX_BOOSTED_GAIN);
|
||||
#endif
|
||||
|
||||
return true; // success
|
||||
}
|
||||
|
||||
float getFreqMHz() const { return freqMHz; }
|
||||
|
||||
bool getRxBoostedGainMode() const { return _rx_boosted; }
|
||||
|
||||
bool isReceiving() {
|
||||
uint32_t irq = getIrqStatus();
|
||||
bool detected = ((irq & RADIOLIB_LR2021_IRQ_SYNCWORD_VALID) || (irq & RADIOLIB_LR2021_IRQ_PREAMBLE_DETECTED));
|
||||
return detected;
|
||||
}
|
||||
|
||||
uint8_t getSpreadingFactor() const { return spreadingFactor; }
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "CustomLR2021.h"
|
||||
#include "RadioLibWrappers.h"
|
||||
|
||||
#ifndef USE_LR2021
|
||||
#define USE_LR2021
|
||||
#endif
|
||||
|
||||
#ifndef LR2021_RX_BOOST_LEVEL
|
||||
#define LR2021_RX_BOOST_LEVEL 7
|
||||
#endif
|
||||
|
||||
class CustomLR2021Wrapper : public RadioLibWrapper {
|
||||
public:
|
||||
CustomLR2021Wrapper(CustomLR2021& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { }
|
||||
|
||||
void setParams(float freq, float bw, uint8_t sf, uint8_t cr) override {
|
||||
((CustomLR2021 *)_radio)->setFrequency(freq);
|
||||
((CustomLR2021 *)_radio)->setSpreadingFactor(sf);
|
||||
((CustomLR2021 *)_radio)->setBandwidth(bw);
|
||||
((CustomLR2021 *)_radio)->setCodingRate(cr);
|
||||
updatePreamble(sf);
|
||||
}
|
||||
|
||||
bool isReceivingPacket() override {
|
||||
return ((CustomLR2021 *)_radio)->isReceiving();
|
||||
}
|
||||
|
||||
float getCurrentRSSI() override {
|
||||
float rssi = -110;
|
||||
((CustomLR2021 *)_radio)->getRssiInst(&rssi);
|
||||
return rssi;
|
||||
}
|
||||
|
||||
void onSendFinished() override {
|
||||
RadioLibWrapper::onSendFinished();
|
||||
_radio->setPreambleLength(preambleLengthForSF(getSpreadingFactor())); // overcomes weird issues with small and big pkts
|
||||
}
|
||||
|
||||
float getLastRSSI() const override { return ((CustomLR2021 *)_radio)->getRSSI(); }
|
||||
float getLastSNR() const override { return ((CustomLR2021 *)_radio)->getSNR(); }
|
||||
|
||||
uint8_t getSpreadingFactor() const override { return ((CustomLR2021 *)_radio)->getSpreadingFactor(); }
|
||||
|
||||
bool setRxBoostedGainMode(bool en) override {
|
||||
((CustomLR2021 *)_radio)->standby(); // radio must be in standby to accept the setRxBoostedGainMode command, otherwise it returns -707 error.
|
||||
int16_t status = ((CustomLR2021 *)_radio)->setRxBoostedGainMode(en ? LR2021_RX_BOOST_LEVEL: 0);
|
||||
RadioLibWrapper::idle(); // trigger startReceive()
|
||||
return status == RADIOLIB_ERR_NONE;
|
||||
}
|
||||
|
||||
bool getRxBoostedGainMode() const override {
|
||||
return ((CustomLR2021 *)_radio)->getRxBoostedGainMode();
|
||||
}
|
||||
|
||||
};
|
||||
@@ -133,7 +133,11 @@ int RadioLibWrapper::recvRaw(uint8_t* bytes, int sz) {
|
||||
n_recv++;
|
||||
}
|
||||
}
|
||||
#if defined(USE_LR2021)
|
||||
state = STATE_RX; // LR2021 stays in Rx after readData, if we issue another startReceive while still in Rx we get -706 errors.
|
||||
#else
|
||||
state = STATE_IDLE; // need another startReceive()
|
||||
#endif
|
||||
}
|
||||
|
||||
if (state != STATE_RX) {
|
||||
|
||||
Reference in New Issue
Block a user