diff --git a/src/main.cpp b/src/main.cpp index f79c9e01..22187b40 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 diff --git a/src/rf95/RadioLibInterface.cpp b/src/rf95/RadioLibInterface.cpp index 32d4704f..9f5858e0 100644 --- a/src/rf95/RadioLibInterface.cpp +++ b/src/rf95/RadioLibInterface.cpp @@ -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; -} - /** * * diff --git a/src/rf95/RadioLibInterface.h b/src/rf95/RadioLibInterface.h index 86bcd95c..6bccd7b2 100644 --- a/src/rf95/RadioLibInterface.h +++ b/src/rf95/RadioLibInterface.h @@ -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; }; \ No newline at end of file diff --git a/src/rf95/SX1262Interface.cpp b/src/rf95/SX1262Interface.cpp new file mode 100644 index 00000000..90604c6c --- /dev/null +++ b/src/rf95/SX1262Interface.cpp @@ -0,0 +1,28 @@ +#include "SX1262Interface.h" +#include + +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; +} diff --git a/src/rf95/SX1262Interface.h b/src/rf95/SX1262Interface.h new file mode 100644 index 00000000..aa577a73 --- /dev/null +++ b/src/rf95/SX1262Interface.h @@ -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(); +}; \ No newline at end of file