From e4f53677fca9ad718706a471b4926e24b7dba2cc Mon Sep 17 00:00:00 2001 From: Mark Trevor Birss Date: Wed, 4 Dec 2024 13:39:02 +0200 Subject: [PATCH] [Add] LR1110, LR1120 and LR1121 to linux native Portduino (#5496) * Update main.cpp * Update PortduinoGlue.h * Update PortduinoGlue.cpp * Update PortduinoGlue.cpp * Update PortduinoGlue.cpp * Update main.cpp --- src/main.cpp | 47 +++++++++++++++++++++++- src/platform/portduino/PortduinoGlue.cpp | 11 +++++- src/platform/portduino/PortduinoGlue.h | 5 ++- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 33eaa131e4..53a6622722 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -858,6 +858,51 @@ void setup() LOG_INFO("SX1280 init success"); } } + } else if (settingsMap[use_lr1110]) { + if (!rIf) { + LOG_DEBUG("Activate lr1110 radio on SPI port %s", settingsStrings[spidev].c_str()); + LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); + rIf = new LR1110Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], + settingsMap[busy]); + if (!rIf->init()) { + LOG_WARN("No LR1110 radio"); + delete rIf; + rIf = NULL; + exit(EXIT_FAILURE); + } else { + LOG_INFO("LR1110 init success"); + } + } + } else if (settingsMap[use_lr1120]) { + if (!rIf) { + LOG_DEBUG("Activate lr1120 radio on SPI port %s", settingsStrings[spidev].c_str()); + LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); + rIf = new LR1120Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], + settingsMap[busy]); + if (!rIf->init()) { + LOG_WARN("No LR1120 radio"); + delete rIf; + rIf = NULL; + exit(EXIT_FAILURE); + } else { + LOG_INFO("LR1120 init success"); + } + } + } else if (settingsMap[use_lr1121]) { + if (!rIf) { + LOG_DEBUG("Activate lr1121 radio on SPI port %s", settingsStrings[spidev].c_str()); + LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); + rIf = new LR1121Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], + settingsMap[busy]); + if (!rIf->init()) { + LOG_WARN("No LR1121 radio"); + delete rIf; + rIf = NULL; + exit(EXIT_FAILURE); + } else { + LOG_INFO("LR1121 init success"); + } + } } else if (settingsMap[use_sx1268]) { if (!rIf) { LOG_DEBUG("Activate sx1268 radio on SPI port %s", settingsStrings[spidev].c_str()); @@ -1218,4 +1263,4 @@ void loop() mainDelay.delay(delayMsec); } } -#endif \ No newline at end of file +#endif diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index d53a5be94a..a4485e91ff 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -272,6 +272,9 @@ bool loadConfig(const char *configPath) settingsMap[use_sx1262] = false; settingsMap[use_rf95] = false; settingsMap[use_sx1280] = false; + settingsMap[use_lr1110] = false; + settingsMap[use_lr1120] = false; + settingsMap[use_lr1121] = false; settingsMap[use_sx1268] = false; if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "sx1262") { @@ -280,6 +283,12 @@ bool loadConfig(const char *configPath) settingsMap[use_rf95] = true; } else if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "sx1280") { settingsMap[use_sx1280] = true; + } else if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "lr1110") { + settingsMap[use_lr1110] = true; + } else if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "lr1120") { + settingsMap[use_lr1120] = true; + } else if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "lr1121") { + settingsMap[use_lr1121] = true; } else if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "sx1268") { settingsMap[use_sx1268] = true; } @@ -415,4 +424,4 @@ bool loadConfig(const char *configPath) static bool ends_with(std::string_view str, std::string_view suffix) { return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; -} \ No newline at end of file +} diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index 95d82c1a21..1e0223c486 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -16,6 +16,9 @@ enum configNames { ch341Quirk, use_rf95, use_sx1280, + use_lr1110, + use_lr1120, + use_lr1121, use_sx1268, user, gpiochip, @@ -67,4 +70,4 @@ extern std::map settingsStrings; extern std::ofstream traceFile; int initGPIOPin(int pinNum, std::string gpioChipname); bool loadConfig(const char *configPath); -static bool ends_with(std::string_view str, std::string_view suffix); \ No newline at end of file +static bool ends_with(std::string_view str, std::string_view suffix);