cleanup so eventually rf95 can share common msg code with sx1262

1.2-legacy
geeksville 2020-04-29 16:28:11 -07:00
rodzic 4693302d82
commit 8d985cfd37
5 zmienionych plików z 67 dodań i 34 usunięć

Wyświetl plik

@ -118,7 +118,7 @@ static uint32_t ledBlinker()
Periodic ledPeriodic(ledBlinker);
#include "RadioLibInterface.h"
#include "SX1262Interface.h"
#include "variant.h"
void setup()
@ -196,7 +196,7 @@ void setup()
#if defined(RF95_IRQ_GPIO)
new CustomRF95();
#elif defined(SX1262_CS)
new RadioLibInterface(SX1262_CS, SX1262_DIO1, SX1262_RESET, SX1262_BUSY, SPI);
new SX1262Interface(SX1262_CS, SX1262_DIO1, SX1262_RESET, SX1262_BUSY, SPI);
#else
new SimRadio();
#endif

Wyświetl plik

@ -5,8 +5,8 @@
static SPISettings spiSettings(4000000, MSBFIRST, SPI_MODE0);
RadioLibInterface::RadioLibInterface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy,
SPIClass &spi)
: module(cs, irq, rst, busy, spi, spiSettings), lora(&module)
SPIClass &spi, PhysicalLayer *_iface)
: module(cs, irq, rst, busy, spi, spiSettings), iface(*_iface)
{
}
@ -15,23 +15,6 @@ ErrorCode RadioLibInterface::send(MeshPacket *p)
return ERR_NONE;
}
/// Initialise the Driver transport hardware and software.
/// Make sure the Driver is properly configured before calling init().
/// \return true if initialisation succeeded.
bool RadioLibInterface::init()
{
// FIXME, move this to main
SPI.begin();
float tcxoVoltage = 0; // None - we use an XTAL
bool useRegulatorLDO = false; // Seems to depend on the connection to pin 9/DCC_SW - if an inductor DCDC?
int res = lora.begin(freq, bw, sf, cr, syncWord, power, currentLimit, preambleLength, tcxoVoltage, useRegulatorLDO);
DEBUG_MSG("LORA init result %d\n", res);
return res == ERR_NONE;
}
/**
*
*

Wyświetl plik

@ -6,11 +6,27 @@
class RadioLibInterface : public RadioInterface
{
protected:
float freq = 915.0; // FIXME, init all these params from suer setings
float bw = 125;
uint8_t sf = 9;
uint8_t cr = 7;
uint8_t syncWord = 0; // FIXME, use a meshtastic sync word, but hashed with the Channel name
int8_t power = 17;
float currentLimit = 100; // FIXME
uint16_t preambleLength = 8;
Module module; // The HW interface to the radio
SX1262 lora;
/**
* provides lowest common denominator RadioLib API
*/
PhysicalLayer &iface;
public:
RadioLibInterface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi);
RadioLibInterface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy,
SPIClass &spi,
PhysicalLayer *iface);
virtual ErrorCode send(MeshPacket *p);
@ -30,7 +46,7 @@ class RadioLibInterface : public RadioInterface
/// Initialise the Driver transport hardware and software.
/// Make sure the Driver is properly configured before calling init().
/// \return true if initialisation succeeded.
virtual bool init();
virtual bool init() { return true; }
/// Sets the transmitter and receiver
/// centre frequency.
@ -79,14 +95,4 @@ class RadioLibInterface : public RadioInterface
/// \param[in] useRFO If true, enables the use of the RFO transmitter pins instead of
/// the PA_BOOST pin (false). Choose the correct setting for your module.
void setTxPower(int8_t power, bool useRFO = false) {}
private:
float freq = 915.0; // FIXME, init all these params from suer setings
float bw = 125;
uint8_t sf = 9;
uint8_t cr = 7;
uint8_t syncWord = 0; // FIXME, use a meshtastic sync word, but hashed with the Channel name
int8_t power = 17;
float currentLimit = 100; // FIXME
uint16_t preambleLength = 8;
};

Wyświetl plik

@ -0,0 +1,28 @@
#include "SX1262Interface.h"
#include <configuration.h>
SX1262Interface::SX1262Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy,
SPIClass &spi)
: RadioLibInterface(cs, irq, rst, busy, spi, &lora), lora(&module)
{
}
/// Initialise the Driver transport hardware and software.
/// Make sure the Driver is properly configured before calling init().
/// \return true if initialisation succeeded.
bool SX1262Interface::init()
{
if (!RadioLibInterface::init())
return false;
// FIXME, move this to main
SPI.begin();
float tcxoVoltage = 0; // None - we use an XTAL
bool useRegulatorLDO = false; // Seems to depend on the connection to pin 9/DCC_SW - if an inductor DCDC?
int res = lora.begin(freq, bw, sf, cr, syncWord, power, currentLimit, preambleLength, tcxoVoltage, useRegulatorLDO);
DEBUG_MSG("LORA init result %d\n", res);
return res == ERR_NONE;
}

Wyświetl plik

@ -0,0 +1,16 @@
#pragma once
#include "RadioLibInterface.h"
class SX1262Interface : public RadioLibInterface
{
SX1262 lora;
public:
SX1262Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi);
/// Initialise the Driver transport hardware and software.
/// Make sure the Driver is properly configured before calling init().
/// \return true if initialisation succeeded.
virtual bool init();
};