diff --git a/.github/workflows/build_raspbian.yml b/.github/workflows/build_raspbian.yml new file mode 100644 index 000000000..103f43a71 --- /dev/null +++ b/.github/workflows/build_raspbian.yml @@ -0,0 +1,45 @@ +name: Build Raspbian + +on: workflow_call + +permissions: + contents: write + packages: write + +jobs: + build-raspbian: + runs-on: [self-hosted, linux, ARM64] + steps: + - 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 + + - 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-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 145a75c2d..6b6ff1ad7 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 @@ -129,6 +128,15 @@ jobs: with: board: ${{ matrix.board }} + build-raspbian: + strategy: + fail-fast: false + max-parallel: 1 + uses: ./.github/workflows/build_raspbian.yml + + package-raspbian: + uses: ./.github/workflows/package_raspbian.yml + build-native: runs-on: ubuntu-latest steps: @@ -204,7 +212,15 @@ 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, + package-raspbian, + ] steps: - name: Checkout code uses: actions/checkout@v3 @@ -216,12 +232,15 @@ 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 - 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 ./firmware-raspbian-*/release/meshtasticd_linux_arm64 ./firmware-raspbian-*/bin/config-dist.yaml - name: Repackage in single firmware zip uses: actions/upload-artifact@v3 @@ -233,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 @@ -294,6 +315,13 @@ jobs: 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 + - name: Device scripts permissions run: | chmod +x ./output/device-install.sh @@ -347,6 +375,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 diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml new file mode 100644 index 000000000..61f82e9d7 --- /dev/null +++ b/.github/workflows/package_raspbian.yml @@ -0,0 +1,62 @@ +name: Package Raspbian + +on: + workflow_call: + workflow_dispatch: + +permissions: + contents: write + packages: write + +jobs: + build-raspbian: + uses: ./.github/workflows/build_raspbian.yml + + package-raspbian: + runs-on: ubuntu-latest + needs: build-raspbian + steps: + - 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 + 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 .debpkg/usr/sbin/meshtasticd + cp bin/config-dist.yaml .debpkg/etc/meshtasticd/config.yaml + chmod +x .debpkg/usr/sbin/meshtasticd + 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: ${{ steps.version.outputs.version }} # refs/tags/v*.*.* + arch: arm64 + depends: libyaml-cpp0.7 + desc: Native Linux Meshtastic binary. + + - uses: actions/upload-artifact@v3 + with: + name: artifact-deb + path: | + ./*.deb 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/.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: diff --git a/arch/esp32/esp32.ini b/arch/esp32/esp32.ini index a26b8ab58..60cdee1cd 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 046c8ac62..0326c87f0 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 8c000519a..0d1151a3b 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 = @@ -23,9 +23,11 @@ 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} -fPIC - -Isrc/platform/portduino \ No newline at end of file + -Isrc/platform/portduino + -DRADIOLIB_EEPROM_UNSUPPORTED + diff --git a/arch/rp2040/rp2040.ini b/arch/rp2040/rp2040.ini index d72f719c6..457961a12 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 - https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b \ No newline at end of file + 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 ab06bdc50..4c4792777 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 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..cde45d1f8 --- /dev/null +++ b/bin/config-dist.yaml @@ -0,0 +1,40 @@ +# 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 + +# Module: sx1262 # Waveshare SX1302 LISTEN ONLY AT THIS TIME! +# CS: 7 +# IRQ: 17 +# Reset: 22 + +# Module: RF95 # Adafruit RFM9x +# Reset: 25 +# 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 + +# 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: +# User: 6 + +# Define GPS + +GPS: +# SerialPath: /dev/ttyS0 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/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 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/ButtonThread.h b/src/ButtonThread.h index a8a89e82e..a60b7730a 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,14 @@ 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) || defined(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,8 +67,13 @@ 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 +#endif #ifdef BUTTON_PIN_ALT userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); #ifdef INPUT_PULLUP_SENSE @@ -87,9 +101,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 +140,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() @@ -199,4 +225,4 @@ class ButtonThread : public concurrency::OSThread } }; -} // namespace concurrency \ No newline at end of file +} // namespace concurrency diff --git a/src/Power.cpp b/src/Power.cpp index e6f7ac990..6f0d2cbdd 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" @@ -52,6 +57,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 +292,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; } @@ -456,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/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/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 8c58333dd..763112fa3 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/gps/GPS.cpp b/src/gps/GPS.cpp index 47ba067d2..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,7 +16,7 @@ #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; #else HardwareSerial *GPS::_serial_gps = NULL; @@ -261,6 +262,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]); @@ -433,6 +448,7 @@ bool GPS::setup() notifyDeepSleepObserver.observe(¬ifyDeepSleep); notifyGPSSleepObserver.observe(¬ifyGPSSleep); + return true; } @@ -889,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/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 c9f5646f5..8ce029361 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,13 +68,14 @@ NRF52Bluetooth *nrf52Bluetooth; #endif #ifdef ARCH_RASPBERRY_PI -#include "platform/portduino/PiHal.h" +#include "linux/LinuxHardwareI2C.h" +#include "platform/portduino/PortduinoGlue.h" #include #include #include #endif -#if HAS_BUTTON +#if HAS_BUTTON || defined(ARCH_RASPBERRY_PI) #include "ButtonThread.h" #endif #include "PowerFSMThread.h" @@ -205,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 @@ -582,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 @@ -627,16 +628,16 @@ 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); +#else // HW_SPI1_DEVICE + SPI.setSCK(LORA_SCK); + SPI.setTX(LORA_MOSI); + SPI.setRX(LORA_MISO); SPI.begin(false); #endif // HW_SPI1_DEVICE #elif defined(ARCH_APOLLO3) @@ -646,8 +647,8 @@ void setup() 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 @@ -693,15 +694,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) { + LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); + 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; + exit(EXIT_FAILURE); + } else { + LOG_INFO("SX1262 Radio init succeeded, using SX1262 radio\n"); + } + } + } else if (settingsMap[use_rf95]) { + if (!rIf) { + LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); + 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; + rIf = NULL; + exit(EXIT_FAILURE); + } else { + LOG_INFO("RF95 Radio init succeeded, using RF95 radio\n"); + } } } @@ -740,7 +758,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/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 0580113d1..afc09309d 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; @@ -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(); @@ -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/RadioLibRF95.cpp b/src/mesh/RadioLibRF95.cpp index 0fa6c7fe8..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,9 +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) - 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 @@ -80,4 +76,4 @@ bool RadioLibRF95::isReceiving() uint8_t RadioLibRF95::readReg(uint8_t addr) { return mod->SPIreadRegister(addr); -} \ No newline at end of file +} diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index 980107917..30951cd16 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[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; @@ -241,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); @@ -275,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(); @@ -318,4 +327,4 @@ template bool SX126xInterface::sleep() #endif return true; -} +} \ No newline at end of file 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 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/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() diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index 163cc8b84..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 -#ifndef RF95_SCK -#define RF95_SCK 5 -#define RF95_MISO 19 -#define RF95_MOSI 27 -#define RF95_NSS 18 +// 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 diff --git a/src/platform/portduino/PiHal.h b/src/platform/portduino/PiHal.h deleted file mode 100644 index f10040583..000000000 --- a/src/platform/portduino/PiHal.h +++ /dev/null @@ -1,155 +0,0 @@ -#ifndef PI_HAL_H -#define PI_HAL_H - -// include RadioLib -#include - -// include the library for Raspberry GPIO pins -#include "pigpio.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; - } - - gpioSetMode(pin, mode); - } - - void digitalWrite(uint32_t pin, uint32_t value) override - { - if (pin == RADIOLIB_NC) { - return; - } - - gpioWrite(pin, value); - } - - uint32_t digitalRead(uint32_t pin) override - { - if (pin == RADIOLIB_NC) { - return (0); - } - - return (gpioRead(pin)); - } - - void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) override - { - if (interruptNum == RADIOLIB_NC) { - return; - } - if (gpioRead(interruptNum) == 1) { - interruptCb(); - } else { - gpioSetAlertFunc(interruptNum, (gpioISRFunc_t)interruptCb); - } - } - - void detachInterrupt(uint32_t interruptNum) override - { - if (interruptNum == RADIOLIB_NC) { - return; - } - - gpioSetAlertFunc(interruptNum, NULL); - } - - 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); - } - - 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); - } - - 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 diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index fb71a429b..06e18eb91 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -9,7 +9,15 @@ #include #ifdef ARCH_RASPBERRY_PI +#include "PortduinoGlue.h" +#include "linux/gpio/LinuxGPIOPin.h" #include "pigpio.h" +#include "yaml-cpp/yaml.h" +#include +#include +#include + +std::map settingsMap; #else #include @@ -27,7 +35,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 +62,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 +102,95 @@ void portduinoSetup() printf("Setting up Meshtastic on Portduino...\n"); #ifdef ARCH_RASPBERRY_PI + gpioInit(); + + std::string gpioChipName = "gpiochip"; + 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 { + 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); + settingsMap[gpiochip] = yamlConfig["Lora"]["gpiochip"].as(0); + gpioChipName += std::to_string(settingsMap[gpiochip]); + } + 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; + 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); + } + + // 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], gpioChipName) != ERRNO_OK) { + settingsMap[cs] = RADIOLIB_NC; + } + } + if (settingsMap.count(irq) > 0 && settingsMap[irq] != RADIOLIB_NC) { + if (initGPIOPin(settingsMap[irq], gpioChipName) != ERRNO_OK) { + settingsMap[irq] = RADIOLIB_NC; + } + } + if (settingsMap.count(busy) > 0 && settingsMap[busy] != RADIOLIB_NC) { + if (initGPIOPin(settingsMap[busy], gpioChipName) != ERRNO_OK) { + settingsMap[busy] = RADIOLIB_NC; + } + } + if (settingsMap.count(reset) > 0 && settingsMap[reset] != RADIOLIB_NC) { + if (initGPIOPin(settingsMap[reset], gpioChipName) != ERRNO_OK) { + settingsMap[reset] = RADIOLIB_NC; + } + } + if (settingsMap.count(user) > 0 && settingsMap[user] != RADIOLIB_NC) { + if (initGPIOPin(settingsMap[user], gpioChipName) != ERRNO_OK) { + settingsMap[user] = RADIOLIB_NC; + } + } + return; #endif @@ -121,7 +218,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); @@ -139,5 +236,23 @@ void portduinoSetup() gpioBind(new SimGPIOPin(LORA_DIO1, "fakeLoraIrq")); } // gpioBind((new SimGPIOPin(LORA_RESET, "LORA_RESET"))); - // gpioBind((new SimGPIOPin(RF95_NSS, "RF95_NSS"))->setSilent()); -} \ No newline at end of file + // gpioBind((new SimGPIOPin(LORA_CS, "LORA_CS"))->setSilent()); +#endif +} + +#ifdef ARCH_RASPBERRY_PI +int initGPIOPin(int pinNum, std::string gpioChipName) +{ + std::string gpio_name = "GPIO" + std::to_string(pinNum); + try { + GPIOPin *csPin; + csPin = new LinuxGPIOPin(pinNum, gpioChipName.c_str(), 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 new file mode 100644 index 000000000..b942ab46a --- /dev/null +++ b/src/platform/portduino/PortduinoGlue.h @@ -0,0 +1,10 @@ +#pragma once +#ifdef ARCH_RASPBERRY_PI +#include + +extern std::map settingsMap; + +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 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/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/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 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/platformio.ini b/variants/portduino/platformio.ini index 323609d0e..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 +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 diff --git a/variants/portduino/variant.h b/variants/portduino/variant.h index 2ce871ddc..23066276b 100644 --- a/variants/portduino/variant.h +++ b/variants/portduino/variant.h @@ -1,33 +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 +#define HAS_WIRE 1 +#define HAS_SCREEN 1 #else // Pine64 mode. @@ -37,10 +10,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/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/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 1ea6d141d..6334157f5 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 @@ -26,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 @@ -45,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/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 diff --git a/variants/rpipico/variant.h b/variants/rpipico/variant.h index 5c92dec59..aeda3d833 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: @@ -32,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 @@ -49,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 6de2f7bd4..abbd1c465 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: @@ -30,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 @@ -47,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