Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for sx1268 #321

Merged
merged 2 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions lib/BoardFinder/BoardFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
OledPins::OledPins(int8_t sda, int8_t scl, int8_t reset, int8_t addr) : Sda(sda), Scl(scl), Reset(reset), Addr(addr) {
}

LoraPins::LoraPins(int8_t sck, int8_t miso, int8_t mosi, int8_t cs, int8_t reset, int8_t irq) : Sck(sck), Miso(miso), Mosi(mosi), CS(cs), Reset(reset), IRQ(irq) {
LoraPins::LoraPins(int8_t sck, int8_t miso, int8_t mosi, int8_t cs, int8_t reset, int8_t irq, LoraModem modem) : Sck(sck), Miso(miso), Mosi(mosi), CS(cs), Reset(reset), IRQ(irq), Modem(modem) {
}

GpsPins::GpsPins(int8_t rx, int8_t tx) : Rx(rx), Tx(tx) {
Expand All @@ -30,6 +30,7 @@ BoardConfig const *BoardFinder::searchBoardConfig(logging::Logger &logger) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "searching for OLED...");

for (BoardConfig const *boardconf : _boardConfigs) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "trying board config: %s", boardconf->Name.c_str());
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf, logger) == boardconf->powerCheckStatus) {
PowerManagement powerManagement;
Wire.begin(boardconf->Oled.Sda, boardconf->Oled.Scl);
Expand All @@ -48,6 +49,7 @@ BoardConfig const *BoardFinder::searchBoardConfig(logging::Logger &logger) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "could not find OLED, will search for the modem now...");

for (BoardConfig const *boardconf : _boardConfigs) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "trying board config: %s", boardconf->Name.c_str());
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf, logger) == boardconf->powerCheckStatus) {
PowerManagement powerManagement;
Wire.begin(boardconf->Oled.Sda, boardconf->Oled.Scl);
Expand Down Expand Up @@ -148,16 +150,16 @@ bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig, logging::Logg
}

// clang-format off
BoardConfig TTGO_LORA32_V1 ("TTGO_LORA32_V1", eTTGO_LORA32_V1, OledPins( 4, 15), LoraPins( 5, 19, 27, 18, 14, 26));
BoardConfig TTGO_LORA32_V2 ("TTGO_LORA32_V2", eTTGO_LORA32_V2, OledPins(21, 22), LoraPins( 5, 19, 27, 18, 14, 26));
BoardConfig TTGO_T_Beam_V0_7 ("TTGO_T_Beam_V0_7", eTTGO_T_Beam_V0_7, OledPins(21, 22), LoraPins( 5, 19, 27, 18, 14, 26), GpsPins(15, 12), EthernetPins(), ButtonPins(38), true);
BoardConfig TTGO_T_Beam_V1_0 ("TTGO_T_Beam_V1_0", eTTGO_T_Beam_V1_0, OledPins(21, 22), LoraPins( 5, 19, 27, 18, 14, 26), GpsPins(12, 34), EthernetPins(), ButtonPins(38), true, true);
BoardConfig LILYGO_POE_ETH_BOARD ("LILYGO_POE_ETH_BOARD", eLILYGO_POE_ETH_BOARD, OledPins(33, 32), LoraPins(14, 2, 15, 12, 4, 36), GpsPins(), EthernetPins(23, 18, 5, 0, -1, ETH_CLOCK_GPIO17_OUT, ETH_PHY_LAN8720));
BoardConfig WT32_ETH_BOARD ("WT32_ETH_BOARD", eWT32_ETH_BOARD, OledPins(17, 5), LoraPins( 4, 12, 14, 15, 33, 32), GpsPins(), EthernetPins(23, 18, -1, 1, 16, ETH_CLOCK_GPIO0_IN, ETH_PHY_LAN8720));
BoardConfig TRACKERD ("TRACKERD", eTRACKERD, OledPins( 5, 4), LoraPins(18, 19, 23, 16, 14, 26));
BoardConfig HELTEC_WIFI_LORA_32_V1 ("HELTEC_WIFI_LORA_32_V1", eHELTEC_WIFI_LORA_32_V1, OledPins( 4, 15, 16), LoraPins( 5, 19, 27, 18, 14, 26));
BoardConfig HELTEC_WIFI_LORA_32_V2 ("HELTEC_WIFI_LORA_32_V2", eHELTEC_WIFI_LORA_32_V2, OledPins( 4, 15, 16), LoraPins( 5, 19, 27, 18, 14, 26));
BoardConfig HELTEC_WIFI_LORA_32_V3 ("HELTEC_WIFI_LORA_32_V3", eHELTEC_WIFI_LORA_32_V3, OledPins( 17, 18, 21), LoraPins( 9, 11, 10, 8, 12, 13));
BoardConfig GUALTHERIUS_LORAHAM_v100("GUALTHERIUS_LORAHAM_v100", eGUALTHERIUS_LORAHAM_v100, OledPins(17, 16), LoraPins(18, 19, 23, 5, 13, 35));
BoardConfig GUALTHERIUS_LORAHAM_v106("GUALTHERIUS_LORAHAM_v106", eGUALTHERIUS_LORAHAM_v106, OledPins(17, 16), LoraPins(18, 19, 23, 2, 13, 35));
BoardConfig TTGO_LORA32_V1 ("TTGO_LORA32_V1", eTTGO_LORA32_V1, OledPins( 4, 15), LoraPins( 5, 19, 27, 18, 14, 26, eSX1278));
BoardConfig TTGO_LORA32_V2 ("TTGO_LORA32_V2", eTTGO_LORA32_V2, OledPins(21, 22), LoraPins( 5, 19, 27, 18, 14, 26, eSX1278));
BoardConfig TTGO_T_Beam_V0_7 ("TTGO_T_Beam_V0_7", eTTGO_T_Beam_V0_7, OledPins(21, 22), LoraPins( 5, 19, 27, 18, 14, 26, eSX1278), GpsPins(15, 12), EthernetPins(), ButtonPins(38), true);
BoardConfig TTGO_T_Beam_V1_0 ("TTGO_T_Beam_V1_0", eTTGO_T_Beam_V1_0, OledPins(21, 22), LoraPins( 5, 19, 27, 18, 14, 26, eSX1278), GpsPins(12, 34), EthernetPins(), ButtonPins(38), true, true);
BoardConfig LILYGO_POE_ETH_BOARD ("LILYGO_POE_ETH_BOARD", eLILYGO_POE_ETH_BOARD, OledPins(33, 32), LoraPins(14, 2, 15, 12, 4, 36, eSX1278), GpsPins(), EthernetPins(23, 18, 5, 0, -1, ETH_CLOCK_GPIO17_OUT, ETH_PHY_LAN8720));
BoardConfig WT32_ETH_BOARD ("WT32_ETH_BOARD", eWT32_ETH_BOARD, OledPins(17, 5), LoraPins( 4, 12, 14, 15, 33, 32, eSX1278), GpsPins(), EthernetPins(23, 18, -1, 1, 16, ETH_CLOCK_GPIO0_IN, ETH_PHY_LAN8720));
BoardConfig TRACKERD ("TRACKERD", eTRACKERD, OledPins( 5, 4), LoraPins(18, 19, 23, 16, 14, 26, eSX1278));
BoardConfig HELTEC_WIFI_LORA_32_V1 ("HELTEC_WIFI_LORA_32_V1", eHELTEC_WIFI_LORA_32_V1, OledPins( 4, 15, 16), LoraPins( 5, 19, 27, 18, 14, 26, eSX1278));
BoardConfig HELTEC_WIFI_LORA_32_V2 ("HELTEC_WIFI_LORA_32_V2", eHELTEC_WIFI_LORA_32_V2, OledPins( 4, 15, 16), LoraPins( 5, 19, 27, 18, 14, 26, eSX1278));
BoardConfig HELTEC_WIFI_LORA_32_V3 ("HELTEC_WIFI_LORA_32_V3", eHELTEC_WIFI_LORA_32_V3, OledPins(17, 18, 21), LoraPins( 9, 11, 10, 8, 12, 14, eSX1268));
BoardConfig GUALTHERIUS_LORAHAM_v100("GUALTHERIUS_LORAHAM_v100", eGUALTHERIUS_LORAHAM_v100, OledPins(17, 16), LoraPins(18, 19, 23, 5, 13, 35, eSX1278));
BoardConfig GUALTHERIUS_LORAHAM_v106("GUALTHERIUS_LORAHAM_v106", eGUALTHERIUS_LORAHAM_v106, OledPins(17, 16), LoraPins(18, 19, 23, 2, 13, 35, eSX1278));
// clang-format on
22 changes: 14 additions & 8 deletions lib/BoardFinder/BoardFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ class OledPins {
int8_t Addr;
};

enum LoraModem {
eSX1278,
eSX1268,
};

class LoraPins {
public:
explicit LoraPins(int8_t sck, int8_t miso, int8_t mosi, int8_t cs, int8_t reset, int8_t irq);

int8_t Sck;
int8_t Miso;
int8_t Mosi;
int8_t CS;
int8_t Reset;
int8_t IRQ;
explicit LoraPins(int8_t sck, int8_t miso, int8_t mosi, int8_t cs, int8_t reset, int8_t irq, LoraModem modem);

int8_t Sck;
int8_t Miso;
int8_t Mosi;
int8_t CS;
int8_t Reset;
int8_t IRQ;
LoraModem Modem;
};

class GpsPins {
Expand Down
133 changes: 133 additions & 0 deletions src/LoRaModem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#include "LoRaModem.h"

// SX1278
Modem_SX1278::Modem_SX1278() : _radio(0) {
}

int16_t Modem_SX1278::begin(const LoraPins &lora_pins, const Configuration::LoRa &lora_config, const uint16_t preambleLength, void (*setFlag)()) {
float _frequencyRx = (float)lora_config.frequencyRx / 1000000;
float BWkHz = (float)lora_config.signalBandwidth / 1000;

SPI.begin(lora_pins.Sck, lora_pins.Miso, lora_pins.Mosi, lora_pins.CS);
_module = new Module(lora_pins.CS, lora_pins.IRQ, lora_pins.Reset);

_radio = new SX1278(_module);
int16_t state = _radio->begin(_frequencyRx, BWkHz, lora_config.spreadingFactor, lora_config.codingRate4, RADIOLIB_SX127X_SYNC_WORD, lora_config.power, preambleLength, lora_config.gainRx);
if (state != RADIOLIB_ERR_NONE) {
return state;
}

state = _radio->setCRC(true);
if (state != RADIOLIB_ERR_NONE) {
return state;
}

_radio->setDio0Action(setFlag, RISING);

if (lora_config.tx_enable && lora_config.power > 17) {
_radio->setCurrentLimit(140);
}
return RADIOLIB_ERR_NONE;
}

int16_t Modem_SX1278::readData(String &str) {
return _radio->readData(str);
}

int16_t Modem_SX1278::setFrequency(float freq) {
return _radio->setFrequency(freq);
}

int16_t Modem_SX1278::startReceive() {
return _radio->startReceive();
}

int16_t Modem_SX1278::startTransmit(String &str) {
return _radio->startTransmit(str);
}

int16_t Modem_SX1278::receive(String &str) {
return _radio->receive(str);
}

float Modem_SX1278::getRSSI() {
return _radio->getRSSI();
}

float Modem_SX1278::getSNR() {
return _radio->getSNR();
}

float Modem_SX1278::getFrequencyError() {
return _radio->getFrequencyError();
}

uint8_t Modem_SX1278::getModemStatus() {
return _radio->getModemStatus();
}

// SX1262
Modem_SX1268::Modem_SX1268() : _radio(0) {
}

int16_t Modem_SX1268::begin(const LoraPins &lora_pins, const Configuration::LoRa &lora_config, const uint16_t preambleLength, void (*setFlag)()) {
float _frequencyRx = (float)lora_config.frequencyRx / 1000000;
float BWkHz = (float)lora_config.signalBandwidth / 1000;

SPI.begin(lora_pins.Sck, lora_pins.Miso, lora_pins.Mosi, lora_pins.CS);
_module = new Module(lora_pins.CS, lora_pins.IRQ, lora_pins.Reset, 13);

_radio = new SX1262(_module);
int16_t state = _radio->begin(_frequencyRx, BWkHz, lora_config.spreadingFactor, lora_config.codingRate4, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, lora_config.power, preambleLength);
if (state != RADIOLIB_ERR_NONE) {
return state;
}

state = _radio->setCRC(true);
if (state != RADIOLIB_ERR_NONE) {
return state;
}

_radio->setDio1Action(setFlag);

if (lora_config.tx_enable && lora_config.power > 17) {
_radio->setCurrentLimit(140);
}
return RADIOLIB_ERR_NONE;
}

int16_t Modem_SX1268::readData(String &str) {
return _radio->readData(str);
}

int16_t Modem_SX1268::setFrequency(float freq) {
return _radio->setFrequency(freq);
}

int16_t Modem_SX1268::startReceive() {
return _radio->startReceive();
}

int16_t Modem_SX1268::startTransmit(String &str) {
return _radio->startTransmit(str);
}

int16_t Modem_SX1268::receive(String &str) {
return _radio->receive(str);
}

float Modem_SX1268::getRSSI() {
return _radio->getRSSI();
}

float Modem_SX1268::getSNR() {
return _radio->getSNR();
}

float Modem_SX1268::getFrequencyError() {
return _radio->getFrequencyError();
}

uint8_t Modem_SX1268::getModemStatus() {
return 0;
}
82 changes: 82 additions & 0 deletions src/LoRaModem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef LORA_MODEM_H_
#define LORA_MODEM_H_

#include <RadioLib.h>

#include "BoardFinder.h"
#include "project_configuration.h"

class LoRaModem {
public:
LoRaModem() : _module(0) {
}

virtual ~LoRaModem() {
}

virtual int16_t begin(const LoraPins &lora_pins, const Configuration::LoRa &lora_config, const uint16_t preambleLength, void (*setFlag)()) = 0;

virtual int16_t readData(String &str) = 0;

virtual int16_t setFrequency(float freq) = 0;
virtual int16_t startReceive() = 0;
virtual int16_t startTransmit(String &str) = 0;

virtual int16_t receive(String &str) = 0;

virtual float getRSSI() = 0;
virtual float getSNR() = 0;
virtual float getFrequencyError() = 0;
virtual uint8_t getModemStatus() = 0;

protected:
Module *_module;
};

class Modem_SX1278 : public LoRaModem {
public:
Modem_SX1278();

int16_t begin(const LoraPins &lora_pins, const Configuration::LoRa &lora_config, const uint16_t preambleLength, void (*setFlag)()) override;

int16_t readData(String &str) override;

int16_t setFrequency(float freq) override;
int16_t startReceive() override;
int16_t startTransmit(String &str) override;

int16_t receive(String &str) override;

float getRSSI() override;
float getSNR() override;
float getFrequencyError() override;
uint8_t getModemStatus() override;

private:
SX1278 *_radio;
};

class Modem_SX1268 : public LoRaModem {
public:
Modem_SX1268();

int16_t begin(const LoraPins &lora_pins, const Configuration::LoRa &lora_config, const uint16_t preambleLength, void (*setFlag)()) override;

int16_t readData(String &str) override;

int16_t setFrequency(float freq) override;
int16_t startReceive() override;
int16_t startTransmit(String &str) override;

int16_t receive(String &str) override;

float getRSSI() override;
float getSNR() override;
float getFrequencyError() override;
uint8_t getModemStatus() override;

private:
SX1262 *_radio;
};

#endif
10 changes: 5 additions & 5 deletions src/LoRa_APRS_iGate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ void setup() {
std::list<BoardConfig const *> boardConfigs;
boardConfigs.push_back(&TTGO_LORA32_V1);
boardConfigs.push_back(&TTGO_LORA32_V2);
boardConfigs.push_back(&TTGO_T_Beam_V0_7);
boardConfigs.push_back(&TTGO_T_Beam_V1_0);
boardConfigs.push_back(&LILYGO_POE_ETH_BOARD);
boardConfigs.push_back(&WT32_ETH_BOARD);
boardConfigs.push_back(&TRACKERD);
boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V1);
boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V2);
boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V3);
boardConfigs.push_back(&LILYGO_POE_ETH_BOARD);
boardConfigs.push_back(&WT32_ETH_BOARD);
boardConfigs.push_back(&TRACKERD);
boardConfigs.push_back(&GUALTHERIUS_LORAHAM_v100);
boardConfigs.push_back(&GUALTHERIUS_LORAHAM_v106);
boardConfigs.push_back(&TTGO_T_Beam_V0_7);
boardConfigs.push_back(&TTGO_T_Beam_V1_0);

ProjectConfigurationManagement confmg(LoRaSystem.getLogger());
confmg.readConfiguration(LoRaSystem.getLogger(), userConfig);
Expand Down
Loading