mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 06:32:06 +00:00
cleanup so eventually rf95 can share common msg code with sx1262
This commit is contained in:
parent
4693302d82
commit
8d985cfd37
@ -118,7 +118,7 @@ static uint32_t ledBlinker()
|
|||||||
|
|
||||||
Periodic ledPeriodic(ledBlinker);
|
Periodic ledPeriodic(ledBlinker);
|
||||||
|
|
||||||
#include "RadioLibInterface.h"
|
#include "SX1262Interface.h"
|
||||||
#include "variant.h"
|
#include "variant.h"
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
@ -196,7 +196,7 @@ void setup()
|
|||||||
#if defined(RF95_IRQ_GPIO)
|
#if defined(RF95_IRQ_GPIO)
|
||||||
new CustomRF95();
|
new CustomRF95();
|
||||||
#elif defined(SX1262_CS)
|
#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
|
#else
|
||||||
new SimRadio();
|
new SimRadio();
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
static SPISettings spiSettings(4000000, MSBFIRST, SPI_MODE0);
|
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,
|
RadioLibInterface::RadioLibInterface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy,
|
||||||
SPIClass &spi)
|
SPIClass &spi, PhysicalLayer *_iface)
|
||||||
: module(cs, irq, rst, busy, spi, spiSettings), lora(&module)
|
: module(cs, irq, rst, busy, spi, spiSettings), iface(*_iface)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,23 +15,6 @@ ErrorCode RadioLibInterface::send(MeshPacket *p)
|
|||||||
return ERR_NONE;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -6,11 +6,27 @@
|
|||||||
|
|
||||||
class RadioLibInterface : public RadioInterface
|
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
|
Module module; // The HW interface to the radio
|
||||||
SX1262 lora;
|
|
||||||
|
/**
|
||||||
|
* provides lowest common denominator RadioLib API
|
||||||
|
*/
|
||||||
|
PhysicalLayer &iface;
|
||||||
|
|
||||||
public:
|
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);
|
virtual ErrorCode send(MeshPacket *p);
|
||||||
|
|
||||||
@ -30,7 +46,7 @@ class RadioLibInterface : public RadioInterface
|
|||||||
/// Initialise the Driver transport hardware and software.
|
/// Initialise the Driver transport hardware and software.
|
||||||
/// Make sure the Driver is properly configured before calling init().
|
/// Make sure the Driver is properly configured before calling init().
|
||||||
/// \return true if initialisation succeeded.
|
/// \return true if initialisation succeeded.
|
||||||
virtual bool init();
|
virtual bool init() { return true; }
|
||||||
|
|
||||||
/// Sets the transmitter and receiver
|
/// Sets the transmitter and receiver
|
||||||
/// centre frequency.
|
/// 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
|
/// \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.
|
/// the PA_BOOST pin (false). Choose the correct setting for your module.
|
||||||
void setTxPower(int8_t power, bool useRFO = false) {}
|
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;
|
|
||||||
};
|
};
|
28
src/rf95/SX1262Interface.cpp
Normal file
28
src/rf95/SX1262Interface.cpp
Normal file
@ -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;
|
||||||
|
}
|
16
src/rf95/SX1262Interface.h
Normal file
16
src/rf95/SX1262Interface.h
Normal file
@ -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();
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user