From 9d4af1146e8273645693405f83a88cc9574de697 Mon Sep 17 00:00:00 2001 From: Ric In New Mexico <78682404+RicInNewMexico@users.noreply.github.com> Date: Fri, 17 Nov 2023 05:46:59 -0700 Subject: [PATCH 01/52] INA3221 bugfixes & refinement (#2944) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reorganized and refactored some INA3221 code Added comments Added missing shunt resistor value (100mΩ) Added INA3221 Channel 1 to getINAVoltage() for device battery monitoring modified: src/Power.cpp modified: src/modules/Telemetry/PowerTelemetry.cpp modified: src/modules/Telemetry/Sensor/INA3221Sensor.cpp modified: src/modules/Telemetry/Sensor/INA3221Sensor.h modified: src/power.h --- src/Power.cpp | 4 ++++ src/modules/Telemetry/PowerTelemetry.cpp | 5 ----- src/modules/Telemetry/Sensor/INA3221Sensor.cpp | 3 ++- src/modules/Telemetry/Sensor/INA3221Sensor.h | 15 +++++++++------ src/power.h | 2 ++ 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index 72bb38181..c7392c90b 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -52,6 +52,7 @@ static const adc_atten_t atten = ADC_ATTENUATION; #if HAS_TELEMETRY && !defined(ARCH_PORTDUINO) INA260Sensor ina260Sensor; INA219Sensor ina219Sensor; +INA3221Sensor ina3221Sensor; #endif #ifdef HAS_PMU @@ -286,6 +287,9 @@ class AnalogBatteryLevel : public HasBatteryLevel } else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first == config.power.device_battery_ina_address) { return ina260Sensor.getBusVoltageMv(); + } else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first == + config.power.device_battery_ina_address) { + return ina3221Sensor.getBusVoltageMv(); } return 0; } diff --git a/src/modules/Telemetry/PowerTelemetry.cpp b/src/modules/Telemetry/PowerTelemetry.cpp index 53e26ee6a..032d7fc27 100644 --- a/src/modules/Telemetry/PowerTelemetry.cpp +++ b/src/modules/Telemetry/PowerTelemetry.cpp @@ -11,11 +11,6 @@ #include "sleep.h" #include "target_specific.h" -#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO) -#include "Sensor/INA3221Sensor.h" -INA3221Sensor ina3221Sensor; -#endif - #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true diff --git a/src/modules/Telemetry/Sensor/INA3221Sensor.cpp b/src/modules/Telemetry/Sensor/INA3221Sensor.cpp index 634f5a5c9..3269ba47a 100644 --- a/src/modules/Telemetry/Sensor/INA3221Sensor.cpp +++ b/src/modules/Telemetry/Sensor/INA3221Sensor.cpp @@ -13,8 +13,9 @@ int32_t INA3221Sensor::runOnce() return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } if (!status) { - ina3221.setAddr(INA3221_ADDR42_SDA); + ina3221.setAddr(INA3221_ADDR42_SDA); // i2c address 0x42 ina3221.begin(); + ina3221.setShuntRes(100, 100, 100); // 0.1 Ohm shunt resistors status = true; } else { status = true; diff --git a/src/modules/Telemetry/Sensor/INA3221Sensor.h b/src/modules/Telemetry/Sensor/INA3221Sensor.h index a1c0fb2a7..4c82fc34d 100644 --- a/src/modules/Telemetry/Sensor/INA3221Sensor.h +++ b/src/modules/Telemetry/Sensor/INA3221Sensor.h @@ -1,16 +1,19 @@ #include "../mesh/generated/meshtastic/telemetry.pb.h" #include "TelemetrySensor.h" +#include "VoltageSensor.h" #include -class INA3221Sensor : public TelemetrySensor +class INA3221Sensor : public TelemetrySensor, VoltageSensor { + private: + INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA); + + protected: + void setup() override; + public: INA3221Sensor(); int32_t runOnce() override; - void setup() override; bool getMetrics(meshtastic_Telemetry *measurement) override; - virtual uint16_t getBusVoltageMv(); - - private: - INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA); + virtual uint16_t getBusVoltageMv() override; }; \ No newline at end of file diff --git a/src/power.h b/src/power.h index e90e3f21b..54d98e715 100644 --- a/src/power.h +++ b/src/power.h @@ -25,8 +25,10 @@ extern RTC_NOINIT_ATTR uint64_t RTC_reg_b; #if HAS_TELEMETRY && !defined(ARCH_PORTDUINO) #include "modules/Telemetry/Sensor/INA219Sensor.h" #include "modules/Telemetry/Sensor/INA260Sensor.h" +#include "modules/Telemetry/Sensor/INA3221Sensor.h" extern INA260Sensor ina260Sensor; extern INA219Sensor ina219Sensor; +extern INA3221Sensor ina3221Sensor; #endif class Power : private concurrency::OSThread From 46bd6ca7ba7c322a2d9fe2549296dfb39ee5a55a Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 18 Nov 2023 08:12:34 -0600 Subject: [PATCH 02/52] YAML based config for PI / Portduino (#2943) * Add configuration via /etc/meshtastic/config.yaml * Move example config, support more locations * Fix config check * Use access() to check for config file presence * Throw an error and exit on radio init fail * Adds error check for reading Bluetooth MAC * Settle on meshtasticd, add install script * Shell fixes * Fine. I'll put it back and then disable you * Get wrekt, shellchekt * Firat attempt at adding raspbian CI build * Tickle the workflow * Beatings will continue til morale improves * Permissions are overrated --------- Co-authored-by: Jonathan Bennett --- .github/workflows/build_raspbian.yml | 30 +++++++++++++ .trunk/configs/.shellcheckrc | 3 ++ bin/build-native.sh | 16 ++++--- bin/config-dist.yaml | 26 +++++++++++ bin/meshtasticd.service | 9 ++++ bin/native-install.sh | 10 +++++ src/configuration.h | 6 +-- src/gps/GPS.cpp | 3 ++ src/main.cpp | 36 +++++++++++---- src/mesh/SX126xInterface.cpp | 11 ++++- src/platform/portduino/PortduinoGlue.cpp | 56 ++++++++++++++++++++++-- src/platform/portduino/PortduinoGlue.h | 21 +++++++++ variants/portduino/platformio.ini | 2 +- variants/portduino/variant.h | 28 ------------ 14 files changed, 206 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/build_raspbian.yml create mode 100644 bin/config-dist.yaml create mode 100644 bin/meshtasticd.service create mode 100755 bin/native-install.sh create mode 100644 src/platform/portduino/PortduinoGlue.h diff --git a/.github/workflows/build_raspbian.yml b/.github/workflows/build_raspbian.yml new file mode 100644 index 000000000..1860e9098 --- /dev/null +++ b/.github/workflows/build_raspbian.yml @@ -0,0 +1,30 @@ +name: Build Raspbian + +on: workflow_call + +permissions: + contents: write + packages: write + +jobs: + build-raspbian: + runs-on: [self-hosted, linux, ARM64] + steps: + - uses: actions/checkout@v3 + - name: Build base + id: base + uses: ./.github/actions/setup-base + + - name: Build Raspbian + run: bin/build-native.sh + + - name: Get release version string + run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT + id: version + + - name: Store binaries as an artifact + uses: actions/upload-artifact@v3 + with: + name: firmware-native-${{ steps.version.outputs.version }}.zip + path: | + release/meshtasticd_linux_arm64 diff --git a/.trunk/configs/.shellcheckrc b/.trunk/configs/.shellcheckrc index 8c7b1ada8..b2e8a14cc 100644 --- a/.trunk/configs/.shellcheckrc +++ b/.trunk/configs/.shellcheckrc @@ -1,7 +1,10 @@ enable=all source-path=SCRIPTDIR disable=SC2154 +disable=SC2248 +disable=SC2250 # If you're having issues with shellcheck following source, disable the errors via: # disable=SC1090 # disable=SC1091 +# \ No newline at end of file diff --git a/bin/build-native.sh b/bin/build-native.sh index 8bc262860..64c5adb50 100755 --- a/bin/build-native.sh +++ b/bin/build-native.sh @@ -2,8 +2,8 @@ set -e -VERSION=`bin/buildinfo.py long` -SHORT_VERSION=`bin/buildinfo.py short` +VERSION=$(bin/buildinfo.py long) +SHORT_VERSION=$(bin/buildinfo.py short) OUTDIR=release/ @@ -13,11 +13,15 @@ mkdir -p $OUTDIR/ rm -r $OUTDIR/* || true # Important to pull latest version of libs into all device flavors, otherwise some devices might be stale -platformio pkg update +platformio pkg update -pio run --environment native -cp .pio/build/native/program $OUTDIR/meshtasticd_linux_amd64 +if command -v raspi-config &>/dev/null; then + pio run --environment raspbian + cp .pio/build/raspbian/program $OUTDIR/meshtasticd_linux_arm64 +else + pio run --environment native + cp .pio/build/native/program $OUTDIR/meshtasticd_linux_amd64 +fi cp bin/device-install.* $OUTDIR cp bin/device-update.* $OUTDIR - diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml new file mode 100644 index 000000000..2a3abac6f --- /dev/null +++ b/bin/config-dist.yaml @@ -0,0 +1,26 @@ +# Define your devices here. +# Use Broadcom pin numbering + +#Waveshare SX126X XXXM + +#USE_SX1262: true +#SX126X_DIO2_AS_RF_SWITCH: true +#SX126X_CS: 21 +#SX126X_DIO1: 16 +#SX126X_BUSY: 20 +#SX126X_RESET: 18 + +#Waveshare SX1302 LISTEN ONLY AT THIS TIME! + +#USE_SX1262: true +#SX126X_CS: 7 +#SX126X_DIO1: 17 +#SX126X_RESET: 22 + +#Adafruit RFM9x + +#USE_RF95: true +#RF95_RESET: 25 +#RF95_NSS: 7 +#RF95_IRQ: 22 +#RF95_DIO1: 23 diff --git a/bin/meshtasticd.service b/bin/meshtasticd.service new file mode 100644 index 000000000..4ed1bfd8f --- /dev/null +++ b/bin/meshtasticd.service @@ -0,0 +1,9 @@ +[unit] +description=Meshtastic Native Daemon + +[Service] +Type=simple +ExecStart=/usr/sbin/meshtasticd + +[Install] +WantedBy=multi-user.target diff --git a/bin/native-install.sh b/bin/native-install.sh new file mode 100755 index 000000000..d1d0c8707 --- /dev/null +++ b/bin/native-install.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +cp release/meshtasticd_linux_arm64 /usr/sbin/meshtasticd +mkdir /etc/meshtasticd +if [[ -f "/etc/meshtasticd/config.yaml" ]]; then + cp bin/config-dist.yaml /etc/meshtasticd/config-upgrade.yaml +else + cp bin/config-dist.yaml /etc/meshtasticd/config.yaml +fi +cp bin/meshtasticd.service /usr/lib/systemd/system/meshtasticd.service diff --git a/src/configuration.h b/src/configuration.h index 199880c6b..cb7ee218b 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -57,8 +57,8 @@ along with this program. If not, see . #define REQUIRE_RADIO true // If true, we will fail to start if the radio is not found /// Convert a preprocessor name into a quoted string -#define xstr(s) str(s) -#define str(s) #s +#define xstr(s) ystr(s) +#define ystr(s) #s /// Convert a preprocessor name into a quoted string and if that string is empty use "unset" #define optstr(s) (xstr(s)[0] ? xstr(s) : "unset") @@ -209,4 +209,4 @@ along with this program. If not, see . #ifndef HW_VENDOR #error HW_VENDOR must be defined -#endif +#endif \ No newline at end of file diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 47ba067d2..af622e3d8 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -17,6 +17,9 @@ #if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(ARCH_ESP32) HardwareSerial *GPS::_serial_gps = &Serial1; +#elif defined(ARCH_RASPBERRY_PI) +// need a translation layer to make _serial_gps work with pigpio https://abyz.me.uk/rpi/pigpio/cif.html#serOpen +HardwareSerial *GPS::_serial_gps = NULL; #else HardwareSerial *GPS::_serial_gps = NULL; #endif diff --git a/src/main.cpp b/src/main.cpp index d5b3895d2..5c3151fc0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,6 +69,7 @@ NRF52Bluetooth *nrf52Bluetooth; #ifdef ARCH_RASPBERRY_PI #include "platform/portduino/PiHal.h" +#include "platform/portduino/PortduinoGlue.h" #include #include #include @@ -690,15 +691,32 @@ void setup() #endif #ifdef ARCH_RASPBERRY_PI - PiHal *RadioLibHAL = new PiHal(1); - if (!rIf) { - rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, 21, 16, 18, 20); - if (!rIf->init()) { - LOG_WARN("Failed to find SX1262 radio\n"); - delete rIf; - rIf = NULL; - } else { - LOG_INFO("SX1262 Radio init succeeded, using SX1262 radio\n"); + if (settingsMap[use_sx1262]) { + if (!rIf) { + PiHal *RadioLibHAL = new PiHal(1); + rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[sx126x_cs], settingsMap[sx126x_dio1], + settingsMap[sx126x_reset], settingsMap[sx126x_busy]); + if (!rIf->init()) { + LOG_ERROR("Failed to find SX1262 radio\n"); + delete rIf; + exit(EXIT_FAILURE); + } else { + LOG_INFO("SX1262 Radio init succeeded, using SX1262 radio\n"); + } + } + } else if (settingsMap[use_rf95]) { + if (!rIf) { + PiHal *RadioLibHAL = new PiHal(1); + rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[rf95_nss], settingsMap[rf95_irq], + settingsMap[rf95_reset], settingsMap[rf95_dio1]); + if (!rIf->init()) { + LOG_ERROR("Failed to find RF95 radio\n"); + delete rIf; + rIf = NULL; + exit(EXIT_FAILURE); + } else { + LOG_INFO("RF95 Radio init succeeded, using RF95 radio\n"); + } } } diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index 980107917..ba3f2bc2a 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -2,6 +2,9 @@ #include "configuration.h" #include "error.h" #include "mesh/NodeDB.h" +#ifdef ARCH_RASPBERRY_PI +#include "PortduinoGlue.h" +#endif // Particular boards might define a different max power based on what their hardware can do, default to max power output if not // specified (may be dangerous if using external PA and SX126x power config forgotten) @@ -74,6 +77,12 @@ template bool SX126xInterface::init() #ifdef SX126X_DIO2_AS_RF_SWITCH LOG_DEBUG("Setting DIO2 as RF switch\n"); bool dio2AsRfSwitch = true; +#elif defined(ARCH_RASPBERRY_PI) + bool dio2AsRfSwitch = false; + if (settingsMap[sx126x_dio2_as_rf_switch]) { + LOG_DEBUG("Setting DIO2 as RF switch\n"); + dio2AsRfSwitch = true; + } #else LOG_DEBUG("Setting DIO2 as not RF switch\n"); bool dio2AsRfSwitch = false; @@ -318,4 +327,4 @@ template bool SX126xInterface::sleep() #endif return true; -} +} \ No newline at end of file diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index fb71a429b..b3c2dc5f2 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -9,7 +9,14 @@ #include #ifdef ARCH_RASPBERRY_PI +#include "PortduinoGlue.h" #include "pigpio.h" +#include "yaml-cpp/yaml.h" +#include +#include +#include + +std::map settingsMap; #else #include @@ -27,7 +34,7 @@ void cpuDeepSleep(uint32_t msecs) } void updateBatteryLevel(uint8_t level) NOT_IMPLEMENTED("updateBatteryLevel"); - +#ifndef ARCH_RASPBERRY_PI /** a simulated pin for busted IRQ hardware * Porduino helper class to do this i2c based polling: */ @@ -54,7 +61,7 @@ class PolledIrqPin : public GPIOPin }; static GPIOPin *loraIrq; - +#endif int TCPPort = 4403; static error_t parse_opt(int key, char *arg, struct argp_state *state) @@ -94,6 +101,48 @@ void portduinoSetup() printf("Setting up Meshtastic on Portduino...\n"); #ifdef ARCH_RASPBERRY_PI + YAML::Node yamlConfig; + + if (access("config.yaml", R_OK) == 0) { + try { + yamlConfig = YAML::LoadFile("config.yaml"); + } catch (YAML::Exception e) { + std::cout << "*** Exception " << e.what() << std::endl; + exit(EXIT_FAILURE); + } + } else if (access("/etc/meshtasticd/config.yaml", R_OK) == 0) { + try { + yamlConfig = YAML::LoadFile("/etc/meshtasticd/config.yaml"); + } catch (YAML::Exception e) { + std::cout << "*** Exception " << e.what() << std::endl; + exit(EXIT_FAILURE); + } + } else { + std::cout << "No 'config.yaml' found, exiting." << std::endl; + exit(EXIT_FAILURE); + } + + try { + settingsMap[use_sx1262] = yamlConfig["USE_SX1262"].as(false); + settingsMap[sx126x_dio2_as_rf_switch] = yamlConfig["SX126X_DIO2_AS_RF_SWITCH"].as(false); + settingsMap[sx126x_cs] = yamlConfig["SX126X_CS"].as(RADIOLIB_NC); + settingsMap[sx126x_dio1] = yamlConfig["SX126X_DIO1"].as(RADIOLIB_NC); + settingsMap[sx126x_busy] = yamlConfig["SX126X_BUSY"].as(RADIOLIB_NC); + settingsMap[sx126x_reset] = yamlConfig["SX126X_RESET"].as(RADIOLIB_NC); + settingsMap[use_rf95] = yamlConfig["USE_RF95"].as(false); + settingsMap[rf95_nss] = yamlConfig["RF95_NSS"].as(RADIOLIB_NC); + settingsMap[rf95_irq] = yamlConfig["RF95_IRQ"].as(RADIOLIB_NC); + settingsMap[rf95_reset] = yamlConfig["RF95_RESET"].as(RADIOLIB_NC); + settingsMap[rf95_dio1] = yamlConfig["RF95_DIO1"].as(RADIOLIB_NC); + + } catch (YAML::Exception e) { + std::cout << "*** Exception " << e.what() << std::endl; + exit(EXIT_FAILURE); + } + if (access("/sys/kernel/debug/bluetooth/hci0/identity", R_OK) != 0) { + std::cout << "Cannot read Bluetooth MAC Address. Please run as root" << std::endl; + exit(EXIT_FAILURE); + } return; #endif @@ -121,7 +170,7 @@ void portduinoSetup() gpioBind(loraCs); } else #endif - +#ifndef ARCH_RASPBERRY_PI { // Set the random seed equal to TCPPort to have a different seed per instance randomSeed(TCPPort); @@ -140,4 +189,5 @@ void portduinoSetup() } // gpioBind((new SimGPIOPin(LORA_RESET, "LORA_RESET"))); // gpioBind((new SimGPIOPin(RF95_NSS, "RF95_NSS"))->setSilent()); +#endif } \ No newline at end of file diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h new file mode 100644 index 000000000..91fc4c2b1 --- /dev/null +++ b/src/platform/portduino/PortduinoGlue.h @@ -0,0 +1,21 @@ +#pragma once +#ifdef ARCH_RASPBERRY_PI +#include + +extern std::map settingsMap; + +enum { + use_sx1262, + sx126x_cs, + sx126x_dio1, + sx126x_busy, + sx126x_reset, + sx126x_dio2_as_rf_switch, + use_rf95, + rf95_nss, + rf95_irq, + rf95_reset, + rf95_dio1 +}; + +#endif \ No newline at end of file diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index 323609d0e..be07bcb15 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -16,7 +16,7 @@ build_src_filter = ${portduino_base.build_src_filter} ; The Raspberry Pi actually has accessible SPI and GPIO, so we can support real hardware there. [env:raspbian] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino -DARCH_RASPBERRY_PI -DRADIOLIB_DEBUG -lpigpio +build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino -DARCH_RASPBERRY_PI -DRADIOLIB_DEBUG -lpigpio -lyaml-cpp board = linux_arm lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} \ No newline at end of file diff --git a/variants/portduino/variant.h b/variants/portduino/variant.h index 2ce871ddc..46f7d1f0c 100644 --- a/variants/portduino/variant.h +++ b/variants/portduino/variant.h @@ -1,34 +1,6 @@ #if defined(ARCH_RASPBERRY_PI) -#define HAS_RADIO 1 -#define GPIOD_CHIP_LABEL "pinctrl-bcm2711" - -// define USE_RF95 -#define USE_SX1262 -#define SX126X_TXEN 6 -#define SX126X_DIO2_AS_RF_SWITCH #define NO_SCREEN -#define RF95_SCK 11 -#define RF95_MISO 9 -#define RF95_MOSI 10 -#define RF95_NSS RADIOLIB_NC - -// #define LORA_DIO0 4 // a No connect on the SX1262 module -// #define LORA_DIO0_LABEL "GPIO_GCLK" -#define LORA_RESET 18 -#define LORA_RESET_LABEL "GPIO18" -#define LORA_DIO1 16 // SX1262 IRQ, called DIO0 on pinelora schematic, pin 7 on ch341f "ack" - FIXME, enable hwints in linux -// #define LORA_DIO2 20 // SX1262 BUSY, actually connected to "DIO5" on pinelora schematic, pin 8 on ch341f "slct" -// #define LORA_DIO3 6 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled - -#ifdef USE_SX1262 -#define SX126X_CS 21 -#define SX126X_DIO1 16 -#define SX126X_BUSY 20 -#define SX126X_RESET LORA_RESET -// HOPE RFM90 does not have a TCXO therefore not SX126X_E22 -#endif - #else // Pine64 mode. // Pine64 uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if From dc8903ec4212b901da3bdab9e41b38091531c635 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 08:55:19 -0600 Subject: [PATCH 03/52] Add Raspbian to Main CI (#2948) --- .github/workflows/main_matrix.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 145a75c2d..bd024b0af 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -129,6 +129,12 @@ jobs: with: board: ${{ matrix.board }} + build-raspbian: + strategy: + fail-fast: false + max-parallel: 1 + uses: ./.github/workflows/build_raspbian.yml + build-native: runs-on: ubuntu-latest steps: From b6ddbd0087dce616ed53b9088b0e09970a9c045e Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 11:04:21 -0600 Subject: [PATCH 04/52] More CI work for Raspbian (#2949) * More CI work for Raspbian * Workaround quirks of Arm64/debian runners --- .github/workflows/build_raspbian.yml | 24 +++++++++++++++++++----- .github/workflows/main_matrix.yml | 10 ++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build_raspbian.yml b/.github/workflows/build_raspbian.yml index 1860e9098..78122cb35 100644 --- a/.github/workflows/build_raspbian.yml +++ b/.github/workflows/build_raspbian.yml @@ -10,10 +10,24 @@ jobs: build-raspbian: runs-on: [self-hosted, linux, ARM64] steps: - - uses: actions/checkout@v3 - - name: Build base - id: base - uses: ./.github/actions/setup-base + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: recursive + ref: ${{github.event.pull_request.head.ref}} + repository: ${{github.event.pull_request.head.repo.full_name}} + + - name: Upgrade python tools + shell: bash + run: | + python -m pip install --upgrade pip + pip install -U platformio adafruit-nrfutil + pip install -U meshtastic --pre + + - name: Upgrade platformio + shell: bash + run: | + pio upgrade - name: Build Raspbian run: bin/build-native.sh @@ -25,6 +39,6 @@ jobs: - name: Store binaries as an artifact uses: actions/upload-artifact@v3 with: - name: firmware-native-${{ steps.version.outputs.version }}.zip + name: firmware-raspbian-${{ steps.version.outputs.version }}.zip path: | release/meshtasticd_linux_arm64 diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index bd024b0af..259306f0c 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -103,7 +103,6 @@ jobs: build-nrf52: strategy: fail-fast: false - max-parallel: 2 matrix: include: - board: rak4631 @@ -210,7 +209,14 @@ jobs: gather-artifacts: runs-on: ubuntu-latest needs: - [build-esp32, build-esp32-s3, build-nrf52, build-native, build-rpi2040] + [ + build-esp32, + build-esp32-s3, + build-nrf52, + build-raspbian, + build-native, + build-rpi2040, + ] steps: - name: Checkout code uses: actions/checkout@v3 From 7bd2b0702404dcb5194f933fe2873035c6747890 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 11:26:07 -0600 Subject: [PATCH 05/52] Disable radiolib debug --- variants/portduino/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index be07bcb15..5e9428d4e 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -16,7 +16,7 @@ build_src_filter = ${portduino_base.build_src_filter} ; The Raspberry Pi actually has accessible SPI and GPIO, so we can support real hardware there. [env:raspbian] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino -DARCH_RASPBERRY_PI -DRADIOLIB_DEBUG -lpigpio -lyaml-cpp +build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino -DARCH_RASPBERRY_PI -lpigpio -lyaml-cpp board = linux_arm lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} \ No newline at end of file From f8e766ebc7b5224569b81e509193580e76c8f2c1 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 11:41:33 -0600 Subject: [PATCH 06/52] Include Raspbian in release zip --- .github/workflows/build_raspbian.yml | 1 + .github/workflows/main_matrix.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_raspbian.yml b/.github/workflows/build_raspbian.yml index 78122cb35..103f43a71 100644 --- a/.github/workflows/build_raspbian.yml +++ b/.github/workflows/build_raspbian.yml @@ -42,3 +42,4 @@ jobs: name: firmware-raspbian-${{ steps.version.outputs.version }}.zip path: | release/meshtasticd_linux_arm64 + bin/config-dist.yaml diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 259306f0c..77459330a 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -233,7 +233,7 @@ jobs: id: version - name: Move files up - run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat + run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./*raspbian*/meshtasticd_linux_arm64 ./*raspbian*/config-dist.yaml - name: Repackage in single firmware zip uses: actions/upload-artifact@v3 From 297267d03769c83b1d6701114f25c30852d1b759 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 13:26:05 -0600 Subject: [PATCH 07/52] Try harder to find Raspbian binary --- .github/workflows/main_matrix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 77459330a..960ff3bdd 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -233,7 +233,7 @@ jobs: id: version - name: Move files up - run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./*raspbian*/meshtasticd_linux_arm64 ./*raspbian*/config-dist.yaml + run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./**/meshtasticd_linux_arm64 ./**/config-dist.yaml - name: Repackage in single firmware zip uses: actions/upload-artifact@v3 From 7ef4abb9749b4097481e134ce82ad30f228e091e Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 14:56:40 -0600 Subject: [PATCH 08/52] Add debugging output to main workflow --- .github/workflows/main_matrix.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 960ff3bdd..ccd198589 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -306,6 +306,9 @@ jobs: name: firmware-${{ steps.version.outputs.version }} path: ./output + - name: Display structure of downloaded files + run: ls -R + - name: Device scripts permissions run: | chmod +x ./output/device-install.sh From 16ef40b21f3c976b5c138859dad7f1a971f3c968 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 15:16:36 -0600 Subject: [PATCH 09/52] Add even moar workflow debugging --- .github/workflows/main_matrix.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index ccd198589..f1f5222ab 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -228,6 +228,9 @@ jobs: with: path: ./ + - name: Display structure of downloaded files + run: ls -R + - name: Get release version string run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT id: version From 08297bb0b72eb5986cfb6129cfefea67274b8123 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 15:36:41 -0600 Subject: [PATCH 10/52] Copy and Paste output file location for workflow --- .github/workflows/main_matrix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index f1f5222ab..960f0d51f 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -236,7 +236,7 @@ jobs: id: version - name: Move files up - run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./**/meshtasticd_linux_arm64 ./**/config-dist.yaml + run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./firmware-raspbian-*/release/meshtasticd_linux_arm64 ./firmware-raspbian-*/bin/config-dist.yaml - name: Repackage in single firmware zip uses: actions/upload-artifact@v3 From 4af90eeb3934f505f466e865b9eadbc9ab857c78 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 14:00:03 -0600 Subject: [PATCH 11/52] Revamp yaml config for Raspbian --- bin/config-dist.yaml | 43 +++++++++++------------- src/main.cpp | 8 ++--- src/mesh/SX126xInterface.cpp | 2 +- src/platform/portduino/PortduinoGlue.cpp | 26 ++++++++------ src/platform/portduino/PortduinoGlue.h | 14 +------- 5 files changed, 40 insertions(+), 53 deletions(-) diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 2a3abac6f..3924335a2 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -1,26 +1,21 @@ -# Define your devices here. -# Use Broadcom pin numbering +# Define your devices here using Broadcom pin numbering +# Uncomment the block that corresponds to your hardware +--- +Lora: +# Module: sx1262 # Waveshare SX126X XXXM +# DIO2_AS_RF_SWITCH: true +# CS: 21 +# IRQ: 16 +# Busy: 20 +# Reset: 18 -#Waveshare SX126X XXXM +# Module: sx1262 # Waveshare SX1302 LISTEN ONLY AT THIS TIME! +# CS: 7 +# IRQ: 17 +# Reset: 22 -#USE_SX1262: true -#SX126X_DIO2_AS_RF_SWITCH: true -#SX126X_CS: 21 -#SX126X_DIO1: 16 -#SX126X_BUSY: 20 -#SX126X_RESET: 18 - -#Waveshare SX1302 LISTEN ONLY AT THIS TIME! - -#USE_SX1262: true -#SX126X_CS: 7 -#SX126X_DIO1: 17 -#SX126X_RESET: 22 - -#Adafruit RFM9x - -#USE_RF95: true -#RF95_RESET: 25 -#RF95_NSS: 7 -#RF95_IRQ: 22 -#RF95_DIO1: 23 +# Module: RF95 # Adafruit RFM9x +# Reset: 25 +# CS: 7 +# IRQ: 22 +# Busy: 23 diff --git a/src/main.cpp b/src/main.cpp index 5c3151fc0..cfd6279e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -694,8 +694,8 @@ void setup() if (settingsMap[use_sx1262]) { if (!rIf) { PiHal *RadioLibHAL = new PiHal(1); - rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[sx126x_cs], settingsMap[sx126x_dio1], - settingsMap[sx126x_reset], settingsMap[sx126x_busy]); + rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], + settingsMap[busy]); if (!rIf->init()) { LOG_ERROR("Failed to find SX1262 radio\n"); delete rIf; @@ -707,8 +707,8 @@ void setup() } else if (settingsMap[use_rf95]) { if (!rIf) { PiHal *RadioLibHAL = new PiHal(1); - rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[rf95_nss], settingsMap[rf95_irq], - settingsMap[rf95_reset], settingsMap[rf95_dio1]); + rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], + settingsMap[busy]); if (!rIf->init()) { LOG_ERROR("Failed to find RF95 radio\n"); delete rIf; diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index ba3f2bc2a..5083eeb53 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -79,7 +79,7 @@ template bool SX126xInterface::init() bool dio2AsRfSwitch = true; #elif defined(ARCH_RASPBERRY_PI) bool dio2AsRfSwitch = false; - if (settingsMap[sx126x_dio2_as_rf_switch]) { + if (settingsMap[dio2_as_rf_switch]) { LOG_DEBUG("Setting DIO2 as RF switch\n"); dio2AsRfSwitch = true; } diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index b3c2dc5f2..2e402c0a0 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -123,17 +123,21 @@ void portduinoSetup() } try { - settingsMap[use_sx1262] = yamlConfig["USE_SX1262"].as(false); - settingsMap[sx126x_dio2_as_rf_switch] = yamlConfig["SX126X_DIO2_AS_RF_SWITCH"].as(false); - settingsMap[sx126x_cs] = yamlConfig["SX126X_CS"].as(RADIOLIB_NC); - settingsMap[sx126x_dio1] = yamlConfig["SX126X_DIO1"].as(RADIOLIB_NC); - settingsMap[sx126x_busy] = yamlConfig["SX126X_BUSY"].as(RADIOLIB_NC); - settingsMap[sx126x_reset] = yamlConfig["SX126X_RESET"].as(RADIOLIB_NC); - settingsMap[use_rf95] = yamlConfig["USE_RF95"].as(false); - settingsMap[rf95_nss] = yamlConfig["RF95_NSS"].as(RADIOLIB_NC); - settingsMap[rf95_irq] = yamlConfig["RF95_IRQ"].as(RADIOLIB_NC); - settingsMap[rf95_reset] = yamlConfig["RF95_RESET"].as(RADIOLIB_NC); - settingsMap[rf95_dio1] = yamlConfig["RF95_DIO1"].as(RADIOLIB_NC); + if (yamlConfig["Lora"]) { + settingsMap[use_sx1262] = false; + settingsMap[use_rf95] = false; + + if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "sx1262") { + settingsMap[use_sx1262] = true; + } else if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "RF95") { + settingsMap[use_rf95] = true; + } + settingsMap[dio2_as_rf_switch] = yamlConfig["Lora"]["DIO2_AS_RF_SWITCH"].as(false); + settingsMap[cs] = yamlConfig["Lora"]["CS"].as(RADIOLIB_NC); + settingsMap[irq] = yamlConfig["Lora"]["IRQ"].as(RADIOLIB_NC); + settingsMap[busy] = yamlConfig["Lora"]["Busy"].as(RADIOLIB_NC); + settingsMap[reset] = yamlConfig["Lora"]["Reset"].as(RADIOLIB_NC); + } } catch (YAML::Exception e) { std::cout << "*** Exception " << e.what() << std::endl; diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index 91fc4c2b1..7dc563038 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -4,18 +4,6 @@ extern std::map settingsMap; -enum { - use_sx1262, - sx126x_cs, - sx126x_dio1, - sx126x_busy, - sx126x_reset, - sx126x_dio2_as_rf_switch, - use_rf95, - rf95_nss, - rf95_irq, - rf95_reset, - rf95_dio1 -}; +enum { use_sx1262, cs, irq, busy, reset, dio2_as_rf_switch, use_rf95 }; #endif \ No newline at end of file From 5ad12fed60e6d3938a23eccc8c65c76610745d1e Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 14:05:47 -0600 Subject: [PATCH 12/52] Chill out, yamllint --- .trunk/configs/.yamllint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.trunk/configs/.yamllint.yaml b/.trunk/configs/.yamllint.yaml index 4d444662d..790846156 100644 --- a/.trunk/configs/.yamllint.yaml +++ b/.trunk/configs/.yamllint.yaml @@ -3,7 +3,7 @@ rules: required: only-when-needed extra-allowed: ["{|}"] empty-values: - forbid-in-block-mappings: true + forbid-in-block-mappings: false forbid-in-flow-mappings: true key-duplicates: {} octal-values: From d33521ee86109f2930aaa642e9ddcbac158938ae Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 14:30:34 -0600 Subject: [PATCH 13/52] Add package-raspbian workflow --- .github/workflows/package_raspbian.yml | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/package_raspbian.yml diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml new file mode 100644 index 000000000..64b0dade2 --- /dev/null +++ b/.github/workflows/package_raspbian.yml @@ -0,0 +1,34 @@ +name: Package Raspbian + +on: workflow_dispatch + +permissions: + contents: write + packages: write + +jobs: + build-raspbian: + uses: ./.github/workflows/build_raspbian.yml + + package-raspbian: + runs-on: [self-hosted, linux, ARM64] + steps: + - name: build .debpkg + run: | + mkdir -p .debpkg/usr/sbin + mkdir -p .debpkg/etc/meshtasticd + mkdir -p .debpkg/usr/lib/systemd/system/ + cp release/meshtasticd_linux_arm64 /usr/sbin/meshtasticd + cp bin/config-dist.yaml /etc/meshtasticd/config.yaml + chmod +x .debpkg/usr/sbin/meshtasticd + cp bin/meshtasticd.service /usr/lib/systemd/system/meshtasticd.service + + - uses: jiro4989/build-deb-action@v3 + with: + package: meshtasticd + package_root: .debpkg + maintainer: Jonathan Bennett + version: ${{ github.ref }} # refs/tags/v*.*.* + arch: arm64 + depends: libyaml-cpp0.7 + desc: Native Linux Meshtastic binary. From 31d7c6826dd59ea781962004b787dbf50cd68fcd Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 15:03:46 -0600 Subject: [PATCH 14/52] Update package_raspbian.yml Properly run build_raspbian as a step --- .github/workflows/package_raspbian.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 64b0dade2..7906f9659 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -7,12 +7,11 @@ permissions: packages: write jobs: - build-raspbian: - uses: ./.github/workflows/build_raspbian.yml - package-raspbian: runs-on: [self-hosted, linux, ARM64] steps: + - uses: ./.github/workflows/build_raspbian.yml + - name: build .debpkg run: | mkdir -p .debpkg/usr/sbin From dad824c0e9529b3850a664bed666ad7c9ce7f693 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 15:16:11 -0600 Subject: [PATCH 15/52] Update package_raspbian.yml -- add checkout step --- .github/workflows/package_raspbian.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 7906f9659..2b0327228 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -10,6 +10,8 @@ jobs: package-raspbian: runs-on: [self-hosted, linux, ARM64] steps: + - uses: actions/checkout@v2 + - uses: ./.github/workflows/build_raspbian.yml - name: build .debpkg From 8e92754b59162bd3ed13f118946226b0cdb75b59 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 15:48:43 -0600 Subject: [PATCH 16/52] Update package_raspbian.yml --- .github/workflows/package_raspbian.yml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 2b0327228..4b56e4557 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -7,29 +7,43 @@ permissions: packages: write jobs: + build-raspbian: + uses: ./.github/workflows/build_raspbian.yml + package-raspbian: runs-on: [self-hosted, linux, ARM64] + needs: build-raspbian steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: ./.github/workflows/build_raspbian.yml + - name: Get release version string + run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT + id: version + + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: firmware-raspbian-${{ steps.version.outputs.version }}.zip + + - name: Display structure of downloaded files + run: ls -R - name: build .debpkg run: | mkdir -p .debpkg/usr/sbin mkdir -p .debpkg/etc/meshtasticd mkdir -p .debpkg/usr/lib/systemd/system/ - cp release/meshtasticd_linux_arm64 /usr/sbin/meshtasticd - cp bin/config-dist.yaml /etc/meshtasticd/config.yaml + cp release/meshtasticd_linux_arm64 .debpkg/usr/sbin/meshtasticd + cp bin/config-dist.yaml .debpkg/etc/meshtasticd/config.yaml chmod +x .debpkg/usr/sbin/meshtasticd - cp bin/meshtasticd.service /usr/lib/systemd/system/meshtasticd.service + cp bin/meshtasticd.service .debpkg/usr/lib/systemd/system/meshtasticd.service - uses: jiro4989/build-deb-action@v3 with: package: meshtasticd package_root: .debpkg maintainer: Jonathan Bennett - version: ${{ github.ref }} # refs/tags/v*.*.* + version: ${{ steps.version.outputs.version }} # refs/tags/v*.*.* arch: arm64 depends: libyaml-cpp0.7 desc: Native Linux Meshtastic binary. From d04ff29c2a759916aecd27a07999367e4a1e9bc6 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 15:56:41 -0600 Subject: [PATCH 17/52] Update package_raspbian.yml use ubuntu-latest --- .github/workflows/package_raspbian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 4b56e4557..f5fbfe30f 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -11,7 +11,7 @@ jobs: uses: ./.github/workflows/build_raspbian.yml package-raspbian: - runs-on: [self-hosted, linux, ARM64] + runs-on: ubuntu-latest needs: build-raspbian steps: - uses: actions/checkout@v3 From 8f0ce606db10def8f56ab691acefed1694785682 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 16:07:08 -0600 Subject: [PATCH 18/52] Update package_raspbian.yml upload .deb as artifact --- .github/workflows/package_raspbian.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index f5fbfe30f..b30c7f45c 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -47,3 +47,9 @@ jobs: arch: arm64 depends: libyaml-cpp0.7 desc: Native Linux Meshtastic binary. + + - uses: actions/upload-artifact@v3 + with: + name: artifact-deb + path: | + ./*.deb From cfb09ee1154fd0f476425b60f77b996ab619bddd Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 16:41:47 -0600 Subject: [PATCH 19/52] add .deb to release --- .github/workflows/main_matrix.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 960f0d51f..8c7ba5919 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -134,6 +134,9 @@ jobs: max-parallel: 1 uses: ./.github/workflows/build_raspbian.yml + package-raspbian: + uses: ./.github/workflows/package_raspbian.yml + build-native: runs-on: ubuntu-latest steps: @@ -216,6 +219,7 @@ jobs: build-raspbian, build-native, build-rpi2040, + package-raspbian, ] steps: - name: Checkout code @@ -308,6 +312,10 @@ jobs: with: name: firmware-${{ steps.version.outputs.version }} path: ./output + + - uses: actions/download-artifact@v3 + with: + name: artifact-deb - name: Display structure of downloaded files run: ls -R @@ -365,6 +373,16 @@ jobs: asset_name: debug-elfs-${{ steps.version.outputs.version }}.zip asset_content_type: application/zip + - name: Add raspbian .deb + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./meshtasticd_${{ steps.version.outputs.version }}_arm64.deb + asset_name: meshtasticd_${{ steps.version.outputs.version }}_arm64.deb + asset_content_type: application/vnd.debian.binary-package + - name: Bump version.properties run: >- bin/bump_version.py From a9d846c1b35cfe993804905671e1a439c29229d5 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 16:45:06 -0600 Subject: [PATCH 20/52] make package_raspbian.yml a reusable workflow --- .github/workflows/package_raspbian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index b30c7f45c..a43a5ce30 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -1,6 +1,6 @@ name: Package Raspbian -on: workflow_dispatch +on: workflow_call permissions: contents: write From 7380f3b170a731848c14e6eb7e8ce12fe4eef1b1 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 16:53:00 -0600 Subject: [PATCH 21/52] Trunk fmt fix whitespace --- .github/workflows/package_raspbian.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index a43a5ce30..028c05471 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -9,13 +9,13 @@ permissions: jobs: build-raspbian: uses: ./.github/workflows/build_raspbian.yml - + package-raspbian: runs-on: ubuntu-latest needs: build-raspbian steps: - uses: actions/checkout@v3 - + - name: Get release version string run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT id: version @@ -27,7 +27,7 @@ jobs: - name: Display structure of downloaded files run: ls -R - + - name: build .debpkg run: | mkdir -p .debpkg/usr/sbin From c1f5878648e9cf271eea91a634e7d5fff22d884e Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 17:11:54 -0600 Subject: [PATCH 22/52] Add Raspbian to firmware zip --- .github/workflows/main_matrix.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 8c7ba5919..6b6ff1ad7 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -252,6 +252,8 @@ jobs: ./firmware-*-ota.zip ./device-*.sh ./device-*.bat + ./meshtasticd_linux_arm64 + ./config-dist.yaml retention-days: 90 - uses: actions/download-artifact@v3 @@ -312,7 +314,7 @@ jobs: with: name: firmware-${{ steps.version.outputs.version }} path: ./output - + - uses: actions/download-artifact@v3 with: name: artifact-deb From 195706e0e599ef71be0527a93cc8fcaebc544b8b Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 20:19:43 -0600 Subject: [PATCH 23/52] Update package_raspbian.yml to pull correct code for PR runs --- .github/workflows/package_raspbian.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 028c05471..8bbfdd372 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -14,7 +14,12 @@ jobs: runs-on: ubuntu-latest needs: build-raspbian steps: - - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: "recursive" + ref: ${{github.event.pull_request.head.ref}} + repository: ${{github.event.pull_request.head.repo.full_name}} - name: Get release version string run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT From 1b20a82b551d34c33036ab82874e259c453ec646 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 20:28:37 -0600 Subject: [PATCH 24/52] Update package_raspbian.yml Trunk --- .github/workflows/package_raspbian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 8bbfdd372..3c17c9da1 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -17,7 +17,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 with: - submodules: "recursive" + submodules: recursive ref: ${{github.event.pull_request.head.ref}} repository: ${{github.event.pull_request.head.repo.full_name}} From 57542ce9e6f099ed67ccf36132b3cd3163898fb1 Mon Sep 17 00:00:00 2001 From: Ric In New Mexico <78682404+RicInNewMexico@users.noreply.github.com> Date: Mon, 20 Nov 2023 05:33:14 -0700 Subject: [PATCH 25/52] Retain device nodeinfo during reset-nodedb (#2951) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * INA3221 bugfixes & refinement Reorganized and refactored some INA3221 code Added comments Added missing shunt resistor value (100mΩ) Added INA3221 Channel 1 to getINAVoltage() for device battery monitoring modified: src/Power.cpp modified: src/modules/Telemetry/PowerTelemetry.cpp modified: src/modules/Telemetry/Sensor/INA3221Sensor.cpp modified: src/modules/Telemetry/Sensor/INA3221Sensor.h modified: src/power.h * reset-nodedb retain device nodeinfo modified: src/mesh/NodeDB.cpp * reset-nodedb #2 modified: src/mesh/NodeDB.cpp --------- Co-authored-by: Jonathan Bennett --- src/mesh/NodeDB.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index d7fa9e5ac..11106585f 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -316,8 +316,8 @@ void NodeDB::installDefaultChannels() void NodeDB::resetNodes() { - devicestate.node_db_lite_count = 0; - memset(devicestate.node_db_lite, 0, sizeof(devicestate.node_db_lite)); + devicestate.node_db_lite_count = 1; + std::fill(&devicestate.node_db_lite[1], &devicestate.node_db_lite[MAX_NUM_NODES - 1], meshtastic_NodeInfoLite()); saveDeviceStateToDisk(); if (neighborInfoModule && moduleConfig.neighbor_info.enabled) neighborInfoModule->resetNeighbors(); From 4712b1ca65f49ead0954bea9648fe919e13fb9a1 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 22 Nov 2023 07:17:48 -0600 Subject: [PATCH 26/52] Add manual run option to package_raspbian.yml (#2954) --- .github/workflows/package_raspbian.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 3c17c9da1..61f82e9d7 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -1,6 +1,8 @@ name: Package Raspbian -on: workflow_call +on: + workflow_call: + workflow_dispatch: permissions: contents: write From cbb8eb65baefb07425d6eb90ec50d6ab4afc8136 Mon Sep 17 00:00:00 2001 From: HookdomPonix <83303405+HookdomPonix@users.noreply.github.com> Date: Wed, 22 Nov 2023 09:30:55 -0700 Subject: [PATCH 27/52] Add USB detection to RAK4631 based boards. (#2956) * Add support for the rak10701 board, no touch * Moved tftblack fillin and changed teh src flags * Added rak10701 to platformio.ini * Add USB detection to RAK4631 units. * Eliminate spurious symbol in comment field. --------- Co-authored-by: Ben Meadors --- src/Power.cpp | 26 +++++++++++++++++++++--- variants/rak10701/variant.h | 3 +++ variants/rak4631/variant.h | 3 +++ variants/rak4631_epaper/variant.h | 5 ++++- variants/rak4631_epaper_onrxtx/variant.h | 5 ++++- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index c7392c90b..0a56a1ba2 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -19,6 +19,11 @@ #include "meshUtils.h" #include "sleep.h" +// Working USB detection for powered/charging states on the RAK platform +#ifdef NRF_APM +#include "nrfx_power.h" +#endif + #ifdef DEBUG_HEAP_MQTT #include "mqtt/MQTT.h" #include "target_specific.h" @@ -460,10 +465,25 @@ void Power::readPowerStatus() } } + OptionalBool NRF_USB = OptFalse; + +#ifdef NRF_APM // Section of code detects USB power on the RAK4631 and updates the power states. Takes 20 seconds or so to detect + // changes. + + nrfx_power_usb_state_t nrf_usb_state = nrfx_power_usbstatus_get(); + + if (nrf_usb_state == NRFX_POWER_USB_STATE_DISCONNECTED) { + powerFSM.trigger(EVENT_POWER_DISCONNECTED); + NRF_USB = OptFalse; + } else { + powerFSM.trigger(EVENT_POWER_CONNECTED); + NRF_USB = OptTrue; + } +#endif // Notify any status instances that are observing us - const PowerStatus powerStatus2 = - PowerStatus(hasBattery ? OptTrue : OptFalse, batteryLevel->isVbusIn() ? OptTrue : OptFalse, - batteryLevel->isCharging() ? OptTrue : OptFalse, batteryVoltageMv, batteryChargePercent); + const PowerStatus powerStatus2 = PowerStatus( + hasBattery ? OptTrue : OptFalse, batteryLevel->isVbusIn() || NRF_USB == OptTrue ? OptTrue : OptFalse, + batteryLevel->isCharging() || NRF_USB == OptTrue ? OptTrue : OptFalse, batteryVoltageMv, batteryChargePercent); LOG_DEBUG("Battery: usbPower=%d, isCharging=%d, batMv=%d, batPct=%d\n", powerStatus2.getHasUSB(), powerStatus2.getIsCharging(), powerStatus2.getBatteryVoltageMv(), powerStatus2.getBatteryChargePercent()); newStatus.notifyObservers(&powerStatus2); diff --git a/variants/rak10701/variant.h b/variants/rak10701/variant.h index 3b771d62b..5ff12a7de 100644 --- a/variants/rak10701/variant.h +++ b/variants/rak10701/variant.h @@ -234,6 +234,9 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG #define SX126X_DIO2_AS_RF_SWITCH #define SX126X_DIO3_TCXO_VOLTAGE 1.8 +// Testing USB detection +#define NRF_APM + // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (34) diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index 89bb62c73..956bcd772 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -215,6 +215,9 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG #define SX126X_DIO2_AS_RF_SWITCH #define SX126X_DIO3_TCXO_VOLTAGE 1.8 +// Testing USB detection +#define NRF_APM + // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (34) diff --git a/variants/rak4631_epaper/variant.h b/variants/rak4631_epaper/variant.h index 0253ec14d..bc2eddfee 100644 --- a/variants/rak4631_epaper/variant.h +++ b/variants/rak4631_epaper/variant.h @@ -209,6 +209,9 @@ static const uint8_t SCK = PIN_SPI_SCK; // RAK12002 RTC Module #define RV3028_RTC (uint8_t)0b1010010 +// Testing USB detection +#define NRF_APM + // Battery // The battery sense is hooked to pin A0 (5) #define BATTERY_PIN PIN_A0 @@ -241,4 +244,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif +#endif \ No newline at end of file diff --git a/variants/rak4631_epaper_onrxtx/variant.h b/variants/rak4631_epaper_onrxtx/variant.h index 6fc6da373..411e3eb17 100644 --- a/variants/rak4631_epaper_onrxtx/variant.h +++ b/variants/rak4631_epaper_onrxtx/variant.h @@ -84,6 +84,9 @@ static const uint8_t AREF = PIN_AREF; #define PIN_SERIAL2_RX (-1) #define PIN_SERIAL2_TX (-1) +// Testing USB detection +#define NRF_APM + /* * SPI Interfaces */ @@ -212,4 +215,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif +#endif \ No newline at end of file From b3852322efc5e413d0301349f829cf280e585a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 24 Nov 2023 14:40:20 +0100 Subject: [PATCH 28/52] Add config example for Elecrow Hat NFC --- bin/config-dist.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 3924335a2..6c8f1946f 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -19,3 +19,8 @@ Lora: # CS: 7 # IRQ: 22 # Busy: 23 + +# Module: RF95 # Elecrow Lora RFM95 IOT https://www.elecrow.com/lora-rfm95-iot-board-for-rpi.html +# Reset: 22 +# CS: 7 +# IRQ: 25 From d6fc1c314f8a31cc925ebab0dce01a6d5d715796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 14 Nov 2023 15:33:54 +0100 Subject: [PATCH 29/52] WIP: Add battery level for Nimble --- src/nimble/NimbleBluetooth.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 1f06b25f2..3175e0f09 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -9,6 +9,7 @@ #include NimBLECharacteristic *fromNumCharacteristic; +NimBLECharacteristic *BatteryCharacteristic; NimBLEServer *bleServer; static bool passkeyShowing; @@ -181,6 +182,18 @@ void NimbleBluetooth::setupService() FromRadioCharacteristic->setCallbacks(fromRadioCallbacks); bleService->start(); + + // Setup the battery service + NimBLEService *batteryService = bleServer->createService(NimBLEUUID((uint16_t)0x180f)); // 0x180F is the Battery Service + BatteryCharacteristic = batteryService->createCharacteristic( // 0x2A19 is the Battery Level characteristic) + (uint16_t)0x2a19, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY); + + NimBLE2904 *batteryLevelDescriptor = (NimBLE2904 *)BatteryCharacteristic->createDescriptor((uint16_t)0x2904); + batteryLevelDescriptor->setFormat(NimBLE2904::FORMAT_UINT8); + batteryLevelDescriptor->setNamespace(1); + batteryLevelDescriptor->setUnit(0x27ad); + + batteryService->start(); } void NimbleBluetooth::startAdvertising() @@ -188,13 +201,15 @@ void NimbleBluetooth::startAdvertising() NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising(); pAdvertising->reset(); pAdvertising->addServiceUUID(MESH_SERVICE_UUID); + pAdvertising->addServiceUUID(NimBLEUUID((uint16_t)0x180f)); // 0x180F is the Battery Service pAdvertising->start(0); } /// Given a level between 0-100, update the BLE attribute void updateBatteryLevel(uint8_t level) { - // blebas.write(level); + BatteryCharacteristic->setValue(&level, 1); + BatteryCharacteristic->notify(); } void NimbleBluetooth::clearBonds() From 1feb74f52570186f4d8d0fe7c86872eac5e9ff29 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 25 Nov 2023 19:34:30 -0600 Subject: [PATCH 30/52] Add number of sats to default position flags (#2962) --- src/mesh/NodeDB.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 11106585f..2e6c8131e 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -200,7 +200,7 @@ void NodeDB::installDefaultConfig() config.position.position_flags = (meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE | meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE_MSL | meshtastic_Config_PositionConfig_PositionFlags_SPEED | meshtastic_Config_PositionConfig_PositionFlags_HEADING | - meshtastic_Config_PositionConfig_PositionFlags_DOP); + meshtastic_Config_PositionConfig_PositionFlags_DOP | meshtastic_Config_PositionConfig_PositionFlags_SATINVIEW); #ifdef T_WATCH_S3 config.display.screen_on_secs = 30; From ac318a9850d6c4828f1a8517eb54cd655f713294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 23 Nov 2023 10:10:16 +0100 Subject: [PATCH 31/52] Swapped out crypto engine for one that also works with AES-256 --- arch/rp2040/rp2040.ini | 2 +- src/platform/rp2040/rp2040CryptoEngine.cpp | 46 ++++++++++++++++++---- variants/rak11310/variant.h | 7 ---- variants/rpipico/variant.h | 7 ---- variants/rpipicow/variant.h | 7 ---- 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/arch/rp2040/rp2040.ini b/arch/rp2040/rp2040.ini index b6ac4f171..495b52a86 100644 --- a/arch/rp2040/rp2040.ini +++ b/arch/rp2040/rp2040.ini @@ -21,4 +21,4 @@ lib_deps = ${arduino_base.lib_deps} ${environmental_base.lib_deps} jgromes/RadioLib@^6.1.0 - https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b \ No newline at end of file + rweather/Crypto \ No newline at end of file diff --git a/src/platform/rp2040/rp2040CryptoEngine.cpp b/src/platform/rp2040/rp2040CryptoEngine.cpp index c90126cc7..5486e51e5 100644 --- a/src/platform/rp2040/rp2040CryptoEngine.cpp +++ b/src/platform/rp2040/rp2040CryptoEngine.cpp @@ -1,33 +1,63 @@ +#include "AES.h" +#include "CTR.h" #include "CryptoEngine.h" -#include "aes.hpp" #include "configuration.h" class RP2040CryptoEngine : public CryptoEngine { + + CTRCommon *ctr = NULL; + public: RP2040CryptoEngine() {} ~RP2040CryptoEngine() {} + virtual void setKey(const CryptoKey &k) override + { + CryptoEngine::setKey(k); + LOG_DEBUG("Installing AES%d key!\n", key.length * 8); + if (ctr) { + delete ctr; + ctr = NULL; + } + if (key.length != 0) { + if (key.length == 16) + ctr = new CTR(); + else + ctr = new CTR(); + + ctr->setKey(key.bytes, key.length); + } + } /** * Encrypt a packet * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { if (key.length > 0) { - AES_ctx ctx; - initNonce(fromNode, packetNum); - AES_init_ctx_iv(&ctx, key.bytes, nonce); - AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes); + initNonce(fromNode, packetId); + if (numBytes <= MAX_BLOCKSIZE) { + static uint8_t scratch[MAX_BLOCKSIZE]; + memcpy(scratch, bytes, numBytes); + memset(scratch + numBytes, 0, + sizeof(scratch) - numBytes); // Fill rest of buffer with zero (in case cypher looks at it) + + ctr->setIV(nonce, sizeof(nonce)); + ctr->setCounterSize(4); + ctr->encrypt(bytes, scratch, numBytes); + } else { + LOG_ERROR("Packet too large for crypto engine: %d. noop encryption!\n", numBytes); + } } } - virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { // For CTR, the implementation is the same - encrypt(fromNode, packetNum, numBytes, bytes); + encrypt(fromNode, packetId, numBytes, bytes); } private: diff --git a/variants/rak11310/variant.h b/variants/rak11310/variant.h index 1ea6d141d..acc21ce99 100644 --- a/variants/rak11310/variant.h +++ b/variants/rak11310/variant.h @@ -4,13 +4,6 @@ #define ARDUINO_ARCH_AVR -#undef CBC -#define CBC 0 -#undef CTR -#define CTR 1 -#undef ECB -#define ECB 0 - #define LED_CONN PIN_LED2 #define LED_PIN LED_BUILTIN diff --git a/variants/rpipico/variant.h b/variants/rpipico/variant.h index 5c92dec59..be26099de 100644 --- a/variants/rpipico/variant.h +++ b/variants/rpipico/variant.h @@ -4,13 +4,6 @@ #define ARDUINO_ARCH_AVR -#undef CBC -#define CBC 0 -#undef CTR -#define CTR 1 -#undef ECB -#define ECB 0 - #define USE_SH1106 1 // default I2C pins: diff --git a/variants/rpipicow/variant.h b/variants/rpipicow/variant.h index 6de2f7bd4..77cb1ffd6 100644 --- a/variants/rpipicow/variant.h +++ b/variants/rpipicow/variant.h @@ -4,13 +4,6 @@ #define ARDUINO_ARCH_AVR -#undef CBC -#define CBC 0 -#undef CTR -#define CTR 1 -#undef ECB -#define ECB 0 - #define USE_SH1106 1 // default I2C pins: From 603e564db37db26861933a3f046ddbd5ee8518e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 23 Nov 2023 12:44:40 +0100 Subject: [PATCH 32/52] same change for STM32WL - also update trunk --- .trunk/trunk.yaml | 20 ++++----- arch/stm32/stm32wl5e.ini | 2 +- src/platform/stm32wl/STM32WLCryptoEngine.cpp | 46 ++++++++++++++++---- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index e31b026f4..66a16a152 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,25 +1,25 @@ version: 0.1 cli: - version: 1.17.1 + version: 1.17.2 plugins: sources: - id: trunk - ref: v1.2.6 + ref: v1.3.0 uri: https://github.com/trunk-io/plugins lint: enabled: - bandit@1.7.5 - - checkov@3.0.16 + - checkov@3.1.9 - terrascan@1.18.3 - - trivy@0.46.1 - - trufflehog@3.62.1 + - trivy@0.47.0 + - trufflehog@3.63.2-rc0 - taplo@0.8.1 - - ruff@0.1.3 - - yamllint@1.32.0 + - ruff@0.1.6 + - yamllint@1.33.0 - isort@5.12.0 - markdownlint@0.37.0 - oxipng@9.0.0 - - svgo@3.0.2 + - svgo@3.0.4 - actionlint@1.6.26 - flake8@6.1.0 - hadolint@2.12.0 @@ -27,9 +27,9 @@ lint: - shellcheck@0.9.0 - black@23.9.1 - git-diff-check - - gitleaks@8.18.0 + - gitleaks@8.18.1 - clang-format@16.0.3 - - prettier@3.0.3 + - prettier@3.1.0 runtimes: enabled: - python@3.10.8 diff --git a/arch/stm32/stm32wl5e.ini b/arch/stm32/stm32wl5e.ini index 524edd6b9..262da12a6 100644 --- a/arch/stm32/stm32wl5e.ini +++ b/arch/stm32/stm32wl5e.ini @@ -21,7 +21,7 @@ upload_protocol = stlink lib_deps = ${env.lib_deps} jgromes/RadioLib@^6.1.0 - https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b + rweather/Crypto https://github.com/littlefs-project/littlefs.git#v2.5.1 https://github.com/stm32duino/STM32FreeRTOS.git#10.3.1 diff --git a/src/platform/stm32wl/STM32WLCryptoEngine.cpp b/src/platform/stm32wl/STM32WLCryptoEngine.cpp index 7367a2bc0..6187cf302 100644 --- a/src/platform/stm32wl/STM32WLCryptoEngine.cpp +++ b/src/platform/stm32wl/STM32WLCryptoEngine.cpp @@ -1,33 +1,63 @@ +#include "AES.h" +#include "CTR.h" #include "CryptoEngine.h" -#include "aes.hpp" #include "configuration.h" class STM32WLCryptoEngine : public CryptoEngine { + + CTRCommon *ctr = NULL; + public: STM32WLCryptoEngine() {} ~STM32WLCryptoEngine() {} + virtual void setKey(const CryptoKey &k) override + { + CryptoEngine::setKey(k); + LOG_DEBUG("Installing AES%d key!\n", key.length * 8); + if (ctr) { + delete ctr; + ctr = NULL; + } + if (key.length != 0) { + if (key.length == 16) + ctr = new CTR(); + else + ctr = new CTR(); + + ctr->setKey(key.bytes, key.length); + } + } /** * Encrypt a packet * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { if (key.length > 0) { - AES_ctx ctx; - initNonce(fromNode, packetNum); - AES_init_ctx_iv(&ctx, key.bytes, nonce); - AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes); + initNonce(fromNode, packetId); + if (numBytes <= MAX_BLOCKSIZE) { + static uint8_t scratch[MAX_BLOCKSIZE]; + memcpy(scratch, bytes, numBytes); + memset(scratch + numBytes, 0, + sizeof(scratch) - numBytes); // Fill rest of buffer with zero (in case cypher looks at it) + + ctr->setIV(nonce, sizeof(nonce)); + ctr->setCounterSize(4); + ctr->encrypt(bytes, scratch, numBytes); + } else { + LOG_ERROR("Packet too large for crypto engine: %d. noop encryption!\n", numBytes); + } } } - virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { // For CTR, the implementation is the same - encrypt(fromNode, packetNum, numBytes, bytes); + encrypt(fromNode, packetId, numBytes, bytes); } private: From c7e3485dd77eff6632c7c9e053d73b9269c42422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 23 Nov 2023 13:47:07 +0100 Subject: [PATCH 33/52] Revert "same change for STM32WL - also update trunk" This reverts commit f9fdb0f98d5e095b5537e9b740231368fc088210. --- .trunk/trunk.yaml | 20 ++++----- arch/stm32/stm32wl5e.ini | 2 +- src/platform/stm32wl/STM32WLCryptoEngine.cpp | 46 ++++---------------- 3 files changed, 19 insertions(+), 49 deletions(-) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 66a16a152..e31b026f4 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,25 +1,25 @@ version: 0.1 cli: - version: 1.17.2 + version: 1.17.1 plugins: sources: - id: trunk - ref: v1.3.0 + ref: v1.2.6 uri: https://github.com/trunk-io/plugins lint: enabled: - bandit@1.7.5 - - checkov@3.1.9 + - checkov@3.0.16 - terrascan@1.18.3 - - trivy@0.47.0 - - trufflehog@3.63.2-rc0 + - trivy@0.46.1 + - trufflehog@3.62.1 - taplo@0.8.1 - - ruff@0.1.6 - - yamllint@1.33.0 + - ruff@0.1.3 + - yamllint@1.32.0 - isort@5.12.0 - markdownlint@0.37.0 - oxipng@9.0.0 - - svgo@3.0.4 + - svgo@3.0.2 - actionlint@1.6.26 - flake8@6.1.0 - hadolint@2.12.0 @@ -27,9 +27,9 @@ lint: - shellcheck@0.9.0 - black@23.9.1 - git-diff-check - - gitleaks@8.18.1 + - gitleaks@8.18.0 - clang-format@16.0.3 - - prettier@3.1.0 + - prettier@3.0.3 runtimes: enabled: - python@3.10.8 diff --git a/arch/stm32/stm32wl5e.ini b/arch/stm32/stm32wl5e.ini index 262da12a6..524edd6b9 100644 --- a/arch/stm32/stm32wl5e.ini +++ b/arch/stm32/stm32wl5e.ini @@ -21,7 +21,7 @@ upload_protocol = stlink lib_deps = ${env.lib_deps} jgromes/RadioLib@^6.1.0 - rweather/Crypto + https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b https://github.com/littlefs-project/littlefs.git#v2.5.1 https://github.com/stm32duino/STM32FreeRTOS.git#10.3.1 diff --git a/src/platform/stm32wl/STM32WLCryptoEngine.cpp b/src/platform/stm32wl/STM32WLCryptoEngine.cpp index 6187cf302..7367a2bc0 100644 --- a/src/platform/stm32wl/STM32WLCryptoEngine.cpp +++ b/src/platform/stm32wl/STM32WLCryptoEngine.cpp @@ -1,63 +1,33 @@ -#include "AES.h" -#include "CTR.h" #include "CryptoEngine.h" +#include "aes.hpp" #include "configuration.h" class STM32WLCryptoEngine : public CryptoEngine { - - CTRCommon *ctr = NULL; - public: STM32WLCryptoEngine() {} ~STM32WLCryptoEngine() {} - virtual void setKey(const CryptoKey &k) override - { - CryptoEngine::setKey(k); - LOG_DEBUG("Installing AES%d key!\n", key.length * 8); - if (ctr) { - delete ctr; - ctr = NULL; - } - if (key.length != 0) { - if (key.length == 16) - ctr = new CTR(); - else - ctr = new CTR(); - - ctr->setKey(key.bytes, key.length); - } - } /** * Encrypt a packet * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override + virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override { if (key.length > 0) { - initNonce(fromNode, packetId); - if (numBytes <= MAX_BLOCKSIZE) { - static uint8_t scratch[MAX_BLOCKSIZE]; - memcpy(scratch, bytes, numBytes); - memset(scratch + numBytes, 0, - sizeof(scratch) - numBytes); // Fill rest of buffer with zero (in case cypher looks at it) - - ctr->setIV(nonce, sizeof(nonce)); - ctr->setCounterSize(4); - ctr->encrypt(bytes, scratch, numBytes); - } else { - LOG_ERROR("Packet too large for crypto engine: %d. noop encryption!\n", numBytes); - } + AES_ctx ctx; + initNonce(fromNode, packetNum); + AES_init_ctx_iv(&ctx, key.bytes, nonce); + AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes); } } - virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override + virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override { // For CTR, the implementation is the same - encrypt(fromNode, packetId, numBytes, bytes); + encrypt(fromNode, packetNum, numBytes, bytes); } private: From c7f6071f703146711433b428b14a2b6c48c6d5de Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 28 Nov 2023 20:40:51 -0600 Subject: [PATCH 34/52] Enable IO2 toggling on RAK if the coast is clear (#2968) * Enable IO2 toggling on RAK if the coast is clear * Guard against monteops target which doesn't use 3V3 pin * Also check for en_gpio = 0 to avoid re-setting the value --- src/gps/GPS.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index af622e3d8..11c16ede9 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -264,6 +264,20 @@ bool GPS::setup() isProblematicGPS = true; } #endif + +#if defined(RAK4630) && defined(PIN_3V3_EN) + // If we are using the RAK4630 and we have no other peripherals on the I2C bus or module interest in 3V3_S, + // then we can safely set en_gpio turn off power to 3V3 (IO2) to hard sleep the GPS + if (rtc_found.port == ScanI2C::DeviceType::NONE && rgb_found.type == ScanI2C::DeviceType::NONE && + accelerometer_found.port == ScanI2C::DeviceType::NONE && !moduleConfig.detection_sensor.enabled && + !moduleConfig.telemetry.air_quality_enabled && !moduleConfig.telemetry.environment_measurement_enabled && + config.power.device_battery_ina_address == 0 && en_gpio == 0) { + LOG_DEBUG("Since no problematic peripherals or interested modules were found, setting power save GPS_EN to pin %i\n", + PIN_3V3_EN); + en_gpio = PIN_3V3_EN; + } +#endif + if (tx_gpio && gnssModel == GNSS_MODEL_UNKNOWN) { LOG_DEBUG("Probing for GPS at %d \n", serialSpeeds[speedSelect]); gnssModel = probe(serialSpeeds[speedSelect]); @@ -436,6 +450,7 @@ bool GPS::setup() notifyDeepSleepObserver.observe(¬ifyDeepSleep); notifyGPSSleepObserver.observe(¬ifyGPSSleep); + return true; } From 18cf8ca4fa61483bb6cb25874be94f2bd0ed082c Mon Sep 17 00:00:00 2001 From: S5NC <145265251+S5NC@users.noreply.github.com> Date: Wed, 29 Nov 2023 21:51:05 +0000 Subject: [PATCH 35/52] Generalise SPI pin names (#2970) * Generalise SPI pin names * CS not NSS * trunk fmt * Update variant.h --------- Co-authored-by: Ben Meadors --- src/main.cpp | 22 ++++++------- src/platform/esp32/architecture.h | 10 +++--- src/platform/portduino/PortduinoGlue.cpp | 2 +- variants/ai-c3/variant.h | 10 +++--- variants/betafpv_2400_tx_micro/variant.h | 8 ++--- variants/betafpv_900_tx_nano/variant.h | 8 ++--- variants/bpi_picow_esp32_s3/variant.h | 28 ++++++++--------- variants/diy/dr-dev/variant.h | 20 ++++++------ variants/diy/hydra/variant.h | 8 ++--- variants/diy/v1/variant.h | 8 ++--- variants/diy/v1_1/variant.h | 16 +++++----- variants/feather_diy/variant.h | 10 +++--- variants/heltec_esp32c3/variant.h | 18 +++++------ variants/heltec_v3/variant.h | 10 +++--- variants/heltec_wireless_paper/variant.h | 10 +++--- variants/heltec_wireless_tracker/variant.h | 10 +++--- variants/heltec_wsl_v3/variant.h | 10 +++--- variants/m5stack-stamp-c3/variant.h | 36 +++++++++++----------- variants/m5stack_core/variant.h | 16 +++++----- variants/m5stack_coreink/variant.h | 26 ++++++++-------- variants/my_esp32s3_diy_eink/variant.h | 12 ++++---- variants/my_esp32s3_diy_oled/variant.h | 12 ++++---- variants/nano-g1-explorer/variant.h | 2 +- variants/nano-g1/variant.h | 2 +- variants/picomputer-s3/variant.h | 8 ++--- variants/portduino/variant.h | 8 ++--- variants/rak11200/variant.h | 16 +++++----- variants/rak11310/variant.h | 18 +++++------ variants/rpipico/variant.h | 18 +++++------ variants/rpipicow/variant.h | 18 +++++------ variants/station-g1/variant.h | 2 +- variants/t-deck/variant.h | 10 +++--- variants/t-watch-s3/variant.h | 10 +++--- variants/tbeam-s3-core/variant.h | 8 ++--- variants/tbeam/variant.h | 2 +- variants/tlora_t3s3_v1/variant.h | 12 ++++---- 36 files changed, 222 insertions(+), 222 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cfd6279e0..4913f1091 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -628,24 +628,24 @@ void setup() initSPI(); #ifdef ARCH_RP2040 #ifdef HW_SPI1_DEVICE - SPI1.setSCK(RF95_SCK); - SPI1.setTX(RF95_MOSI); - SPI1.setRX(RF95_MISO); - pinMode(RF95_NSS, OUTPUT); - digitalWrite(RF95_NSS, HIGH); + SPI1.setSCK(LORA_SCK); + SPI1.setTX(LORA_MOSI); + SPI1.setRX(LORA_MISO); + pinMode(LORA_CS, OUTPUT); + digitalWrite(LORA_CS, HIGH); SPI1.begin(false); #else // HW_SPI1_DEVICE - SPI.setSCK(RF95_SCK); - SPI.setTX(RF95_MOSI); - SPI.setRX(RF95_MISO); + SPI.setSCK(LORA_SCK); + SPI.setTX(LORA_MOSI); + SPI.setRX(LORA_MISO); SPI.begin(false); #endif // HW_SPI1_DEVICE #elif !defined(ARCH_ESP32) // ARCH_RP2040 SPI.begin(); #else // ESP32 - SPI.begin(RF95_SCK, RF95_MISO, RF95_MOSI, RF95_NSS); - LOG_WARN("SPI.begin(SCK=%d, MISO=%d, MOSI=%d, NSS=%d)\n", RF95_SCK, RF95_MISO, RF95_MOSI, RF95_NSS); + SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); + LOG_WARN("SPI.begin(SCK=%d, MISO=%d, MOSI=%d, NSS=%d)\n", LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); SPI.setFrequency(4000000); #endif @@ -755,7 +755,7 @@ void setup() #if defined(RF95_IRQ) if (!rIf) { - rIf = new RF95Interface(RadioLibHAL, RF95_NSS, RF95_IRQ, RF95_RESET, RF95_DIO1); + rIf = new RF95Interface(RadioLibHAL, LORA_CS, RF95_IRQ, RF95_RESET, RF95_DIO1); if (!rIf->init()) { LOG_WARN("Failed to find RF95 radio\n"); delete rIf; diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index 163cc8b84..781d41678 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -128,11 +128,11 @@ // ----------------------------------------------------------------------------- // NRF52 boards will define this in variant.h -#ifndef RF95_SCK -#define RF95_SCK 5 -#define RF95_MISO 19 -#define RF95_MOSI 27 -#define RF95_NSS 18 +#ifndef LORA_SCK +#define LORA_SCK 5 +#define LORA_MISO 19 +#define LORA_MOSI 27 +#define LORA_CS 18 #endif #define SERIAL0_RX_GPIO 3 // Always GPIO3 on ESP32 \ No newline at end of file diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 2e402c0a0..d2a00e1e1 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -192,6 +192,6 @@ void portduinoSetup() gpioBind(new SimGPIOPin(LORA_DIO1, "fakeLoraIrq")); } // gpioBind((new SimGPIOPin(LORA_RESET, "LORA_RESET"))); - // gpioBind((new SimGPIOPin(RF95_NSS, "RF95_NSS"))->setSilent()); + // gpioBind((new SimGPIOPin(LORA_CS, "LORA_CS"))->setSilent()); #endif } \ No newline at end of file diff --git a/variants/ai-c3/variant.h b/variants/ai-c3/variant.h index 254f5fd36..6c4f4d38a 100644 --- a/variants/ai-c3/variant.h +++ b/variants/ai-c3/variant.h @@ -7,10 +7,10 @@ #define LED_PIN 30 // RGB LED #define USE_RF95 -#define RF95_SCK 4 -#define RF95_MISO 5 -#define RF95_MOSI 6 -#define RF95_NSS 7 +#define LORA_SCK 4 +#define LORA_MISO 5 +#define LORA_MOSI 6 +#define LORA_CS 7 #define LORA_DIO0 10 #define LORA_DIO1 3 @@ -19,7 +19,7 @@ // WaveShare Core1262-868M // https://www.waveshare.com/wiki/Core1262-868M #define USE_SX1262 -#define SX126X_CS RF95_NSS +#define SX126X_CS LORA_CS #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY 10 #define SX126X_RESET LORA_RESET diff --git a/variants/betafpv_2400_tx_micro/variant.h b/variants/betafpv_2400_tx_micro/variant.h index 2a8b2f40c..8c615d168 100644 --- a/variants/betafpv_2400_tx_micro/variant.h +++ b/variants/betafpv_2400_tx_micro/variant.h @@ -9,10 +9,10 @@ #undef GPS_RX_PIN #undef GPS_TX_PIN -#define RF95_SCK 18 -#define RF95_MISO 19 -#define RF95_MOSI 23 -#define RF95_NSS 5 +#define LORA_SCK 18 +#define LORA_MISO 19 +#define LORA_MOSI 23 +#define LORA_CS 5 #define RF95_FAN_EN 17 #define LED_PIN 16 // This is a LED_WS2812 not a standard LED diff --git a/variants/betafpv_900_tx_nano/variant.h b/variants/betafpv_900_tx_nano/variant.h index 01961d92d..7a4ae9190 100644 --- a/variants/betafpv_900_tx_nano/variant.h +++ b/variants/betafpv_900_tx_nano/variant.h @@ -9,10 +9,10 @@ #define USE_RF95 -#define RF95_SCK 18 -#define RF95_MISO 19 -#define RF95_MOSI 23 -#define RF95_NSS 5 +#define LORA_SCK 18 +#define LORA_MISO 19 +#define LORA_MOSI 23 +#define LORA_CS 5 #define LORA_DIO0 4 #define LORA_RESET 14 diff --git a/variants/bpi_picow_esp32_s3/variant.h b/variants/bpi_picow_esp32_s3/variant.h index 8114b9ea3..d8d9413d7 100644 --- a/variants/bpi_picow_esp32_s3/variant.h +++ b/variants/bpi_picow_esp32_s3/variant.h @@ -22,24 +22,24 @@ // #define USE_RF95 // RFM95/SX127x -#undef RF95_SCK -#undef RF95_MISO -#undef RF95_MOSI -#undef RF95_NSS +#undef LORA_SCK +#undef LORA_MISO +#undef LORA_MOSI +#undef LORA_CS // WaveShare Core1262-868M OK // https://www.waveshare.com/wiki/Core1262-868M #define USE_SX1262 #ifdef USE_SX1262 -#define RF95_MISO 39 -#define RF95_SCK 21 -#define RF95_MOSI 38 -#define RF95_NSS 17 +#define LORA_MISO 39 +#define LORA_SCK 21 +#define LORA_MOSI 38 +#define LORA_CS 17 #define LORA_RESET 42 #define LORA_DIO1 5 #define LORA_BUSY 47 -#define SX126X_CS RF95_NSS +#define SX126X_CS LORA_CS #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_BUSY #define SX126X_RESET LORA_RESET @@ -49,14 +49,14 @@ // #define USE_SX1280 #ifdef USE_SX1280 -#define RF95_MISO 1 -#define RF95_SCK 3 -#define RF95_MOSI 4 -#define RF95_NSS 2 +#define LORA_MISO 1 +#define LORA_SCK 3 +#define LORA_MOSI 4 +#define LORA_CS 2 #define LORA_RESET 17 #define LORA_DIO1 12 #define LORA_BUSY 47 -#define SX128X_CS RF95_NSS +#define SX128X_CS LORA_CS #define SX128X_DIO1 LORA_DIO1 #define SX128X_BUSY LORA_BUSY #define SX128X_RESET LORA_RESET diff --git a/variants/diy/dr-dev/variant.h b/variants/diy/dr-dev/variant.h index 08d57eec9..35b18ee74 100644 --- a/variants/diy/dr-dev/variant.h +++ b/variants/diy/dr-dev/variant.h @@ -22,12 +22,12 @@ // In receiving, set RXEN as high communication level, TXEN is lowlevel; // Before powering off, set TXEN、RXEN as low level. -#undef RF95_SCK -#define RF95_SCK 18 -#undef RF95_MISO -#define RF95_MISO 19 -#undef RF95_MOSI -#define RF95_MOSI 23 +#undef LORA_SCK +#define LORA_SCK 18 +#undef LORA_MISO +#define LORA_MISO 19 +#undef LORA_MOSI +#define LORA_MOSI 23 // PINS FOR THE 900M22S @@ -38,8 +38,8 @@ // E22_TXEN_CONNECTED_TO_DIO2 wasn't defined, so RXEN wasn't controlled. Commented it out to maintain behavior, but shouldn't be. // Need to comment out defining SX126X_RXEN as LORA_RXEN too // #define LORA_RXEN 17 // Input - RF switch RX control, connecting external MCU IO, valid in high level -#undef RF95_NSS -#define RF95_NSS 16 +#undef LORA_CS +#define LORA_CS 16 #define SX126X_BUSY 22 #define SX126X_CS 16 @@ -49,8 +49,8 @@ #define LORA_DIO2 35 // BUSY for SX1262/SX1268 #define LORA_TXEN NOT_A_PIN // Input - RF switch TX control, connecting external MCU IO or DIO2, valid in high level #define LORA_RXEN 21 // Input - RF switch RX control, connecting external MCU IO, valid in high level -#undef RF95_NSS -#define RF95_NSS 33 +#undef LORA_CS +#define LORA_CS 33 #define SX126X_BUSY 35 #define SX126X_CS 33 */ diff --git a/variants/diy/hydra/variant.h b/variants/diy/hydra/variant.h index 64bdd73f7..a51b21653 100644 --- a/variants/diy/hydra/variant.h +++ b/variants/diy/hydra/variant.h @@ -33,8 +33,8 @@ #define SX126X_TXEN 13 // Schematic connects EBYTE module's TXEN pin to MCU #define SX126X_RXEN 14 // Schematic connects EBYTE module's RXEN pin to MCU -#define RF95_NSS SX126X_CS // Compatibility with variant file configuration structure -#define RF95_SCK SX126X_SCK // Compatibility with variant file configuration structure -#define RF95_MOSI SX126X_MOSI // Compatibility with variant file configuration structure -#define RF95_MISO SX126X_MISO // Compatibility with variant file configuration structure +#define LORA_CS SX126X_CS // Compatibility with variant file configuration structure +#define LORA_SCK SX126X_SCK // Compatibility with variant file configuration structure +#define LORA_MOSI SX126X_MOSI // Compatibility with variant file configuration structure +#define LORA_MISO SX126X_MISO // Compatibility with variant file configuration structure #define LORA_DIO1 SX126X_DIO1 // Compatibility with variant file configuration structure diff --git a/variants/diy/v1/variant.h b/variants/diy/v1/variant.h index 48906515b..4802dbe89 100644 --- a/variants/diy/v1/variant.h +++ b/variants/diy/v1/variant.h @@ -23,10 +23,10 @@ #define LORA_DIO2 32 // BUSY for SX1262/SX1268 #define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262/SX1268, if DIO3 is high the TXCO is enabled -#define RF95_SCK 5 -#define RF95_MISO 19 -#define RF95_MOSI 27 -#define RF95_NSS 18 +#define LORA_SCK 5 +#define LORA_MISO 19 +#define LORA_MOSI 27 +#define LORA_CS 18 // supported modules list #define USE_RF95 // RFM95/SX127x diff --git a/variants/diy/v1_1/variant.h b/variants/diy/v1_1/variant.h index fd5276ced..8a006d0d2 100644 --- a/variants/diy/v1_1/variant.h +++ b/variants/diy/v1_1/variant.h @@ -22,14 +22,14 @@ #define LORA_RXEN 14 // Input - RF switch RX control, connecting external MCU IO, valid in high level #define LORA_TXEN 13 // Input - RF switch TX control, connecting external MCU IO or DIO2, valid in high level -#undef RF95_SCK -#define RF95_SCK 18 -#undef RF95_MISO -#define RF95_MISO 19 -#undef RF95_MOSI -#define RF95_MOSI 23 -#undef RF95_NSS -#define RF95_NSS 5 +#undef LORA_SCK +#define LORA_SCK 18 +#undef LORA_MISO +#define LORA_MISO 19 +#undef LORA_MOSI +#define LORA_MOSI 23 +#undef LORA_CS +#define LORA_CS 5 // RX/TX for RFM95/SX127x #define RF95_RXEN LORA_RXEN diff --git a/variants/feather_diy/variant.h b/variants/feather_diy/variant.h index 5e889b04e..1c0979f82 100644 --- a/variants/feather_diy/variant.h +++ b/variants/feather_diy/variant.h @@ -81,10 +81,10 @@ extern "C" { #define LORA_DIO2 (0 + 8) // P0.08 12 // BUSY for SX1262/SX1268 #define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262/SX1268, if DIO3 is high the TXCO is enabled -#define RF95_SCK SCK -#define RF95_MISO MI -#define RF95_MOSI MO -#define RF95_NSS SS +#define LORA_SCK SCK +#define LORA_MISO MI +#define LORA_MOSI MO +#define LORA_CS SS // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (-1) @@ -95,7 +95,7 @@ extern "C" { #define USE_SX1262 // common pinouts for SX126X modules -#define SX126X_CS RF95_NSS // NSS for SX126X +#define SX126X_CS LORA_CS // NSS for SX126X #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/heltec_esp32c3/variant.h b/variants/heltec_esp32c3/variant.h index 7d113720d..de6462a38 100644 --- a/variants/heltec_esp32c3/variant.h +++ b/variants/heltec_esp32c3/variant.h @@ -14,22 +14,22 @@ #undef GPS_RX_PIN #undef GPS_TX_PIN -#undef RF95_SCK -#undef RF95_MISO -#undef RF95_MOSI -#undef RF95_NSS +#undef LORA_SCK +#undef LORA_MISO +#undef LORA_MOSI +#undef LORA_CS #define USE_SX1262 -#define RF95_SCK 10 -#define RF95_MISO 6 -#define RF95_MOSI 7 -#define RF95_NSS 8 +#define LORA_SCK 10 +#define LORA_MISO 6 +#define LORA_MOSI 7 +#define LORA_CS 8 #define LORA_DIO0 RADIOLIB_NC #define LORA_RESET 5 #define LORA_DIO1 3 #define LORA_DIO2 RADIOLIB_NC #define LORA_BUSY 4 -#define SX126X_CS RF95_NSS +#define SX126X_CS LORA_CS #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_BUSY #define SX126X_RESET LORA_RESET diff --git a/variants/heltec_v3/variant.h b/variants/heltec_v3/variant.h index 4ce47996b..2532ea682 100644 --- a/variants/heltec_v3/variant.h +++ b/variants/heltec_v3/variant.h @@ -24,12 +24,12 @@ #define LORA_DIO2 13 // SX1262 BUSY #define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled -#define RF95_SCK 9 -#define RF95_MISO 11 -#define RF95_MOSI 10 -#define RF95_NSS 8 +#define LORA_SCK 9 +#define LORA_MISO 11 +#define LORA_MOSI 10 +#define LORA_CS 8 -#define SX126X_CS RF95_NSS +#define SX126X_CS LORA_CS #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/heltec_wireless_paper/variant.h b/variants/heltec_wireless_paper/variant.h index b73596f50..88c5faaa1 100644 --- a/variants/heltec_wireless_paper/variant.h +++ b/variants/heltec_wireless_paper/variant.h @@ -31,12 +31,12 @@ #define LORA_DIO2 13 // SX1262 BUSY #define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled -#define RF95_SCK 9 -#define RF95_MISO 11 -#define RF95_MOSI 10 -#define RF95_NSS 8 +#define LORA_SCK 9 +#define LORA_MISO 11 +#define LORA_MOSI 10 +#define LORA_CS 8 -#define SX126X_CS RF95_NSS +#define SX126X_CS LORA_CS #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/heltec_wireless_tracker/variant.h b/variants/heltec_wireless_tracker/variant.h index 4a1b61038..88b4804a1 100644 --- a/variants/heltec_wireless_tracker/variant.h +++ b/variants/heltec_wireless_tracker/variant.h @@ -58,12 +58,12 @@ #define LORA_DIO2 13 // SX1262 BUSY #define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled -#define RF95_SCK 9 -#define RF95_MISO 11 -#define RF95_MOSI 10 -#define RF95_NSS 8 +#define LORA_SCK 9 +#define LORA_MISO 11 +#define LORA_MOSI 10 +#define LORA_CS 8 -#define SX126X_CS RF95_NSS +#define SX126X_CS LORA_CS #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/heltec_wsl_v3/variant.h b/variants/heltec_wsl_v3/variant.h index 417abf34d..0ad1b8487 100644 --- a/variants/heltec_wsl_v3/variant.h +++ b/variants/heltec_wsl_v3/variant.h @@ -21,12 +21,12 @@ #define LORA_DIO2 13 // SX1262 BUSY #define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled -#define RF95_SCK 9 -#define RF95_MISO 11 -#define RF95_MOSI 10 -#define RF95_NSS 8 +#define LORA_SCK 9 +#define LORA_MISO 11 +#define LORA_MOSI 10 +#define LORA_CS 8 -#define SX126X_CS RF95_NSS +#define SX126X_CS LORA_CS #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/m5stack-stamp-c3/variant.h b/variants/m5stack-stamp-c3/variant.h index 87adbc226..8242ef499 100644 --- a/variants/m5stack-stamp-c3/variant.h +++ b/variants/m5stack-stamp-c3/variant.h @@ -9,18 +9,18 @@ #undef GPS_RX_PIN #undef GPS_TX_PIN -#undef RF95_SCK -#undef RF95_MISO -#undef RF95_MOSI -#undef RF95_NSS +#undef LORA_SCK +#undef LORA_MISO +#undef LORA_MOSI +#undef LORA_CS // Adafruit RFM95W OK // https://www.adafruit.com/product/3072 #define USE_RF95 -#define RF95_SCK 4 -#define RF95_MISO 5 -#define RF95_MOSI 6 -#define RF95_NSS 7 +#define LORA_SCK 4 +#define LORA_MISO 5 +#define LORA_MOSI 6 +#define LORA_CS 7 #define LORA_DIO0 10 #define LORA_RESET 8 #define LORA_DIO1 RADIOLIB_NC @@ -29,16 +29,16 @@ // WaveShare Core1262-868M OK // https://www.waveshare.com/wiki/Core1262-868M // #define USE_SX1262 -// #define RF95_SCK 4 -// #define RF95_MISO 5 -// #define RF95_MOSI 6 -// #define RF95_NSS 7 +// #define LORA_SCK 4 +// #define LORA_MISO 5 +// #define LORA_MOSI 6 +// #define LORA_CS 7 // #define LORA_DIO0 RADIOLIB_NC // #define LORA_RESET 8 // #define LORA_DIO1 10 // #define LORA_DIO2 RADIOLIB_NC // #define LORA_BUSY 18 -// #define SX126X_CS RF95_NSS +// #define SX126X_CS LORA_CS // #define SX126X_DIO1 LORA_DIO1 // #define SX126X_BUSY LORA_BUSY // #define SX126X_RESET LORA_RESET @@ -47,16 +47,16 @@ // SX128X 2.4 Ghz LoRa module Not OK - RadioLib issue ? still to confirm // #define USE_SX1280 -// #define RF95_SCK 4 -// #define RF95_MISO 5 -// #define RF95_MOSI 6 -// #define RF95_NSS 7 +// #define LORA_SCK 4 +// #define LORA_MISO 5 +// #define LORA_MOSI 6 +// #define LORA_CS 7 // #define LORA_DIO0 -1 // #define LORA_DIO1 10 // #define LORA_DIO2 21 // #define LORA_RESET 8 // #define LORA_BUSY 1 -// #define SX128X_CS RF95_NSS +// #define SX128X_CS LORA_CS // #define SX128X_DIO1 LORA_DIO1 // #define SX128X_BUSY LORA_BUSY // #define SX128X_RESET LORA_RESET diff --git a/variants/m5stack_core/variant.h b/variants/m5stack_core/variant.h index c671d77fa..72aeb160e 100644 --- a/variants/m5stack_core/variant.h +++ b/variants/m5stack_core/variant.h @@ -12,15 +12,15 @@ #define PIN_BUZZER 25 -#undef RF95_SCK -#undef RF95_MISO -#undef RF95_MOSI -#undef RF95_NSS +#undef LORA_SCK +#undef LORA_MISO +#undef LORA_MOSI +#undef LORA_CS -#define RF95_SCK 18 -#define RF95_MISO 19 -#define RF95_MOSI 23 -#define RF95_NSS 5 +#define LORA_SCK 18 +#define LORA_MISO 19 +#define LORA_MOSI 23 +#define LORA_CS 5 #define USE_RF95 #define LORA_DIO0 36 // a No connect on the SX1262 module diff --git a/variants/m5stack_coreink/variant.h b/variants/m5stack_coreink/variant.h index 90ce41334..0fc56477c 100644 --- a/variants/m5stack_coreink/variant.h +++ b/variants/m5stack_coreink/variant.h @@ -34,18 +34,18 @@ // BUZZER #define PIN_BUZZER 2 -#undef RF95_SCK -#undef RF95_MISO -#undef RF95_MOSI -#undef RF95_NSS +#undef LORA_SCK +#undef LORA_MISO +#undef LORA_MOSI +#undef LORA_CS #define USE_RF95 // #define USE_SX1280 #ifdef USE_RF95 -#define RF95_SCK 18 -#define RF95_MISO 34 -#define RF95_MOSI 23 -#define RF95_NSS 14 +#define LORA_SCK 18 +#define LORA_MISO 34 +#define LORA_MOSI 23 +#define LORA_CS 14 #define LORA_DIO0 25 #define LORA_RESET 26 #define LORA_DIO1 RADIOLIB_NC @@ -53,14 +53,14 @@ #endif #ifdef USE_SX1280 -#define RF95_SCK 18 -#define RF95_MISO 34 -#define RF95_MOSI 23 -#define RF95_NSS 14 +#define LORA_SCK 18 +#define LORA_MISO 34 +#define LORA_MOSI 23 +#define LORA_CS 14 #define LORA_RESET 26 #define LORA_DIO1 25 #define LORA_DIO2 13 -#define SX128X_CS RF95_NSS +#define SX128X_CS LORA_CS #define SX128X_DIO1 LORA_DIO1 #define SX128X_BUSY LORA_DIO2 #define SX128X_RESET LORA_RESET diff --git a/variants/my_esp32s3_diy_eink/variant.h b/variants/my_esp32s3_diy_eink/variant.h index 7e4fe2756..a5bebdacc 100644 --- a/variants/my_esp32s3_diy_eink/variant.h +++ b/variants/my_esp32s3_diy_eink/variant.h @@ -20,16 +20,16 @@ // #define USE_SX1262 #define USE_SX1280 -#define RF95_MISO 3 -#define RF95_SCK 5 -#define RF95_MOSI 6 -#define RF95_NSS 7 +#define LORA_MISO 3 +#define LORA_SCK 5 +#define LORA_MOSI 6 +#define LORA_CS 7 #define LORA_RESET 8 #define LORA_DIO1 16 #ifdef USE_SX1262 -#define SX126X_CS RF95_NSS // FIXME - we really should define LORA_CS instead +#define SX126X_CS LORA_CS // FIXME - we really should define LORA_CS instead #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY 15 #define SX126X_RESET LORA_RESET @@ -38,7 +38,7 @@ #endif #ifdef USE_SX1280 -#define SX128X_CS RF95_NSS +#define SX128X_CS LORA_CS #define SX128X_DIO1 LORA_DIO1 #define SX128X_BUSY 15 #define SX128X_RESET LORA_RESET diff --git a/variants/my_esp32s3_diy_oled/variant.h b/variants/my_esp32s3_diy_oled/variant.h index bb9657c5b..6dd18c236 100644 --- a/variants/my_esp32s3_diy_oled/variant.h +++ b/variants/my_esp32s3_diy_oled/variant.h @@ -20,16 +20,16 @@ // #define USE_SX1262 #define USE_SX1280 -#define RF95_MISO 3 -#define RF95_SCK 5 -#define RF95_MOSI 6 -#define RF95_NSS 7 +#define LORA_MISO 3 +#define LORA_SCK 5 +#define LORA_MOSI 6 +#define LORA_CS 7 #define LORA_RESET 8 #define LORA_DIO1 16 #ifdef USE_SX1262 -#define SX126X_CS RF95_NSS // FIXME - we really should define LORA_CS instead +#define SX126X_CS LORA_CS // FIXME - we really should define LORA_CS instead #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY 15 #define SX126X_RESET LORA_RESET @@ -38,7 +38,7 @@ #endif #ifdef USE_SX1280 -#define SX128X_CS RF95_NSS +#define SX128X_CS LORA_CS #define SX128X_DIO1 LORA_DIO1 #define SX128X_BUSY 15 #define SX128X_RESET LORA_RESET diff --git a/variants/nano-g1-explorer/variant.h b/variants/nano-g1-explorer/variant.h index 71dd49f05..3d5d71acc 100644 --- a/variants/nano-g1-explorer/variant.h +++ b/variants/nano-g1-explorer/variant.h @@ -23,7 +23,7 @@ #define LORA_DIO3 // Not connected on PCB #ifdef USE_SX1262 -#define SX126X_CS RF95_NSS // FIXME - we really should define LORA_CS instead +#define SX126X_CS LORA_CS // FIXME - we really should define LORA_CS instead #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/nano-g1/variant.h b/variants/nano-g1/variant.h index 5ceb96f0c..dd8355492 100644 --- a/variants/nano-g1/variant.h +++ b/variants/nano-g1/variant.h @@ -23,7 +23,7 @@ #define LORA_DIO3 // Not connected on PCB #ifdef USE_SX1262 -#define SX126X_CS RF95_NSS // FIXME - we really should define LORA_CS instead +#define SX126X_CS LORA_CS // FIXME - we really should define LORA_CS instead #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/picomputer-s3/variant.h b/variants/picomputer-s3/variant.h index 732be4bcf..fc746c599 100644 --- a/variants/picomputer-s3/variant.h +++ b/variants/picomputer-s3/variant.h @@ -15,10 +15,10 @@ #define USE_RF95 // RFM95/SX127x -#define RF95_SCK SCK // 21 -#define RF95_MISO MISO // 39 -#define RF95_MOSI MOSI // 38 -#define RF95_NSS SS // 40 +#define LORA_SCK SCK // 21 +#define LORA_MISO MISO // 39 +#define LORA_MOSI MOSI // 38 +#define LORA_CS SS // 40 #define LORA_RESET RADIOLIB_NC // per SX1276_Receive_Interrupt/utilities.h diff --git a/variants/portduino/variant.h b/variants/portduino/variant.h index 46f7d1f0c..8e1c0b1f2 100644 --- a/variants/portduino/variant.h +++ b/variants/portduino/variant.h @@ -9,10 +9,10 @@ #define USE_SX1262 // Fake SPI device selections -#define RF95_SCK 5 -#define RF95_MISO 19 -#define RF95_MOSI 27 -#define RF95_NSS RADIOLIB_NC // the ch341f spi controller does CS for us +#define LORA_SCK 5 +#define LORA_MISO 19 +#define LORA_MOSI 27 +#define LORA_CS RADIOLIB_NC // the ch341f spi controller does CS for us #define LORA_DIO0 26 // a No connect on the SX1262 module #define LORA_RESET 14 diff --git a/variants/rak11200/variant.h b/variants/rak11200/variant.h index b6d9c4229..007ed8f15 100644 --- a/variants/rak11200/variant.h +++ b/variants/rak11200/variant.h @@ -66,14 +66,14 @@ static const uint8_t SCK = 33; #define LORA_DIO3 \ RADIOLIB_NC // Not connected on PCB, but internally on the TTGO SX1262/SX1268, if DIO3 is high the TXCO is enabled -#undef RF95_SCK -#define RF95_SCK SCK -#undef RF95_MISO -#define RF95_MISO MISO -#undef RF95_MOSI -#define RF95_MOSI MOSI -#undef RF95_NSS -#define RF95_NSS SS +#undef LORA_SCK +#define LORA_SCK SCK +#undef LORA_MISO +#define LORA_MISO MISO +#undef LORA_MOSI +#define LORA_MOSI MOSI +#undef LORA_CS +#define LORA_CS SS #define USE_SX1262 #define SX126X_CS SS // NSS for SX126X diff --git a/variants/rak11310/variant.h b/variants/rak11310/variant.h index acc21ce99..6334157f5 100644 --- a/variants/rak11310/variant.h +++ b/variants/rak11310/variant.h @@ -19,17 +19,17 @@ #define USE_SX1262 -#undef RF95_SCK -#undef RF95_MISO -#undef RF95_MOSI -#undef RF95_NSS +#undef LORA_SCK +#undef LORA_MISO +#undef LORA_MOSI +#undef LORA_CS // RAK BSP somehow uses SPI1 instead of SPI0 #define HW_SPI1_DEVICE -#define RF95_SCK PIN_SPI0_SCK -#define RF95_MOSI PIN_SPI0_MOSI -#define RF95_MISO PIN_SPI0_MISO -#define RF95_NSS PIN_SPI0_SS +#define LORA_SCK PIN_SPI0_SCK +#define LORA_MOSI PIN_SPI0_MOSI +#define LORA_MISO PIN_SPI0_MISO +#define LORA_CS PIN_SPI0_SS #define LORA_DIO0 RADIOLIB_NC #define LORA_RESET 14 @@ -38,7 +38,7 @@ #define LORA_DIO3 RADIOLIB_NC #ifdef USE_SX1262 -#define SX126X_CS RF95_NSS +#define SX126X_CS LORA_CS #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/rpipico/variant.h b/variants/rpipico/variant.h index be26099de..aeda3d833 100644 --- a/variants/rpipico/variant.h +++ b/variants/rpipico/variant.h @@ -25,15 +25,15 @@ #define USE_SX1262 -#undef RF95_SCK -#undef RF95_MISO -#undef RF95_MOSI -#undef RF95_NSS +#undef LORA_SCK +#undef LORA_MISO +#undef LORA_MOSI +#undef LORA_CS -#define RF95_SCK 10 -#define RF95_MISO 12 -#define RF95_MOSI 11 -#define RF95_NSS 3 +#define LORA_SCK 10 +#define LORA_MISO 12 +#define LORA_MOSI 11 +#define LORA_CS 3 #define LORA_DIO0 RADIOLIB_NC #define LORA_RESET 15 @@ -42,7 +42,7 @@ #define LORA_DIO3 RADIOLIB_NC #ifdef USE_SX1262 -#define SX126X_CS RF95_NSS +#define SX126X_CS LORA_CS #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/rpipicow/variant.h b/variants/rpipicow/variant.h index 77cb1ffd6..abbd1c465 100644 --- a/variants/rpipicow/variant.h +++ b/variants/rpipicow/variant.h @@ -23,15 +23,15 @@ #define USE_SX1262 -#undef RF95_SCK -#undef RF95_MISO -#undef RF95_MOSI -#undef RF95_NSS +#undef LORA_SCK +#undef LORA_MISO +#undef LORA_MOSI +#undef LORA_CS -#define RF95_SCK 10 -#define RF95_MISO 12 -#define RF95_MOSI 11 -#define RF95_NSS 3 +#define LORA_SCK 10 +#define LORA_MISO 12 +#define LORA_MOSI 11 +#define LORA_CS 3 #define LORA_DIO0 RADIOLIB_NC #define LORA_RESET 15 @@ -40,7 +40,7 @@ #define LORA_DIO3 RADIOLIB_NC #ifdef USE_SX1262 -#define SX126X_CS RF95_NSS +#define SX126X_CS LORA_CS #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/station-g1/variant.h b/variants/station-g1/variant.h index 79a49fc96..e58853fb7 100644 --- a/variants/station-g1/variant.h +++ b/variants/station-g1/variant.h @@ -23,7 +23,7 @@ #define LORA_DIO3 // Not connected on PCB #ifdef USE_SX1262 -#define SX126X_CS RF95_NSS // FIXME - we really should define LORA_CS instead +#define SX126X_CS LORA_CS // FIXME - we really should define LORA_CS instead #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/t-deck/variant.h b/variants/t-deck/variant.h index b1673d338..446e22732 100644 --- a/variants/t-deck/variant.h +++ b/variants/t-deck/variant.h @@ -69,10 +69,10 @@ #define USE_SX1262 #define USE_SX1268 -#define RF95_SCK 40 -#define RF95_MISO 38 -#define RF95_MOSI 41 -#define RF95_NSS 9 +#define LORA_SCK 40 +#define LORA_MISO 38 +#define LORA_MOSI 41 +#define LORA_CS 9 #define LORA_DIO0 -1 // a No connect on the SX1262 module #define LORA_RESET 17 @@ -80,7 +80,7 @@ #define LORA_DIO2 13 // SX1262 BUSY #define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled -#define SX126X_CS RF95_NSS // FIXME - we really should define LORA_CS instead +#define SX126X_CS LORA_CS // FIXME - we really should define LORA_CS instead #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/t-watch-s3/variant.h b/variants/t-watch-s3/variant.h index c87845afa..c30224034 100644 --- a/variants/t-watch-s3/variant.h +++ b/variants/t-watch-s3/variant.h @@ -48,10 +48,10 @@ #define USE_SX1262 #define USE_SX1268 -#define RF95_SCK 3 -#define RF95_MISO 4 -#define RF95_MOSI 1 -#define RF95_NSS 5 +#define LORA_SCK 3 +#define LORA_MISO 4 +#define LORA_MOSI 1 +#define LORA_CS 5 #define LORA_DIO0 -1 // a No connect on the SX1262 module #define LORA_RESET 8 @@ -59,7 +59,7 @@ #define LORA_DIO2 7 // SX1262 BUSY #define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled -#define SX126X_CS RF95_NSS // FIXME - we really should define LORA_CS instead +#define SX126X_CS LORA_CS // FIXME - we really should define LORA_CS instead #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/tbeam-s3-core/variant.h b/variants/tbeam-s3-core/variant.h index 5e9894cc6..0fa9f8fe8 100644 --- a/variants/tbeam-s3-core/variant.h +++ b/variants/tbeam-s3-core/variant.h @@ -47,10 +47,10 @@ #define PMU_USE_WIRE1 #define RTC_USE_WIRE1 -#define RF95_SCK 12 -#define RF95_MISO 13 -#define RF95_MOSI 11 -#define RF95_NSS 10 +#define LORA_SCK 12 +#define LORA_MISO 13 +#define LORA_MOSI 11 +#define LORA_CS 10 #define GPS_RX_PIN 9 #define GPS_TX_PIN 8 diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index a0ba70bfd..d237f542b 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -24,7 +24,7 @@ #define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled #ifdef USE_SX1262 -#define SX126X_CS RF95_NSS // FIXME - we really should define LORA_CS instead +#define SX126X_CS LORA_CS // FIXME - we really should define LORA_CS instead #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET diff --git a/variants/tlora_t3s3_v1/variant.h b/variants/tlora_t3s3_v1/variant.h index 6e1d1d0eb..8a1af1ec2 100644 --- a/variants/tlora_t3s3_v1/variant.h +++ b/variants/tlora_t3s3_v1/variant.h @@ -25,10 +25,10 @@ #define USE_SX1262 #define USE_SX1280 -#define RF95_SCK 5 -#define RF95_MISO 3 -#define RF95_MOSI 6 -#define RF95_NSS 7 +#define LORA_SCK 5 +#define LORA_MISO 3 +#define LORA_MOSI 6 +#define LORA_CS 7 #define LORA_RESET 8 // per SX1276_Receive_Interrupt/utilities.h @@ -40,7 +40,7 @@ // per SX1262_Receive_Interrupt/utilities.h #ifdef USE_SX1262 -#define SX126X_CS RF95_NSS +#define SX126X_CS LORA_CS #define SX126X_DIO1 33 #define SX126X_BUSY 34 #define SX126X_RESET LORA_RESET @@ -50,7 +50,7 @@ // per SX128x_Receive_Interrupt/utilities.h #ifdef USE_SX1280 -#define SX128X_CS RF95_NSS +#define SX128X_CS LORA_CS #define SX128X_DIO1 9 #define SX128X_DIO2 33 #define SX128X_DIO3 34 From 102efd49548e5c1c6673da2c4b462692544ebee2 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 26 Nov 2023 15:08:20 -0600 Subject: [PATCH 36/52] Move to portduino GPIO, adding user button support --- bin/config-dist.yaml | 5 +++ src/ButtonThread.h | 28 ++++++++++++- src/main.cpp | 8 ++-- src/platform/portduino/PiHal.h | 31 ++++---------- src/platform/portduino/PortduinoGlue.cpp | 52 +++++++++++++++++++++++- src/platform/portduino/PortduinoGlue.h | 3 +- 6 files changed, 96 insertions(+), 31 deletions(-) diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 6c8f1946f..d6cf8f878 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -24,3 +24,8 @@ Lora: # Reset: 22 # CS: 7 # IRQ: 25 + +# Define GPIO buttons here: + +GPIO: +# User: 6 diff --git a/src/ButtonThread.h b/src/ButtonThread.h index a8a89e82e..2ca5d4c28 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -36,6 +36,9 @@ class ButtonThread : public concurrency::OSThread #endif #ifdef BUTTON_PIN_TOUCH OneButton userButtonTouch; +#endif +#if defined(ARCH_RASPBERRY_PI) + OneButton userButton; #endif static bool shutdown_on_long_stop; @@ -45,8 +48,13 @@ class ButtonThread : public concurrency::OSThread // callback returns the period for the next callback invocation (or 0 if we should no longer be called) ButtonThread() : OSThread("Button") { -#ifdef BUTTON_PIN +#if defined(ARCH_RASPBERRY_PI) + if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) + userButton = OneButton(settingsMap[user], true, true); +#elif defined(BUTTON_PIN) + userButton = OneButton(config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN, true, true); +#endif #ifdef INPUT_PULLUP_SENSE // Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did pinMode(config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN, INPUT_PULLUP_SENSE); @@ -58,6 +66,10 @@ class ButtonThread : public concurrency::OSThread userButton.attachMultiClick(userButtonMultiPressed); userButton.attachLongPressStart(userButtonPressedLongStart); userButton.attachLongPressStop(userButtonPressedLongStop); +#if defined(ARCH_RASPBERRY_PI) + if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) + wakeOnIrq(settingsMap[user], FALLING); +#else wakeOnIrq(config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN, FALLING); #endif #ifdef BUTTON_PIN_ALT @@ -87,9 +99,14 @@ class ButtonThread : public concurrency::OSThread { canSleep = true; // Assume we should not keep the board awake -#ifdef BUTTON_PIN +#if defined(BUTTON_PIN) userButton.tick(); canSleep &= userButton.isIdle(); +#elif defined(ARCH_RASPBERRY_PI) + if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) { + userButton.tick(); + canSleep &= userButton.isIdle(); + } #endif #ifdef BUTTON_PIN_ALT userButtonAlt.tick(); @@ -121,6 +138,13 @@ class ButtonThread : public concurrency::OSThread !moduleConfig.canned_message.enabled) { powerFSM.trigger(EVENT_PRESS); } +#endif +#if defined(ARCH_RASPBERRY_PI) + if ((settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) && + (settingsMap[user] != moduleConfig.canned_message.inputbroker_pin_press) || + !moduleConfig.canned_message.enabled) { + powerFSM.trigger(EVENT_PRESS); + } #endif } static void userButtonPressedLong() diff --git a/src/main.cpp b/src/main.cpp index 4913f1091..b8432c5ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,7 +75,7 @@ NRF52Bluetooth *nrf52Bluetooth; #include #endif -#if HAS_BUTTON +#if HAS_BUTTON || defined(ARCH_RASPBERRY_PI) #include "ButtonThread.h" #endif #include "PowerFSMThread.h" @@ -206,13 +206,13 @@ static int32_t ledBlinker() uint32_t timeLastPowered = 0; -#if HAS_BUTTON +#if HAS_BUTTON || defined(ARCH_RASPBERRY_PI) bool ButtonThread::shutdown_on_long_stop = false; #endif static Periodic *ledPeriodic; static OSThread *powerFSMthread; -#if HAS_BUTTON +#if HAS_BUTTON || defined(ARCH_RASPBERRY_PI) static OSThread *buttonThread; uint32_t ButtonThread::longPressTime = 0; #endif @@ -583,7 +583,7 @@ void setup() else router = new ReliableRouter(); -#if HAS_BUTTON +#if HAS_BUTTON || defined(ARCH_RASPBERRY_PI) // Buttons. Moved here cause we need NodeDB to be initialized buttonThread = new ButtonThread(); #endif diff --git a/src/platform/portduino/PiHal.h b/src/platform/portduino/PiHal.h index f10040583..d80009450 100644 --- a/src/platform/portduino/PiHal.h +++ b/src/platform/portduino/PiHal.h @@ -7,6 +7,8 @@ // include the library for Raspberry GPIO pins #include "pigpio.h" +#include "linux/gpio/LinuxGPIOPin.h" + // create a new Raspberry Pi hardware abstraction layer // using the pigpio library // the HAL must inherit from the base RadioLibHal class @@ -54,8 +56,7 @@ class PiHal : public RadioLibHal if (pin == RADIOLIB_NC) { return; } - - gpioSetMode(pin, mode); + ::pinMode(pin, RADIOLIB_ARDUINOHAL_PIN_MODE_CAST mode); } void digitalWrite(uint32_t pin, uint32_t value) override @@ -63,8 +64,7 @@ class PiHal : public RadioLibHal if (pin == RADIOLIB_NC) { return; } - - gpioWrite(pin, value); + ::digitalWrite(pin, RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST value); } uint32_t digitalRead(uint32_t pin) override @@ -73,7 +73,7 @@ class PiHal : public RadioLibHal return (0); } - return (gpioRead(pin)); + return (::digitalRead(pin)); } void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) override @@ -81,11 +81,7 @@ class PiHal : public RadioLibHal if (interruptNum == RADIOLIB_NC) { return; } - if (gpioRead(interruptNum) == 1) { - interruptCb(); - } else { - gpioSetAlertFunc(interruptNum, (gpioISRFunc_t)interruptCb); - } + ::attachInterrupt(interruptNum, interruptCb, RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST mode); } void detachInterrupt(uint32_t interruptNum) override @@ -94,7 +90,7 @@ class PiHal : public RadioLibHal return; } - gpioSetAlertFunc(interruptNum, NULL); + ::detachInterrupt(interruptNum); } void delay(unsigned long ms) override { gpioDelay(ms * 1000); } @@ -111,19 +107,8 @@ class PiHal : public RadioLibHal return (0); } - this->pinMode(pin, PI_INPUT); - uint32_t start = this->micros(); - uint32_t curtick = this->micros(); - - while (this->digitalRead(pin) == state) { - if ((this->micros() - curtick) > timeout) { - return (0); - } - } - - return (this->micros() - start); + return (::pulseIn(pin, state, timeout)); } - void spiBegin() { if (_spiHandle < 0) { diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index d2a00e1e1..f7389431b 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -10,6 +10,7 @@ #ifdef ARCH_RASPBERRY_PI #include "PortduinoGlue.h" +#include "linux/gpio/LinuxGPIOPin.h" #include "pigpio.h" #include "yaml-cpp/yaml.h" #include @@ -101,6 +102,7 @@ void portduinoSetup() printf("Setting up Meshtastic on Portduino...\n"); #ifdef ARCH_RASPBERRY_PI + gpioInit(); YAML::Node yamlConfig; if (access("config.yaml", R_OK) == 0) { @@ -138,6 +140,9 @@ void portduinoSetup() settingsMap[busy] = yamlConfig["Lora"]["Busy"].as(RADIOLIB_NC); settingsMap[reset] = yamlConfig["Lora"]["Reset"].as(RADIOLIB_NC); } + if (yamlConfig["GPIO"]) { + settingsMap[user] = yamlConfig["GPIO"]["User"].as(RADIOLIB_NC); + } } catch (YAML::Exception e) { std::cout << "*** Exception " << e.what() << std::endl; @@ -147,6 +152,34 @@ void portduinoSetup() std::cout << "Cannot read Bluetooth MAC Address. Please run as root" << std::endl; exit(EXIT_FAILURE); } + + // Need to bind all the configured GPIO pins so they're not simulated + if (settingsMap.count(cs) > 0 && settingsMap[cs] != RADIOLIB_NC) { + if (initGPIOPin(settingsMap[cs]) != ERRNO_OK) { + settingsMap[cs] = RADIOLIB_NC; + } + } + if (settingsMap.count(irq) > 0 && settingsMap[irq] != RADIOLIB_NC) { + if (initGPIOPin(settingsMap[irq]) != ERRNO_OK) { + settingsMap[irq] = RADIOLIB_NC; + } + } + if (settingsMap.count(busy) > 0 && settingsMap[busy] != RADIOLIB_NC) { + if (initGPIOPin(settingsMap[busy]) != ERRNO_OK) { + settingsMap[busy] = RADIOLIB_NC; + } + } + if (settingsMap.count(reset) > 0 && settingsMap[reset] != RADIOLIB_NC) { + if (initGPIOPin(settingsMap[reset]) != ERRNO_OK) { + settingsMap[reset] = RADIOLIB_NC; + } + } + if (settingsMap.count(user) > 0 && settingsMap[user] != RADIOLIB_NC) { + if (initGPIOPin(settingsMap[user]) != ERRNO_OK) { + settingsMap[user] = RADIOLIB_NC; + } + } + return; #endif @@ -194,4 +227,21 @@ void portduinoSetup() // gpioBind((new SimGPIOPin(LORA_RESET, "LORA_RESET"))); // gpioBind((new SimGPIOPin(LORA_CS, "LORA_CS"))->setSilent()); #endif -} \ No newline at end of file +} + +#ifdef ARCH_RASPBERRY_PI +int initGPIOPin(int pinNum) +{ + std::string gpio_name = "GPIO" + std::to_string(pinNum); + try { + GPIOPin *csPin; + csPin = new LinuxGPIOPin(pinNum, "gpiochip0", pinNum, gpio_name.c_str()); + csPin->setSilent(); + gpioBind(csPin); + return ERRNO_OK; + } catch (std::invalid_argument &e) { + std::cout << "Warning, cannot claim pin" << gpio_name << std::endl; + return ERRNO_DISABLED; + } +} +#endif \ No newline at end of file diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index 7dc563038..7544a0853 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -4,6 +4,7 @@ extern std::map settingsMap; -enum { use_sx1262, cs, irq, busy, reset, dio2_as_rf_switch, use_rf95 }; +enum { use_sx1262, cs, irq, busy, reset, dio2_as_rf_switch, use_rf95, user }; +int initGPIOPin(int pinNum); #endif \ No newline at end of file From d3e64350d9ebe413b0380d066843c63f1b76b809 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 26 Nov 2023 20:29:01 -0600 Subject: [PATCH 37/52] Remove RADIOLIB_SPI_PARANOID compile option, as it does nothing --- platformio.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index cb79565f1..451fe3f1a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -93,7 +93,7 @@ lib_deps = end2endzone/NonBlockingRTTTL@^1.3.0 https://github.com/meshtastic/SparkFun_ATECCX08a_Arduino_Library.git#5cf62b36c6f30bc72a07bdb2c11fc9a22d1e31da -build_flags = ${env.build_flags} -Os -DRADIOLIB_SPI_PARANOID=0 +build_flags = ${env.build_flags} -Os build_src_filter = ${env.build_src_filter} - ; Common libs for communicating over TCP/IP networks such as MQTT @@ -123,4 +123,4 @@ lib_deps = adafruit/Adafruit PM25 AQI Sensor@^1.0.6 adafruit/Adafruit MPU6050@^2.2.4 adafruit/Adafruit LIS3DH@^1.2.4 - https://github.com/lewisxhe/BMA423_Library@^0.0.1 \ No newline at end of file + https://github.com/lewisxhe/BMA423_Library@^0.0.1 From d10b1e1d00034b1d80ea063a110f6651b47e9a11 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 26 Nov 2023 20:31:52 -0600 Subject: [PATCH 38/52] Add better error reporting for RF95 init failure --- src/mesh/RadioLibRF95.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mesh/RadioLibRF95.cpp b/src/mesh/RadioLibRF95.cpp index 0fa6c7fe8..eca2509aa 100644 --- a/src/mesh/RadioLibRF95.cpp +++ b/src/mesh/RadioLibRF95.cpp @@ -14,8 +14,10 @@ int16_t RadioLibRF95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_ { // execute common part int16_t state = SX127x::begin(RF95_CHIP_VERSION, syncWord, preambleLength); - if (state != RADIOLIB_ERR_NONE) + if (state != RADIOLIB_ERR_NONE) { + LOG_WARN("Initial probe for RF95 failed with %d, trying again with alternative hardware version\n", state); state = SX127x::begin(RF95_ALT_VERSION, syncWord, preambleLength); + } RADIOLIB_ASSERT(state); // current limit was removed from module' ctor @@ -80,4 +82,4 @@ bool RadioLibRF95::isReceiving() uint8_t RadioLibRF95::readReg(uint8_t addr) { return mod->SPIreadRegister(addr); -} \ No newline at end of file +} From 1ca29236580c3994eb7fc623edec599759b0fb76 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 26 Nov 2023 20:41:22 -0600 Subject: [PATCH 39/52] Fix missed #if defined() logic --- src/ButtonThread.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 2ca5d4c28..a60b7730a 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -48,6 +48,7 @@ class ButtonThread : public concurrency::OSThread // callback returns the period for the next callback invocation (or 0 if we should no longer be called) ButtonThread() : OSThread("Button") { +#if defined(ARCH_RASPBERRY_PI) || defined(BUTTON_PIN) #if defined(ARCH_RASPBERRY_PI) if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) userButton = OneButton(settingsMap[user], true, true); @@ -72,6 +73,7 @@ class ButtonThread : public concurrency::OSThread #else wakeOnIrq(config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN, FALLING); #endif +#endif #ifdef BUTTON_PIN_ALT userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); #ifdef INPUT_PULLUP_SENSE @@ -223,4 +225,4 @@ class ButtonThread : public concurrency::OSThread } }; -} // namespace concurrency \ No newline at end of file +} // namespace concurrency From 57227c0f85f82c955c9a8ce30890f59a38a3ef77 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 26 Nov 2023 21:29:19 -0600 Subject: [PATCH 40/52] Add gpiochip setting --- bin/config-dist.yaml | 4 ++++ src/platform/portduino/PortduinoGlue.cpp | 18 +++++++++++------- src/platform/portduino/PortduinoGlue.h | 4 ++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index d6cf8f878..43360eb2e 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -25,6 +25,10 @@ Lora: # CS: 7 # IRQ: 25 +# Set gpio chip to use in /dev/. Defaults to 0. +# Notably the Raspberry Pi 5 puts the GPIO header on gpiochip4 +# gpiochip: 4 + # Define GPIO buttons here: GPIO: diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index f7389431b..54d633530 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -103,6 +103,8 @@ void portduinoSetup() #ifdef ARCH_RASPBERRY_PI gpioInit(); + + std::string gpioChipName = "gpiochip"; YAML::Node yamlConfig; if (access("config.yaml", R_OK) == 0) { @@ -139,6 +141,8 @@ void portduinoSetup() settingsMap[irq] = yamlConfig["Lora"]["IRQ"].as(RADIOLIB_NC); settingsMap[busy] = yamlConfig["Lora"]["Busy"].as(RADIOLIB_NC); settingsMap[reset] = yamlConfig["Lora"]["Reset"].as(RADIOLIB_NC); + settingsMap[gpiochip] = yamlConfig["Lora"]["gpiochip"].as(0); + gpioChipName += std::to_string(settingsMap[gpiochip]); } if (yamlConfig["GPIO"]) { settingsMap[user] = yamlConfig["GPIO"]["User"].as(RADIOLIB_NC); @@ -155,27 +159,27 @@ void portduinoSetup() // Need to bind all the configured GPIO pins so they're not simulated if (settingsMap.count(cs) > 0 && settingsMap[cs] != RADIOLIB_NC) { - if (initGPIOPin(settingsMap[cs]) != ERRNO_OK) { + if (initGPIOPin(settingsMap[cs], gpioChipName) != ERRNO_OK) { settingsMap[cs] = RADIOLIB_NC; } } if (settingsMap.count(irq) > 0 && settingsMap[irq] != RADIOLIB_NC) { - if (initGPIOPin(settingsMap[irq]) != ERRNO_OK) { + if (initGPIOPin(settingsMap[irq], gpioChipName) != ERRNO_OK) { settingsMap[irq] = RADIOLIB_NC; } } if (settingsMap.count(busy) > 0 && settingsMap[busy] != RADIOLIB_NC) { - if (initGPIOPin(settingsMap[busy]) != ERRNO_OK) { + if (initGPIOPin(settingsMap[busy], gpioChipName) != ERRNO_OK) { settingsMap[busy] = RADIOLIB_NC; } } if (settingsMap.count(reset) > 0 && settingsMap[reset] != RADIOLIB_NC) { - if (initGPIOPin(settingsMap[reset]) != ERRNO_OK) { + if (initGPIOPin(settingsMap[reset], gpioChipName) != ERRNO_OK) { settingsMap[reset] = RADIOLIB_NC; } } if (settingsMap.count(user) > 0 && settingsMap[user] != RADIOLIB_NC) { - if (initGPIOPin(settingsMap[user]) != ERRNO_OK) { + if (initGPIOPin(settingsMap[user], gpioChipName) != ERRNO_OK) { settingsMap[user] = RADIOLIB_NC; } } @@ -230,12 +234,12 @@ void portduinoSetup() } #ifdef ARCH_RASPBERRY_PI -int initGPIOPin(int pinNum) +int initGPIOPin(int pinNum, std::string gpioChipName) { std::string gpio_name = "GPIO" + std::to_string(pinNum); try { GPIOPin *csPin; - csPin = new LinuxGPIOPin(pinNum, "gpiochip0", pinNum, gpio_name.c_str()); + csPin = new LinuxGPIOPin(pinNum, gpioChipName.c_str(), pinNum, gpio_name.c_str()); csPin->setSilent(); gpioBind(csPin); return ERRNO_OK; diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index 7544a0853..ac356607f 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -4,7 +4,7 @@ extern std::map settingsMap; -enum { use_sx1262, cs, irq, busy, reset, dio2_as_rf_switch, use_rf95, user }; -int initGPIOPin(int pinNum); +enum { use_sx1262, cs, irq, busy, reset, dio2_as_rf_switch, use_rf95, user, gpiochip }; +int initGPIOPin(int pinNum, std::string gpioChipname); #endif \ No newline at end of file From ce8342d3e528692849854e0eca4f55ff93c7f761 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 26 Nov 2023 21:30:08 -0600 Subject: [PATCH 41/52] Drop Pi HAL --- src/main.cpp | 5 +- src/platform/portduino/PiHal.h | 140 --------------------------------- 2 files changed, 2 insertions(+), 143 deletions(-) delete mode 100644 src/platform/portduino/PiHal.h diff --git a/src/main.cpp b/src/main.cpp index b8432c5ad..83f3b721e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,7 +68,6 @@ NRF52Bluetooth *nrf52Bluetooth; #endif #ifdef ARCH_RASPBERRY_PI -#include "platform/portduino/PiHal.h" #include "platform/portduino/PortduinoGlue.h" #include #include @@ -693,7 +692,7 @@ void setup() #ifdef ARCH_RASPBERRY_PI if (settingsMap[use_sx1262]) { if (!rIf) { - PiHal *RadioLibHAL = new PiHal(1); + LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], settingsMap[busy]); if (!rIf->init()) { @@ -706,7 +705,7 @@ void setup() } } else if (settingsMap[use_rf95]) { if (!rIf) { - PiHal *RadioLibHAL = new PiHal(1); + LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], settingsMap[busy]); if (!rIf->init()) { diff --git a/src/platform/portduino/PiHal.h b/src/platform/portduino/PiHal.h deleted file mode 100644 index d80009450..000000000 --- a/src/platform/portduino/PiHal.h +++ /dev/null @@ -1,140 +0,0 @@ -#ifndef PI_HAL_H -#define PI_HAL_H - -// include RadioLib -#include - -// include the library for Raspberry GPIO pins -#include "pigpio.h" - -#include "linux/gpio/LinuxGPIOPin.h" - -// create a new Raspberry Pi hardware abstraction layer -// using the pigpio library -// the HAL must inherit from the base RadioLibHal class -// and implement all of its virtual methods -class PiHal : public RadioLibHal -{ - public: - // default constructor - initializes the base HAL and any needed private members - PiHal(uint8_t spiChannel, uint32_t spiSpeed = 2000000) - : RadioLibHal(PI_INPUT, PI_OUTPUT, PI_LOW, PI_HIGH, RISING_EDGE, FALLING_EDGE), _spiChannel(spiChannel), - _spiSpeed(spiSpeed) - { - } - - void init() override - { - // first initialise pigpio library - gpioInitialise(); - - // now the SPI - spiBegin(); - - // Waveshare LoRaWAN Hat also needs pin 18 to be pulled high to enable the radio - // gpioSetMode(18, PI_OUTPUT); - // gpioWrite(18, PI_HIGH); - } - - void term() override - { - // stop the SPI - spiEnd(); - - // pull the enable pin low - // gpioSetMode(18, PI_OUTPUT); - // gpioWrite(18, PI_LOW); - - // finally, stop the pigpio library - gpioTerminate(); - } - - // GPIO-related methods (pinMode, digitalWrite etc.) should check - // RADIOLIB_NC as an alias for non-connected pins - void pinMode(uint32_t pin, uint32_t mode) override - { - if (pin == RADIOLIB_NC) { - return; - } - ::pinMode(pin, RADIOLIB_ARDUINOHAL_PIN_MODE_CAST mode); - } - - void digitalWrite(uint32_t pin, uint32_t value) override - { - if (pin == RADIOLIB_NC) { - return; - } - ::digitalWrite(pin, RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST value); - } - - uint32_t digitalRead(uint32_t pin) override - { - if (pin == RADIOLIB_NC) { - return (0); - } - - return (::digitalRead(pin)); - } - - void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) override - { - if (interruptNum == RADIOLIB_NC) { - return; - } - ::attachInterrupt(interruptNum, interruptCb, RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST mode); - } - - void detachInterrupt(uint32_t interruptNum) override - { - if (interruptNum == RADIOLIB_NC) { - return; - } - - ::detachInterrupt(interruptNum); - } - - void delay(unsigned long ms) override { gpioDelay(ms * 1000); } - - void delayMicroseconds(unsigned long us) override { gpioDelay(us); } - - unsigned long millis() override { return (gpioTick() / 1000); } - - unsigned long micros() override { return (gpioTick()); } - - long pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) override - { - if (pin == RADIOLIB_NC) { - return (0); - } - - return (::pulseIn(pin, state, timeout)); - } - void spiBegin() - { - if (_spiHandle < 0) { - _spiHandle = spiOpen(_spiChannel, _spiSpeed, 0); - } - } - - void spiBeginTransaction() {} - - void spiTransfer(uint8_t *out, size_t len, uint8_t *in) { spiXfer(_spiHandle, (char *)out, (char *)in, len); } - - void spiEndTransaction() {} - - void spiEnd() - { - if (_spiHandle >= 0) { - spiClose(_spiHandle); - _spiHandle = -1; - } - } - - private: - // the HAL can contain any additional private members - const unsigned int _spiSpeed; - const uint8_t _spiChannel; - int _spiHandle = -1; -}; - -#endif \ No newline at end of file From 423b8ad6036342c723bbe5f3151a1f441f424ebf Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Tue, 28 Nov 2023 12:39:32 -0600 Subject: [PATCH 42/52] Adds real GPS support to Raspberry Pi arch --- bin/config-dist.yaml | 5 +++++ src/gps/GPS.cpp | 10 ++++++---- src/platform/portduino/PortduinoGlue.cpp | 7 +++++++ src/platform/portduino/PortduinoGlue.h | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 43360eb2e..cde45d1f8 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -33,3 +33,8 @@ Lora: GPIO: # User: 6 + +# Define GPS + +GPS: +# SerialPath: /dev/ttyS0 diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 11c16ede9..7ea36c860 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -7,6 +7,7 @@ #include "ubx.h" #ifdef ARCH_PORTDUINO +#include "PortduinoGlue.h" #include "meshUtils.h" #include #endif @@ -15,11 +16,8 @@ #define GPS_RESET_MODE HIGH #endif -#if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(ARCH_ESP32) +#if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(ARCH_ESP32) || defined(ARCH_RASPBERRY_PI) HardwareSerial *GPS::_serial_gps = &Serial1; -#elif defined(ARCH_RASPBERRY_PI) -// need a translation layer to make _serial_gps work with pigpio https://abyz.me.uk/rpi/pigpio/cif.html#serOpen -HardwareSerial *GPS::_serial_gps = NULL; #else HardwareSerial *GPS::_serial_gps = NULL; #endif @@ -907,6 +905,10 @@ GPS *GPS::createGps() #if defined(PIN_GPS_EN) if (!_en_gpio) _en_gpio = PIN_GPS_EN; +#endif +#ifdef ARCH_RASPBERRY_PI + if (!settingsMap[has_gps]) + return nullptr; #endif if (!_rx_gpio || !_serial_gps) // Configured to have no GPS at all return nullptr; diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 54d633530..06e18eb91 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -147,6 +147,13 @@ void portduinoSetup() if (yamlConfig["GPIO"]) { settingsMap[user] = yamlConfig["GPIO"]["User"].as(RADIOLIB_NC); } + if (yamlConfig["GPS"]) { + std::string serialPath = yamlConfig["GPS"]["SerialPath"].as(""); + if (serialPath != "") { + Serial1.setPath(serialPath); + settingsMap[has_gps] = 1; + } + } } catch (YAML::Exception e) { std::cout << "*** Exception " << e.what() << std::endl; diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index ac356607f..b942ab46a 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -4,7 +4,7 @@ extern std::map settingsMap; -enum { use_sx1262, cs, irq, busy, reset, dio2_as_rf_switch, use_rf95, user, gpiochip }; +enum { use_sx1262, cs, irq, busy, reset, dio2_as_rf_switch, use_rf95, user, gpiochip, has_gps }; int initGPIOPin(int pinNum, std::string gpioChipname); #endif \ No newline at end of file From 14d03a2bda24f69fec7dcd42f7fe043b6eb74bc9 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 29 Nov 2023 00:48:30 -0600 Subject: [PATCH 43/52] Initial implementation of I2C --- src/detect/ScanI2CTwoWire.cpp | 11 ++++++++++- src/graphics/Screen.cpp | 2 +- src/main.cpp | 1 + src/platform/portduino/architecture.h | 2 +- variants/portduino/variant.h | 3 ++- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index b3873dc91..a5c932f1f 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -2,7 +2,9 @@ #include "concurrency/LockGuard.h" #include "configuration.h" - +#if defined(ARCH_RASPBERRY_PI) +#include "linux/LinuxHardwareI2C.h" +#endif #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) #include "main.h" // atecc #endif @@ -162,7 +164,14 @@ void ScanI2CTwoWire::scanPort(I2CPort port) for (addr.address = 1; addr.address < 127; addr.address++) { i2cBus->beginTransmission(addr.address); +#ifdef ARCH_PORTDUINO + if (i2cBus->read() != -1) + err = 0; + else + err = 2; +#else err = i2cBus->endTransmission(); +#endif type = NONE; if (err == 0) { LOG_DEBUG("I2C device found at address 0x%x\n", addr.address); diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index b626e393a..2e144e41a 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1564,7 +1564,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 // Jm void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { -#if HAS_WIFI +#if HAS_WIFI && !defined(ARCH_RASPBERRY_PI) const char *wifiName = config.network.wifi_ssid; display->setFont(FONT_SMALL); diff --git a/src/main.cpp b/src/main.cpp index 83f3b721e..5cea142bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,6 +68,7 @@ NRF52Bluetooth *nrf52Bluetooth; #endif #ifdef ARCH_RASPBERRY_PI +#include "linux/LinuxHardwareI2C.h" #include "platform/portduino/PortduinoGlue.h" #include #include diff --git a/src/platform/portduino/architecture.h b/src/platform/portduino/architecture.h index 9408ad19c..a98769222 100644 --- a/src/platform/portduino/architecture.h +++ b/src/platform/portduino/architecture.h @@ -16,4 +16,4 @@ #endif #ifndef HAS_TELEMETRY #define HAS_TELEMETRY 1 -#endif +#endif \ No newline at end of file diff --git a/variants/portduino/variant.h b/variants/portduino/variant.h index 8e1c0b1f2..23066276b 100644 --- a/variants/portduino/variant.h +++ b/variants/portduino/variant.h @@ -1,5 +1,6 @@ #if defined(ARCH_RASPBERRY_PI) -#define NO_SCREEN +#define HAS_WIRE 1 +#define HAS_SCREEN 1 #else // Pine64 mode. From c489c251ab1dd701f7cfb52145a765b42891a887 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 29 Nov 2023 19:03:07 -0600 Subject: [PATCH 44/52] Pull in Portduino changes for Raspberry Pi support --- arch/portduino/portduino.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index b39974853..e4a60306b 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -1,6 +1,6 @@ ; The Portduino based sim environment on top of any host OS, all hardware will be simulated [portduino_base] -platform = https://github.com/meshtastic/platform-native.git#489ff929dca0bb768256ba2de45f95815111490f +platform = https://github.com/meshtastic/platform-native.git#05255283879a0c65a7d3eba6c468b9186438bb14 framework = arduino build_src_filter = From bd2675caf169b1f86c396470148a4f0c9371d4b9 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 29 Nov 2023 19:46:15 -0600 Subject: [PATCH 45/52] Temporarily Pin RadioLib to 6.2.0 --- arch/esp32/esp32.ini | 4 ++-- arch/nrf52/nrf52.ini | 2 +- arch/portduino/portduino.ini | 2 +- arch/rp2040/rp2040.ini | 2 +- arch/stm32/stm32wl5e.ini | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/esp32/esp32.ini b/arch/esp32/esp32.ini index aa31db13e..ab18e5500 100644 --- a/arch/esp32/esp32.ini +++ b/arch/esp32/esp32.ini @@ -39,7 +39,7 @@ lib_deps = ${environmental_base.lib_deps} https://github.com/meshtastic/esp32_https_server.git#23665b3adc080a311dcbb586ed5941b5f94d6ea2 h2zero/NimBLE-Arduino@^1.4.1 - jgromes/RadioLib@^6.1.0 + jgromes/RadioLib@ 6.2.0 https://github.com/lewisxhe/XPowersLib.git#84b7373faea3118b6c37954d52f98b8a337148d6 https://github.com/meshtastic/ESP32_Codec2.git#633326c78ac251c059ab3a8c430fcdf25b41672f @@ -57,4 +57,4 @@ lib_ignore = ; customize the partition table ; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables -board_build.partitions = partition-table.csv +board_build.partitions = partition-table.csv \ No newline at end of file diff --git a/arch/nrf52/nrf52.ini b/arch/nrf52/nrf52.ini index d1826a96a..ee2b70d3b 100644 --- a/arch/nrf52/nrf52.ini +++ b/arch/nrf52/nrf52.ini @@ -15,7 +15,7 @@ build_src_filter = lib_deps= ${arduino_base.lib_deps} - jgromes/RadioLib@^6.1.0 + jgromes/RadioLib@ 6.2.0 lib_ignore = BluetoothOTA \ No newline at end of file diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index e4a60306b..d50fbb9ed 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -22,7 +22,7 @@ lib_deps = ${env.lib_deps} ${networking_base.lib_deps} rweather/Crypto@^0.4.0 - jgromes/RadioLib@6.1.0 + jgromes/RadioLib@6.2.0 build_flags = ${arduino_base.build_flags} diff --git a/arch/rp2040/rp2040.ini b/arch/rp2040/rp2040.ini index 495b52a86..f173d0af6 100644 --- a/arch/rp2040/rp2040.ini +++ b/arch/rp2040/rp2040.ini @@ -20,5 +20,5 @@ lib_ignore = lib_deps = ${arduino_base.lib_deps} ${environmental_base.lib_deps} - jgromes/RadioLib@^6.1.0 + jgromes/RadioLib@ 6.2.0 rweather/Crypto \ No newline at end of file diff --git a/arch/stm32/stm32wl5e.ini b/arch/stm32/stm32wl5e.ini index 524edd6b9..ba92e0370 100644 --- a/arch/stm32/stm32wl5e.ini +++ b/arch/stm32/stm32wl5e.ini @@ -20,7 +20,7 @@ upload_protocol = stlink lib_deps = ${env.lib_deps} - jgromes/RadioLib@^6.1.0 + jgromes/RadioLib@ 6.2.0 https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b https://github.com/littlefs-project/littlefs.git#v2.5.1 https://github.com/stm32duino/STM32FreeRTOS.git#10.3.1 From 39743832adf8b642813797a9f11b12b52e8318a1 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 29 Nov 2023 19:50:44 -0600 Subject: [PATCH 46/52] Revert Portduino RadioLib to 6.1.0 --- arch/portduino/portduino.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index d50fbb9ed..e4a60306b 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -22,7 +22,7 @@ lib_deps = ${env.lib_deps} ${networking_base.lib_deps} rweather/Crypto@^0.4.0 - jgromes/RadioLib@6.2.0 + jgromes/RadioLib@6.1.0 build_flags = ${arduino_base.build_flags} From 6fa026a78b81d89617b8bf822ce8a42aacc8b49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 30 Nov 2023 10:59:01 +0100 Subject: [PATCH 47/52] fix radiolib API for 6.3.0 release --- arch/esp32/esp32.ini | 2 +- src/mesh/RadioLibRF95.cpp | 10 ++-------- src/mesh/SX126xInterface.cpp | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/esp32/esp32.ini b/arch/esp32/esp32.ini index ab18e5500..db4b8e0b5 100644 --- a/arch/esp32/esp32.ini +++ b/arch/esp32/esp32.ini @@ -39,7 +39,7 @@ lib_deps = ${environmental_base.lib_deps} https://github.com/meshtastic/esp32_https_server.git#23665b3adc080a311dcbb586ed5941b5f94d6ea2 h2zero/NimBLE-Arduino@^1.4.1 - jgromes/RadioLib@ 6.2.0 + jgromes/RadioLib@^6.2.0 https://github.com/lewisxhe/XPowersLib.git#84b7373faea3118b6c37954d52f98b8a337148d6 https://github.com/meshtastic/ESP32_Codec2.git#633326c78ac251c059ab3a8c430fcdf25b41672f diff --git a/src/mesh/RadioLibRF95.cpp b/src/mesh/RadioLibRF95.cpp index eca2509aa..f84ec28b7 100644 --- a/src/mesh/RadioLibRF95.cpp +++ b/src/mesh/RadioLibRF95.cpp @@ -1,9 +1,6 @@ #include "RadioLibRF95.h" #include "configuration.h" -#define RF95_CHIP_VERSION 0x12 -#define RF95_ALT_VERSION 0x11 // Supposedly some versions of the chip have id 0x11 - // From datasheet but radiolib doesn't know anything about this #define SX127X_REG_TCXO 0x4B @@ -13,11 +10,8 @@ int16_t RadioLibRF95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_ uint8_t gain) { // execute common part - int16_t state = SX127x::begin(RF95_CHIP_VERSION, syncWord, preambleLength); - if (state != RADIOLIB_ERR_NONE) { - LOG_WARN("Initial probe for RF95 failed with %d, trying again with alternative hardware version\n", state); - state = SX127x::begin(RF95_ALT_VERSION, syncWord, preambleLength); - } + uint8_t rf95versions[2] = {0x12, 0x11}; + int16_t state = SX127x::begin(rf95versions, sizeof(rf95versions), syncWord, preambleLength); RADIOLIB_ASSERT(state); // current limit was removed from module' ctor diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index 5083eeb53..30951cd16 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -250,7 +250,7 @@ template void SX126xInterface::startReceive() // We use a 16 bit preamble so this should save some power by letting radio sit in standby mostly. // Furthermore, we need the PREAMBLE_DETECTED and HEADER_VALID IRQ flag to detect whether we are actively receiving int err = lora.startReceiveDutyCycleAuto(preambleLength, 8, - RADIOLIB_SX126X_IRQ_RX_DEFAULT | RADIOLIB_SX126X_IRQ_RADIOLIB_PREAMBLE_DETECTED | + RADIOLIB_SX126X_IRQ_RX_DEFAULT | RADIOLIB_SX126X_IRQ_PREAMBLE_DETECTED | RADIOLIB_SX126X_IRQ_HEADER_VALID); assert(err == RADIOLIB_ERR_NONE); @@ -284,7 +284,7 @@ template bool SX126xInterface::isActivelyReceiving() // received and handled the interrupt for reading the packet/handling errors. uint16_t irq = lora.getIrqStatus(); - bool detected = (irq & (RADIOLIB_SX126X_IRQ_HEADER_VALID | RADIOLIB_SX126X_IRQ_RADIOLIB_PREAMBLE_DETECTED)); + bool detected = (irq & (RADIOLIB_SX126X_IRQ_HEADER_VALID | RADIOLIB_SX126X_IRQ_PREAMBLE_DETECTED)); // Handle false detections if (detected) { uint32_t now = millis(); From 5df7f07f9570e628671c5214497ba46093192926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 30 Nov 2023 11:10:43 +0100 Subject: [PATCH 48/52] unpin radiolib --- arch/nrf52/nrf52.ini | 2 +- arch/portduino/portduino.ini | 2 +- arch/rp2040/rp2040.ini | 2 +- arch/stm32/stm32wl5e.ini | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/nrf52/nrf52.ini b/arch/nrf52/nrf52.ini index ee2b70d3b..1a3631420 100644 --- a/arch/nrf52/nrf52.ini +++ b/arch/nrf52/nrf52.ini @@ -15,7 +15,7 @@ build_src_filter = lib_deps= ${arduino_base.lib_deps} - jgromes/RadioLib@ 6.2.0 + jgromes/RadioLib@^6.2.0 lib_ignore = BluetoothOTA \ No newline at end of file diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index e4a60306b..cdba520d3 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -22,7 +22,7 @@ lib_deps = ${env.lib_deps} ${networking_base.lib_deps} rweather/Crypto@^0.4.0 - jgromes/RadioLib@6.1.0 + jgromes/RadioLib@^6.1.0 build_flags = ${arduino_base.build_flags} diff --git a/arch/rp2040/rp2040.ini b/arch/rp2040/rp2040.ini index f173d0af6..38acde1e0 100644 --- a/arch/rp2040/rp2040.ini +++ b/arch/rp2040/rp2040.ini @@ -20,5 +20,5 @@ lib_ignore = lib_deps = ${arduino_base.lib_deps} ${environmental_base.lib_deps} - jgromes/RadioLib@ 6.2.0 + jgromes/RadioLib@^6.2.0 rweather/Crypto \ No newline at end of file diff --git a/arch/stm32/stm32wl5e.ini b/arch/stm32/stm32wl5e.ini index ba92e0370..f563eec18 100644 --- a/arch/stm32/stm32wl5e.ini +++ b/arch/stm32/stm32wl5e.ini @@ -20,7 +20,7 @@ upload_protocol = stlink lib_deps = ${env.lib_deps} - jgromes/RadioLib@ 6.2.0 + jgromes/RadioLib@^6.2.0 https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b https://github.com/littlefs-project/littlefs.git#v2.5.1 https://github.com/stm32duino/STM32FreeRTOS.git#10.3.1 From 238cf8cdebda32051e6c4c25f13710f01d67ea34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 30 Nov 2023 11:26:48 +0100 Subject: [PATCH 49/52] fix portduino --- arch/portduino/portduino.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index cdba520d3..3de602f6a 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -27,4 +27,5 @@ lib_deps = build_flags = ${arduino_base.build_flags} -fPIC - -Isrc/platform/portduino \ No newline at end of file + -Isrc/platform/portduino + -DRADIOLIB_EEPROM_UNSUPPORTED // Portduino does not implement EEPROM \ No newline at end of file From 8e742f2f8011caad4f7e5340756599fc6142eb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 30 Nov 2023 11:31:08 +0100 Subject: [PATCH 50/52] Update portduino.ini --- arch/portduino/portduino.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index 3de602f6a..8b4ab5d4b 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -28,4 +28,5 @@ build_flags = ${arduino_base.build_flags} -fPIC -Isrc/platform/portduino - -DRADIOLIB_EEPROM_UNSUPPORTED // Portduino does not implement EEPROM \ No newline at end of file + -DRADIOLIB_EEPROM_UNSUPPORTED + From fb89482129315069bf7551a78f76a3ea30272528 Mon Sep 17 00:00:00 2001 From: S5NC <145265251+S5NC@users.noreply.github.com> Date: Thu, 30 Nov 2023 12:39:46 +0000 Subject: [PATCH 51/52] Set default LoRa SPI pins individually on ESP32 architecture (#2971) * Each pin individually * Correction --------- Co-authored-by: Jonathan Bennett Co-authored-by: Ben Meadors --- src/platform/esp32/architecture.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index 781d41678..0686aa59f 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -127,12 +127,20 @@ // LoRa SPI // ----------------------------------------------------------------------------- -// NRF52 boards will define this in variant.h +// If an SPI-related pin used by the LoRa module isn't defined, use the conventional pin number for it. +// FIXME: these pins should really be defined in each variant.h file to prevent breakages if the defaults change, currently many +// ESP32 variants don't define these pins in their variant.h file. #ifndef LORA_SCK #define LORA_SCK 5 +#endif +#ifndef LORA_MISO #define LORA_MISO 19 +#endif +#ifndef LORA_MOSI #define LORA_MOSI 27 +#endif +#ifndef LORA_CS #define LORA_CS 18 #endif -#define SERIAL0_RX_GPIO 3 // Always GPIO3 on ESP32 \ No newline at end of file +#define SERIAL0_RX_GPIO 3 // Always GPIO3 on ESP32 // FIXME: may be different on ESP32-S3, etc. \ No newline at end of file From def4ec5822331ab57b07aedd873fe5b92a1e1929 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 1 Dec 2023 07:00:19 -0600 Subject: [PATCH 52/52] Always set user (nodeinfo) role to device config's current role (#2973) --- protobufs | 2 +- src/mesh/NodeDB.cpp | 3 ++- src/mesh/generated/meshtastic/deviceonly.pb.h | 4 ++-- src/mesh/generated/meshtastic/mesh.pb.h | 15 ++++++++++----- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/protobufs b/protobufs index c845b7848..9148427a3 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit c845b7848eebb11150ca0427773303bf8758e533 +Subproject commit 9148427a3be535c9e3f17e846ecbb64ce04b6521 diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 2e6c8131e..59b6e4bf1 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -370,7 +370,6 @@ void NodeDB::installDefaultDeviceState() pickNewNodeNum(); // based on macaddr now snprintf(owner.long_name, sizeof(owner.long_name), "Meshtastic %02x%02x", ourMacAddr[4], ourMacAddr[5]); snprintf(owner.short_name, sizeof(owner.short_name), "%02x%02x", ourMacAddr[4], ourMacAddr[5]); - snprintf(owner.id, sizeof(owner.id), "!%08x", getNodeNum()); // Default node ID now based on nodenum memcpy(owner.macaddr, ourMacAddr, sizeof(owner.macaddr)); } @@ -395,6 +394,8 @@ void NodeDB::init() // Set our board type so we can share it with others owner.hw_model = HW_VENDOR; + // Ensure user (nodeinfo) role is set to whatever we're configured to + owner.role = config.device.role; // Include our owner in the node db under our nodenum meshtastic_NodeInfoLite *info = getOrCreateMeshNode(getNodeNum()); diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index ace142773..b099a3eab 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -313,8 +313,8 @@ extern const pb_msgdesc_t meshtastic_NodeRemoteHardwarePin_msg; /* Maximum encoded size of messages (where known) */ #define meshtastic_ChannelFile_size 638 -#define meshtastic_DeviceState_size 16854 -#define meshtastic_NodeInfoLite_size 151 +#define meshtastic_DeviceState_size 17056 +#define meshtastic_NodeInfoLite_size 153 #define meshtastic_NodeRemoteHardwarePin_size 29 #define meshtastic_OEMStore_size 3231 #define meshtastic_PositionLite_size 28 diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index dfaf693fc..59005db48 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -402,6 +402,8 @@ typedef struct _meshtastic_User { If this user is a licensed operator, set this flag. Also, "long_name" should be their licence number. */ bool is_licensed; + /* Indicates that the user's role in the mesh */ + meshtastic_Config_DeviceConfig_Role role; } meshtastic_User; /* A message used in our Dynamic Source Routing protocol (RFC 4728 based) */ @@ -826,6 +828,7 @@ extern "C" { #define meshtastic_Position_altitude_source_ENUMTYPE meshtastic_Position_AltSource #define meshtastic_User_hw_model_ENUMTYPE meshtastic_HardwareModel +#define meshtastic_User_role_ENUMTYPE meshtastic_Config_DeviceConfig_Role #define meshtastic_Routing_variant_error_reason_ENUMTYPE meshtastic_Routing_Error @@ -854,7 +857,7 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_Position_init_default {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN, _meshtastic_Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define meshtastic_User_init_default {"", "", "", {0}, _meshtastic_HardwareModel_MIN, 0} +#define meshtastic_User_init_default {"", "", "", {0}, _meshtastic_HardwareModel_MIN, 0, _meshtastic_Config_DeviceConfig_Role_MIN} #define meshtastic_RouteDiscovery_init_default {0, {0, 0, 0, 0, 0, 0, 0, 0}} #define meshtastic_Routing_init_default {0, {meshtastic_RouteDiscovery_init_default}} #define meshtastic_Data_init_default {_meshtastic_PortNum_MIN, {0, {0}}, 0, 0, 0, 0, 0, 0} @@ -872,7 +875,7 @@ extern "C" { #define meshtastic_Neighbor_init_default {0, 0, 0, 0} #define meshtastic_DeviceMetadata_init_default {"", 0, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_Role_MIN, 0, _meshtastic_HardwareModel_MIN, 0} #define meshtastic_Position_init_zero {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN, _meshtastic_Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define meshtastic_User_init_zero {"", "", "", {0}, _meshtastic_HardwareModel_MIN, 0} +#define meshtastic_User_init_zero {"", "", "", {0}, _meshtastic_HardwareModel_MIN, 0, _meshtastic_Config_DeviceConfig_Role_MIN} #define meshtastic_RouteDiscovery_init_zero {0, {0, 0, 0, 0, 0, 0, 0, 0}} #define meshtastic_Routing_init_zero {0, {meshtastic_RouteDiscovery_init_zero}} #define meshtastic_Data_init_zero {_meshtastic_PortNum_MIN, {0, {0}}, 0, 0, 0, 0, 0, 0} @@ -919,6 +922,7 @@ extern "C" { #define meshtastic_User_macaddr_tag 4 #define meshtastic_User_hw_model_tag 5 #define meshtastic_User_is_licensed_tag 6 +#define meshtastic_User_role_tag 7 #define meshtastic_RouteDiscovery_route_tag 1 #define meshtastic_Routing_route_request_tag 1 #define meshtastic_Routing_route_reply_tag 2 @@ -1047,7 +1051,8 @@ X(a, STATIC, SINGULAR, STRING, long_name, 2) \ X(a, STATIC, SINGULAR, STRING, short_name, 3) \ X(a, STATIC, SINGULAR, FIXED_LENGTH_BYTES, macaddr, 4) \ X(a, STATIC, SINGULAR, UENUM, hw_model, 5) \ -X(a, STATIC, SINGULAR, BOOL, is_licensed, 6) +X(a, STATIC, SINGULAR, BOOL, is_licensed, 6) \ +X(a, STATIC, SINGULAR, UENUM, role, 7) #define meshtastic_User_CALLBACK NULL #define meshtastic_User_DEFAULT NULL @@ -1280,13 +1285,13 @@ extern const pb_msgdesc_t meshtastic_DeviceMetadata_msg; #define meshtastic_MyNodeInfo_size 18 #define meshtastic_NeighborInfo_size 258 #define meshtastic_Neighbor_size 22 -#define meshtastic_NodeInfo_size 261 +#define meshtastic_NodeInfo_size 263 #define meshtastic_Position_size 137 #define meshtastic_QueueStatus_size 23 #define meshtastic_RouteDiscovery_size 40 #define meshtastic_Routing_size 42 #define meshtastic_ToRadio_size 504 -#define meshtastic_User_size 77 +#define meshtastic_User_size 79 #define meshtastic_Waypoint_size 165 #ifdef __cplusplus