From 09222fde96d7cade879c71f054ebac6c369bdb06 Mon Sep 17 00:00:00 2001 From: Alexander Begoon Date: Wed, 5 Mar 2025 15:32:28 +0100 Subject: [PATCH 1/9] Fix conflicts --- .gitignore | 10 ++++- CMakeLists.txt | 6 +++ arch/esp32/esp32.ini | 2 +- bin/platformio-custom.py | 24 ++++++++--- platformio.ini | 2 +- sdkconfig.defaults | 34 +++++++++++++++ src/CMakeLists.txt | 14 ++++++ src/RedirectablePrint.cpp | 2 +- src/gps/GPS.cpp | 2 +- src/gps/NMEAWPL.cpp | 2 +- src/gps/RTC.cpp | 2 +- src/main.cpp | 14 +++++- src/mesh/MeshService.cpp | 2 +- src/mesh/NodeDB.cpp | 2 +- src/mesh/PhoneAPI.cpp | 2 +- src/mesh/Router.cpp | 2 +- src/mesh/StreamAPI.cpp | 2 +- src/mesh/eth/ethClient.cpp | 2 +- src/mesh/wifi/WiFiAPClient.cpp | 2 +- src/modules/AdminModule.cpp | 2 +- src/modules/ExternalNotificationModule.cpp | 2 +- src/modules/NeighborInfoModule.cpp | 2 +- src/modules/NodeInfoModule.cpp | 2 +- src/modules/PositionModule.cpp | 2 +- src/modules/PowerStressModule.cpp | 2 +- src/modules/RangeTestModule.cpp | 2 +- src/modules/RemoteHardwareModule.cpp | 2 +- src/modules/SerialModule.cpp | 2 +- src/modules/StoreForwardModule.cpp | 2 +- src/modules/Telemetry/AirQualityTelemetry.cpp | 2 +- src/modules/Telemetry/DeviceTelemetry.cpp | 2 +- .../Telemetry/EnvironmentTelemetry.cpp | 2 +- src/modules/Telemetry/HealthTelemetry.cpp | 2 +- src/modules/Telemetry/PowerTelemetry.cpp | 2 +- src/modules/esp32/AudioModule.cpp | 2 +- src/nimble/NimbleBluetooth.cpp | 17 ++++---- src/platform/esp32/main-esp32.cpp | 21 ++++++++- src/platform/stm32wl/main-stm32wl.cpp | 2 +- variants/seeed_xiao_esp32c6/platformio.ini | 40 +++++++++++++++++ variants/seeed_xiao_esp32c6/variant.h | 43 +++++++++++++++++++ variants/tlora_c6/platformio.ini | 35 ++++++++++++++- 41 files changed, 267 insertions(+), 51 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 sdkconfig.defaults create mode 100644 src/CMakeLists.txt create mode 100644 variants/seeed_xiao_esp32c6/platformio.ini create mode 100644 variants/seeed_xiao_esp32c6/variant.h diff --git a/.gitignore b/.gitignore index b63f431d1..038055a81 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,12 @@ release/ .vscode/extensions.json /compile_commands.json src/mesh/raspihttp/certificate.pem -src/mesh/raspihttp/private_key.pem \ No newline at end of file +src/mesh/raspihttp/private_key.pem + +managed_components +dependencies.lock + +log_* +sdkconfig +sdkconfig.* +!sdkconfig.defaults \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..d570718ba --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +# This file supports the ESP-IDF framework only. +# Specifically, it targets the ESP32-C6 due to limited support in PlatformIO (see: https://github.com/platformio/platform-espressif32/issues/1225). +# Currently, we need to compile NimBLE CPP manually to enable BLE, and possibly WiFi, for ESP32-C6 targets. +cmake_minimum_required(VERSION 3.16.0) +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(firmware) diff --git a/arch/esp32/esp32.ini b/arch/esp32/esp32.ini index 256781ba1..5199de6bf 100644 --- a/arch/esp32/esp32.ini +++ b/arch/esp32/esp32.ini @@ -46,7 +46,7 @@ lib_deps = ${environmental_base.lib_deps} ${radiolib_base.lib_deps} https://github.com/meshtastic/esp32_https_server.git#23665b3adc080a311dcbb586ed5941b5f94d6ea2 - h2zero/NimBLE-Arduino@^1.4.3 + h2zero/NimBLE-Arduino@^2.1.0 https://github.com/dbinfrago/libpax.git#3cdc0371c375676a97967547f4065607d4c53fd1 lewisxhe/XPowersLib@^0.2.7 https://github.com/meshtastic/ESP32_Codec2.git#633326c78ac251c059ab3a8c430fcdf25b41672f diff --git a/bin/platformio-custom.py b/bin/platformio-custom.py index 09e8e6d83..ad3b33b2c 100644 --- a/bin/platformio-custom.py +++ b/bin/platformio-custom.py @@ -86,11 +86,20 @@ if platform.name == "nordicnrf52": env.VerboseAction(f"{sys.executable} ./bin/uf2conv.py $BUILD_DIR/firmware.hex -c -f 0xADA52840 -o $BUILD_DIR/firmware.uf2", "Generating UF2 file")) -Import("projenv") +verPropFile = "version.properties" + +try: + # See: https://github.com/platformio/platform-espressif32/issues/953 + Import("projenv") + prefsLoc = projenv["PROJECT_DIR"] + "/" + verPropFile +except Exception as e: + print(f"Warning: Unable to import 'projenv'. Falling back. Error: {e}") + projenv = None + prefsLoc = "./" + verPropFile # Fallback location -prefsLoc = projenv["PROJECT_DIR"] + "/version.properties" verObj = readProps(prefsLoc) -print("Using meshtastic platformio-custom.py, firmware version " + verObj["long"] + " on " + env.get("PIOENV")) + +appEnv = env.get("PIOENV") jsonLoc = env["PROJECT_DIR"] + "/userPrefs.jsonc" with open(jsonLoc) as f: @@ -122,7 +131,8 @@ flags = [ print ("Using flags:") for flag in flags: print(flag) - -projenv.Append( - CCFLAGS=flags, -) \ No newline at end of file + +if projenv: + projenv.Append(CCFLAGS=flags) + +env.Append(CCFLAGS=flags) \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index e8348e002..39fb1ec8d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -56,7 +56,7 @@ build_flags = -Wno-missing-field-initializers monitor_speed = 115200 monitor_filters = direct lib_deps = - https://github.com/meshtastic/esp8266-oled-ssd1306.git#e16cee124fe26490cb14880c679321ad8ac89c95 + https://github.com/meshtastic/esp8266-oled-ssd1306.git#3e9fce851952aa78ef6ce44e892ec9bcf31e1c0b mathertel/OneButton@2.6.1 https://github.com/meshtastic/arduino-fsm.git#7db3702bf0cfe97b783d6c72595e3f38e0b19159 https://github.com/meshtastic/TinyGPSPlus.git#71a82db35f3b973440044c476d4bcdc673b104f4 diff --git a/sdkconfig.defaults b/sdkconfig.defaults new file mode 100644 index 000000000..267ca7f35 --- /dev/null +++ b/sdkconfig.defaults @@ -0,0 +1,34 @@ +# CONFIG_AUTOSTART_ARDUINO is not set +# CONFIG_WS2812_LED_ENABLE is not set +CONFIG_FREERTOS_HZ=1000 +CONFIG_MBEDTLS_PSK_MODES=y +CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=y + +# Override some defaults so BT stack is enabled +# in this example +# +# BT config +# +CONFIG_BT_ENABLED=y +CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y +CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n +CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_BLUEDROID_ENABLED=n +CONFIG_BT_NIMBLE_ENABLED=y + +# +# Arduino Configuration +# +# +# Disable all Arduino included BLE libraries +# +CONFIG_ARDUINO_SELECTIVE_COMPILATION=y +# CONFIG_ARDUINO_SELECTIVE_WiFiProv is not set +# CONFIG_ARDUINO_SELECTIVE_BLE is not set +# CONFIG_ARDUINO_SELECTIVE_BluetoothSerial is not set +# CONFIG_ARDUINO_SELECTIVE_SimpleBLE is not set +# end of Arduino Configuration \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..7d3548813 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,14 @@ +# This file supports the ESP-IDF framework only. +# Specifically, it targets the ESP32-C6 due to limited support in PlatformIO (see: https://github.com/platformio/platform-espressif32/issues/1225). +# Currently, we need to compile NimBLE CPP manually to enable BLE, and possibly WiFi, for ESP32-C6 targets. +FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*) +FILE(GLOB_RECURSE platform_sources ${CMAKE_SOURCE_DIR}/src/platform/**/*.*) +list(REMOVE_ITEM app_sources ${platform_sources}) +FILE(GLOB_RECURSE esp32_sources ${CMAKE_SOURCE_DIR}/src/platform/esp32/*.*) +list(APPEND app_sources ${esp32_sources}) +FILE(GLOB_RECURSE esp32_sources ${CMAKE_SOURCE_DIR}/src/platform/esp32/**/*.*) +list(APPEND app_sources ${esp32_sources}) +list(REMOVE_ITEM app_sources ${CMAKE_SOURCE_DIR}/src/mesh/eth/ethClient.cpp) + +# Register the component with ESP-IDF +idf_component_register(SRCS ${app_sources} INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src) diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 07f873864..d87eb6a32 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -1,8 +1,8 @@ #include "RedirectablePrint.h" #include "NodeDB.h" -#include "RTC.h" #include "concurrency/OSThread.h" #include "configuration.h" +#include "gps/RTC.h" #include "main.h" #include "mesh/generated/meshtastic/mesh.pb.h" #include diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 7dcb77fcc..0910a2d3b 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -9,9 +9,9 @@ #include "GpioLogic.h" #include "NodeDB.h" #include "PowerMon.h" -#include "RTC.h" #include "Throttle.h" #include "buzz.h" +#include "gps/RTC.h" #include "meshUtils.h" #include "main.h" // pmu_found diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index f4249ca62..5259427e6 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -1,7 +1,7 @@ #if !MESHTASTIC_EXCLUDE_GPS #include "NMEAWPL.h" #include "GeoCoord.h" -#include "RTC.h" +#include "gps/RTC.h" #include /* ------------------------------------------- diff --git a/src/gps/RTC.cpp b/src/gps/RTC.cpp index af964eab5..6b1a0b6bf 100644 --- a/src/gps/RTC.cpp +++ b/src/gps/RTC.cpp @@ -1,4 +1,4 @@ -#include "RTC.h" +#include "gps/RTC.h" #include "configuration.h" #include "detect/ScanI2C.h" #include "main.h" diff --git a/src/main.cpp b/src/main.cpp index 2160d73e4..b28847d18 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,13 +13,13 @@ #include "FSCommon.h" #include "Led.h" -#include "RTC.h" #include "SPILock.h" #include "Throttle.h" #include "concurrency/OSThread.h" #include "concurrency/Periodic.h" #include "detect/ScanI2C.h" #include "error.h" +#include "gps/RTC.h" #include "power.h" #if !MESHTASTIC_EXCLUDE_I2C @@ -1275,4 +1275,16 @@ void loop() } } +#endif + +#if !defined(CONFIG_AUTOSTART_ARDUINO) && (ESP_IDF_VERSION_MAJOR * 100 + ESP_IDF_VERSION_MINOR * 10 + ESP_IDF_VERSION_PATCH) > 514 +// Define app_main to bridge Arduino and ESP-IDF +extern "C" void app_main(void) +{ + setup(); + while (1) { + loop(); + vTaskDelay(1); // Allows FreeRTOS to manage tasks + } +} #endif \ No newline at end of file diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 0ef21d4ca..58ea58b32 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -9,8 +9,8 @@ #include "MeshService.h" #include "NodeDB.h" #include "PowerFSM.h" -#include "RTC.h" #include "TypeConversions.h" +#include "gps/RTC.h" #include "main.h" #include "mesh-pb-constants.h" #include "meshUtils.h" diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 62ab675bc..8e2140c22 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -11,12 +11,12 @@ #include "NodeDB.h" #include "PacketHistory.h" #include "PowerFSM.h" -#include "RTC.h" #include "Router.h" #include "SPILock.h" #include "SafeFile.h" #include "TypeConversions.h" #include "error.h" +#include "gps/RTC.h" #include "main.h" #include "mesh-pb-constants.h" #include "meshUtils.h" diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 204886be5..0f88dd11b 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -29,7 +29,7 @@ #include "mqtt/MQTT.h" #endif #include "Throttle.h" -#include +#include "gps/RTC.h" PhoneAPI::PhoneAPI() { diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 9e1e41d53..a3860e135 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -4,9 +4,9 @@ #include "MeshRadio.h" #include "MeshService.h" #include "NodeDB.h" -#include "RTC.h" #include "configuration.h" #include "detect/LoRaRadioType.h" +#include "gps/RTC.h" #include "main.h" #include "mesh-pb-constants.h" #include "meshUtils.h" diff --git a/src/mesh/StreamAPI.cpp b/src/mesh/StreamAPI.cpp index 4a42e5197..982c4a973 100644 --- a/src/mesh/StreamAPI.cpp +++ b/src/mesh/StreamAPI.cpp @@ -1,8 +1,8 @@ #include "StreamAPI.h" #include "PowerFSM.h" -#include "RTC.h" #include "Throttle.h" #include "configuration.h" +#include "gps/RTC.h" #define START1 0x94 #define START2 0xc3 diff --git a/src/mesh/eth/ethClient.cpp b/src/mesh/eth/ethClient.cpp index 70c6e3fe4..e6fa24de6 100644 --- a/src/mesh/eth/ethClient.cpp +++ b/src/mesh/eth/ethClient.cpp @@ -1,8 +1,8 @@ #include "mesh/eth/ethClient.h" #include "NodeDB.h" -#include "RTC.h" #include "concurrency/Periodic.h" #include "configuration.h" +#include "gps/RTC.h" #include "main.h" #include "mesh/api/ethServerAPI.h" #include "target_specific.h" diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index ee50ee56f..9bd793e9e 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -1,8 +1,8 @@ #include "configuration.h" #if HAS_WIFI #include "NodeDB.h" -#include "RTC.h" #include "concurrency/Periodic.h" +#include "gps/RTC.h" #include "mesh/wifi/WiFiAPClient.h" #include "main.h" diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index ac25f57a5..2e7d344a9 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -3,8 +3,8 @@ #include "MeshService.h" #include "NodeDB.h" #include "PowerFSM.h" -#include "RTC.h" #include "SPILock.h" +#include "gps/RTC.h" #include "meshUtils.h" #include #if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_BLUETOOTH diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index bbb3f90e0..5b78042d8 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -16,10 +16,10 @@ #include "ExternalNotificationModule.h" #include "MeshService.h" #include "NodeDB.h" -#include "RTC.h" #include "Router.h" #include "buzz/buzz.h" #include "configuration.h" +#include "gps/RTC.h" #include "main.h" #include "mesh/generated/meshtastic/rtttl.pb.h" #include diff --git a/src/modules/NeighborInfoModule.cpp b/src/modules/NeighborInfoModule.cpp index eebf428a4..92a2f4e58 100644 --- a/src/modules/NeighborInfoModule.cpp +++ b/src/modules/NeighborInfoModule.cpp @@ -2,7 +2,7 @@ #include "Default.h" #include "MeshService.h" #include "NodeDB.h" -#include "RTC.h" +#include "gps/RTC.h" #include NeighborInfoModule *neighborInfoModule; diff --git a/src/modules/NodeInfoModule.cpp b/src/modules/NodeInfoModule.cpp index ce4a6bd06..9464502f8 100644 --- a/src/modules/NodeInfoModule.cpp +++ b/src/modules/NodeInfoModule.cpp @@ -2,9 +2,9 @@ #include "Default.h" #include "MeshService.h" #include "NodeDB.h" -#include "RTC.h" #include "Router.h" #include "configuration.h" +#include "gps/RTC.h" #include "main.h" #include diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index acbc3143d..a0daeead9 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -4,12 +4,12 @@ #include "GPS.h" #include "MeshService.h" #include "NodeDB.h" -#include "RTC.h" #include "Router.h" #include "TypeConversions.h" #include "airtime.h" #include "configuration.h" #include "gps/GeoCoord.h" +#include "gps/RTC.h" #include "main.h" #include "mesh/compression/unishox2.h" #include "meshUtils.h" diff --git a/src/modules/PowerStressModule.cpp b/src/modules/PowerStressModule.cpp index d487fe6fc..feed175de 100644 --- a/src/modules/PowerStressModule.cpp +++ b/src/modules/PowerStressModule.cpp @@ -3,9 +3,9 @@ #include "MeshService.h" #include "NodeDB.h" #include "PowerMon.h" -#include "RTC.h" #include "Router.h" #include "configuration.h" +#include "gps/RTC.h" #include "main.h" #include "sleep.h" #include "target_specific.h" diff --git a/src/modules/RangeTestModule.cpp b/src/modules/RangeTestModule.cpp index cad1d51f1..def1c3096 100644 --- a/src/modules/RangeTestModule.cpp +++ b/src/modules/RangeTestModule.cpp @@ -13,12 +13,12 @@ #include "MeshService.h" #include "NodeDB.h" #include "PowerFSM.h" -#include "RTC.h" #include "Router.h" #include "SPILock.h" #include "airtime.h" #include "configuration.h" #include "gps/GeoCoord.h" +#include "gps/RTC.h" #include #include diff --git a/src/modules/RemoteHardwareModule.cpp b/src/modules/RemoteHardwareModule.cpp index 9bc8512b6..5427d7112 100644 --- a/src/modules/RemoteHardwareModule.cpp +++ b/src/modules/RemoteHardwareModule.cpp @@ -1,9 +1,9 @@ #include "RemoteHardwareModule.h" #include "MeshService.h" #include "NodeDB.h" -#include "RTC.h" #include "Router.h" #include "configuration.h" +#include "gps/RTC.h" #include "main.h" #include diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index c6a95912b..7e7cc8c90 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -3,9 +3,9 @@ #include "MeshService.h" #include "NMEAWPL.h" #include "NodeDB.h" -#include "RTC.h" #include "Router.h" #include "configuration.h" +#include "gps/RTC.h" #include #include diff --git a/src/modules/StoreForwardModule.cpp b/src/modules/StoreForwardModule.cpp index 0a6e1b4c4..cdbc93dbf 100644 --- a/src/modules/StoreForwardModule.cpp +++ b/src/modules/StoreForwardModule.cpp @@ -15,11 +15,11 @@ #include "StoreForwardModule.h" #include "MeshService.h" #include "NodeDB.h" -#include "RTC.h" #include "Router.h" #include "Throttle.h" #include "airtime.h" #include "configuration.h" +#include "gps/RTC.h" #include "memGet.h" #include "mesh-pb-constants.h" #include "mesh/generated/meshtastic/storeforward.pb.h" diff --git a/src/modules/Telemetry/AirQualityTelemetry.cpp b/src/modules/Telemetry/AirQualityTelemetry.cpp index 392bd6148..53a6cf963 100644 --- a/src/modules/Telemetry/AirQualityTelemetry.cpp +++ b/src/modules/Telemetry/AirQualityTelemetry.cpp @@ -8,9 +8,9 @@ #include "MeshService.h" #include "NodeDB.h" #include "PowerFSM.h" -#include "RTC.h" #include "Router.h" #include "detect/ScanI2CTwoWire.h" +#include "gps/RTC.h" #include "main.h" #include diff --git a/src/modules/Telemetry/DeviceTelemetry.cpp b/src/modules/Telemetry/DeviceTelemetry.cpp index 192754e09..19765aba0 100644 --- a/src/modules/Telemetry/DeviceTelemetry.cpp +++ b/src/modules/Telemetry/DeviceTelemetry.cpp @@ -4,10 +4,10 @@ #include "MeshService.h" #include "NodeDB.h" #include "PowerFSM.h" -#include "RTC.h" #include "RadioLibInterface.h" #include "Router.h" #include "configuration.h" +#include "gps/RTC.h" #include "main.h" #include #include diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 3fa3e848a..99909821d 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -8,9 +8,9 @@ #include "MeshService.h" #include "NodeDB.h" #include "PowerFSM.h" -#include "RTC.h" #include "Router.h" #include "UnitConversions.h" +#include "gps/RTC.h" #include "main.h" #include "power.h" #include "sleep.h" diff --git a/src/modules/Telemetry/HealthTelemetry.cpp b/src/modules/Telemetry/HealthTelemetry.cpp index a2a18ba03..e0a50d22c 100644 --- a/src/modules/Telemetry/HealthTelemetry.cpp +++ b/src/modules/Telemetry/HealthTelemetry.cpp @@ -8,9 +8,9 @@ #include "MeshService.h" #include "NodeDB.h" #include "PowerFSM.h" -#include "RTC.h" #include "Router.h" #include "UnitConversions.h" +#include "gps/RTC.h" #include "main.h" #include "power.h" #include "sleep.h" diff --git a/src/modules/Telemetry/PowerTelemetry.cpp b/src/modules/Telemetry/PowerTelemetry.cpp index 14901f0af..b7b903090 100644 --- a/src/modules/Telemetry/PowerTelemetry.cpp +++ b/src/modules/Telemetry/PowerTelemetry.cpp @@ -8,8 +8,8 @@ #include "NodeDB.h" #include "PowerFSM.h" #include "PowerTelemetry.h" -#include "RTC.h" #include "Router.h" +#include "gps/RTC.h" #include "main.h" #include "power.h" #include "sleep.h" diff --git a/src/modules/esp32/AudioModule.cpp b/src/modules/esp32/AudioModule.cpp index 77cc94359..f7093632b 100644 --- a/src/modules/esp32/AudioModule.cpp +++ b/src/modules/esp32/AudioModule.cpp @@ -4,8 +4,8 @@ #include "FSCommon.h" #include "MeshService.h" #include "NodeDB.h" -#include "RTC.h" #include "Router.h" +#include "gps/RTC.h" /* AudioModule diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 009439f25..6c8f6c53f 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -49,7 +49,7 @@ static uint8_t lastToRadio[MAX_TO_FROM_RADIO_SIZE]; class NimbleBluetoothToRadioCallback : public NimBLECharacteristicCallbacks { - virtual void onWrite(NimBLECharacteristic *pCharacteristic) + virtual void onWrite(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo &connInfo) { LOG_DEBUG("To Radio onwrite"); auto val = pCharacteristic->getValue(); @@ -66,7 +66,7 @@ class NimbleBluetoothToRadioCallback : public NimBLECharacteristicCallbacks class NimbleBluetoothFromRadioCallback : public NimBLECharacteristicCallbacks { - virtual void onRead(NimBLECharacteristic *pCharacteristic) + virtual void onRead(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo &connInfo) { uint8_t fromRadioBytes[meshtastic_FromRadio_size]; size_t numBytes = bluetoothPhoneAPI->getFromRadio(fromRadioBytes); @@ -79,7 +79,7 @@ class NimbleBluetoothFromRadioCallback : public NimBLECharacteristicCallbacks class NimbleBluetoothServerCallback : public NimBLEServerCallbacks { - virtual uint32_t onPassKeyRequest() + virtual void onPassKeyEntry(NimBLEConnInfo &connInfo) { uint32_t passkey = config.bluetooth.fixed_pin; @@ -122,10 +122,10 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks #endif passkeyShowing = true; - return passkey; + NimBLEDevice::injectPassKey(connInfo, passkey); } - virtual void onAuthenticationComplete(ble_gap_conn_desc *desc) + virtual void onAuthenticationComplete(NimBLEConnInfo &connInfo) { LOG_INFO("BLE authentication complete"); @@ -138,9 +138,9 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks } } - virtual void onDisconnect(NimBLEServer *pServer, ble_gap_conn_desc *desc) + virtual void onDisconnect(NimBLEServer *pServer, NimBLEConnInfo &connInfo, int reason) { - LOG_INFO("BLE disconnect"); + LOG_INFO("BLE disconnect. Reason %i", reason); bluetoothStatus->updateStatus( new meshtastic::BluetoothStatus(meshtastic::BluetoothStatus::ConnectionState::DISCONNECTED)); @@ -191,7 +191,7 @@ int NimbleBluetooth::getRssi() if (bleServer && isConnected()) { auto service = bleServer->getServiceByUUID(MESH_SERVICE_UUID); uint16_t handle = service->getHandle(); - return NimBLEDevice::getClientByID(handle)->getRssi(); + return NimBLEDevice::getClientByHandle(handle)->getRssi(); } return 0; // FIXME figure out where to source this } @@ -216,6 +216,7 @@ void NimbleBluetooth::setup() NimbleBluetoothServerCallback *serverCallbacks = new NimbleBluetoothServerCallback(); bleServer->setCallbacks(serverCallbacks, true); + bleServer->advertiseOnDisconnect(true); setupService(); startAdvertising(); } diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index 679222af5..50c67c990 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -109,9 +109,14 @@ void esp32Setup() LOG_DEBUG("Free heap: %d", ESP.getFreeHeap()); LOG_DEBUG("Total PSRAM: %d", ESP.getPsramSize()); LOG_DEBUG("Free PSRAM: %d", ESP.getFreePsram()); + esp_log_level_set("gpio", ESP_LOG_WARN); + + auto res = nvs_flash_init(); + assert(res == ESP_OK); nvs_stats_t nvs_stats; - auto res = nvs_get_stats(NULL, &nvs_stats); + res = nvs_get_stats(NULL, &nvs_stats); + assert(res == ESP_OK); LOG_DEBUG("NVS: UsedEntries %d, FreeEntries %d, AllEntries %d, NameSpaces %d", nvs_stats.used_entries, nvs_stats.free_entries, nvs_stats.total_entries, nvs_stats.namespace_count); @@ -155,8 +160,9 @@ void esp32Setup() #ifdef CONFIG_IDF_TARGET_ESP32C6 esp_task_wdt_config_t *wdt_config = (esp_task_wdt_config_t *)malloc(sizeof(esp_task_wdt_config_t)); wdt_config->timeout_ms = APP_WATCHDOG_SECS * 1000; + wdt_config->idle_core_mask = 0; wdt_config->trigger_panic = true; - res = esp_task_wdt_init(wdt_config); + res = esp_task_wdt_reconfigure(wdt_config); assert(res == ESP_OK); #else res = esp_task_wdt_init(APP_WATCHDOG_SECS, true); @@ -168,6 +174,17 @@ void esp32Setup() #ifdef HAS_32768HZ enableSlowCLK(); #endif + +#ifdef USE_XIAO_ESP32C6_EXTERNAL_ANTENNA +#warning "Connect an external antenna to your XIAO ESP32C6; otherwise, it may be damaged!" + gpio_reset_pin(GPIO_NUM_3); + gpio_set_direction(GPIO_NUM_3, GPIO_MODE_OUTPUT); + gpio_set_level(GPIO_NUM_3, LOW); + + gpio_reset_pin(GPIO_NUM_14); + gpio_set_direction(GPIO_NUM_14, GPIO_MODE_OUTPUT); + gpio_set_level(GPIO_NUM_14, HIGH); +#endif } /// loop code specific to ESP32 targets diff --git a/src/platform/stm32wl/main-stm32wl.cpp b/src/platform/stm32wl/main-stm32wl.cpp index 3eddbb3cf..b37930736 100644 --- a/src/platform/stm32wl/main-stm32wl.cpp +++ b/src/platform/stm32wl/main-stm32wl.cpp @@ -1,5 +1,5 @@ -#include "RTC.h" #include "configuration.h" +#include "gps/RTC.h" #include #include diff --git a/variants/seeed_xiao_esp32c6/platformio.ini b/variants/seeed_xiao_esp32c6/platformio.ini new file mode 100644 index 000000000..b3aa6c74d --- /dev/null +++ b/variants/seeed_xiao_esp32c6/platformio.ini @@ -0,0 +1,40 @@ +[env:seeed-xiao-esp32c6] +extends = esp32c6_base +platform = https://github.com/pioarduino/platform-espressif32.git#f5d602fa7b4b778604306a149fe474723e79be2d +framework = arduino, espidf +board = esp32-c6-devkitm-1 +board_check = true +board_build.partitions = partition-table.csv +upload_protocol = esptool +upload_speed = 921600 +monitor_speed = 460800 +monitor_filters = esp32_c3_exception_decoder +extra_scripts = pre:bin/platformio-custom.py +build_unflags = + -D HAS_BLUETOOTH + -D MESHTASTIC_EXCLUDE_BLUETOOTH + -D HAS_WIFI +build_flags = + ${esp32c6_base.build_flags} + -D PRIVATE_HW + -I variants/seeed_xiao_esp32c6 + -D ARDUINO_USB_CDC_ON_BOOT=1 + -D ARDUINO_USB_MODE=1 + -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/esp32c3" + -D HAS_BLUETOOTH=1 + -D MESHTASTIC_EXCLUDE_WEBSERVER + -D MESHTASTIC_EXCLUDE_MQTT + -D CONFIG_NIMBLE_CPP_FREERTOS_TASK_BLOCK_BIT=1 + +board_build.embed_txtfiles = + managed_components/espressif__esp_insights/server_certs/https_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt + +lib_deps = + ${esp32c6_base.lib_deps} + https://github.com/h2zero/esp-nimble-cpp.git#2.0.2 + +lib_ignore = + ${esp32c6_base.lib_ignore} \ No newline at end of file diff --git a/variants/seeed_xiao_esp32c6/variant.h b/variants/seeed_xiao_esp32c6/variant.h new file mode 100644 index 000000000..2f9365492 --- /dev/null +++ b/variants/seeed_xiao_esp32c6/variant.h @@ -0,0 +1,43 @@ +#define LED_PIN 15 +#define LED_STATE_ON 0 // State when LED is lit + +#define BUTTON_PIN 21 // This is the Program Button +#define BUTTON_NEED_PULLUP + +#define I2C_SDA 22 +#define I2C_SCL 23 + +// #define USE_RF95 +#define USE_SX1262 + +#define LORA_MISO 20 +#define LORA_SCK 19 +#define LORA_MOSI 18 + +#ifdef USE_RF95 +#define LORA_CS 17 +#define LORA_RESET 1 +#define LORA_DIO0 0 +#define LORA_DIO1 16 +#endif + +#ifdef USE_SX1262 +#define LORA_CS 21 +#define LORA_DIO1 2 +#define LORA_BUSY 0 +#define LORA_RESET 5 +#define SX126X_CS LORA_CS +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_BUSY +#define SX126X_RESET LORA_RESET +#define SX126X_RXEN 4 +#define SX126X_TXEN RADIOLIB_NC +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#endif + +#define HAS_GPS 0 +#undef GPS_RX_PIN +#undef GPS_TX_PIN + +#define USE_XIAO_ESP32C6_EXTERNAL_ANTENNA \ No newline at end of file diff --git a/variants/tlora_c6/platformio.ini b/variants/tlora_c6/platformio.ini index d042cd78b..8abc955bc 100644 --- a/variants/tlora_c6/platformio.ini +++ b/variants/tlora_c6/platformio.ini @@ -1,10 +1,41 @@ [env:tlora-c6] extends = esp32c6_base +platform = https://github.com/pioarduino/platform-espressif32.git#f5d602fa7b4b778604306a149fe474723e79be2d +framework = arduino, espidf board = esp32-c6-devkitm-1 -build_flags = +board_build.partitions = partition-table.csv +upload_protocol = esptool +upload_speed = 921600 +monitor_speed = 460800 +monitor_filters = esp32_c3_exception_decoder +extra_scripts = pre:bin/platformio-custom.py + +build_unflags = + -D HAS_BLUETOOTH + -D MESHTASTIC_EXCLUDE_BLUETOOTH + -D HAS_WIFI + +build_flags = ${esp32c6_base.build_flags} -D TLORA_C6 -I variants/tlora_c6 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MODE=1 - -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/esp32c3" \ No newline at end of file + -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/esp32c3" + -D HAS_BLUETOOTH=1 + -D MESHTASTIC_EXCLUDE_WEBSERVER + -D MESHTASTIC_EXCLUDE_MQTT + -D CONFIG_NIMBLE_CPP_FREERTOS_TASK_BLOCK_BIT=1 + +board_build.embed_txtfiles = + managed_components/espressif__esp_insights/server_certs/https_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt + +lib_deps = + ${esp32c6_base.lib_deps} + https://github.com/h2zero/esp-nimble-cpp.git#2.0.2 + +lib_ignore = + ${esp32c6_base.lib_ignore} From 53b5a59115641549ae193970f7d6e9e6168d53e8 Mon Sep 17 00:00:00 2001 From: Alexander Begoon Date: Thu, 6 Mar 2025 13:29:48 +0100 Subject: [PATCH 2/9] bump deps version --- variants/seeed_xiao_esp32c6/platformio.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variants/seeed_xiao_esp32c6/platformio.ini b/variants/seeed_xiao_esp32c6/platformio.ini index b3aa6c74d..b709d10d7 100644 --- a/variants/seeed_xiao_esp32c6/platformio.ini +++ b/variants/seeed_xiao_esp32c6/platformio.ini @@ -1,6 +1,6 @@ [env:seeed-xiao-esp32c6] extends = esp32c6_base -platform = https://github.com/pioarduino/platform-espressif32.git#f5d602fa7b4b778604306a149fe474723e79be2d +platform = https://github.com/pioarduino/platform-espressif32.git#d2f1607cb561cf3da3f2cc03ceb94d25255e6fe4 framework = arduino, espidf board = esp32-c6-devkitm-1 board_check = true @@ -34,7 +34,7 @@ board_build.embed_txtfiles = lib_deps = ${esp32c6_base.lib_deps} - https://github.com/h2zero/esp-nimble-cpp.git#2.0.2 + https://github.com/h2zero/esp-nimble-cpp.git#2.2.1 lib_ignore = ${esp32c6_base.lib_ignore} \ No newline at end of file From 7cad7d38641bf23d3f7fe53dd2f4c7ecd9b36a13 Mon Sep 17 00:00:00 2001 From: Alexander Begoon Date: Sat, 19 Apr 2025 11:56:55 +0200 Subject: [PATCH 3/9] Improve pio config. Fix Nimble pin code issue. Address some PR comments. --- arch/esp32/esp32c6.ini | 3 +-- sdkconfig.defaults | 3 +++ src/main.cpp | 2 +- src/nimble/NimbleBluetooth.cpp | 2 +- variants/seeed_xiao_esp32c6/platformio.ini | 20 ---------------- variants/seeed_xiao_esp32c6/variant.h | 1 + variants/tlora_c6/platformio.ini | 27 +++------------------- 7 files changed, 10 insertions(+), 48 deletions(-) diff --git a/arch/esp32/esp32c6.ini b/arch/esp32/esp32c6.ini index e1cf955e8..ac1778cfb 100644 --- a/arch/esp32/esp32c6.ini +++ b/arch/esp32/esp32c6.ini @@ -17,9 +17,7 @@ build_flags = -DMESHTASTIC_EXCLUDE_WEBSERVER ;-DDEBUG_HEAP ; TEMP - -DHAS_BLUETOOTH=0 -DMESHTASTIC_EXCLUDE_PAXCOUNTER - -DMESHTASTIC_EXCLUDE_BLUETOOTH lib_deps = ${arduino_base.lib_deps} @@ -32,6 +30,7 @@ lib_deps = https://github.com/meshtastic/ESP32_Codec2/archive/633326c78ac251c059ab3a8c430fcdf25b41672f.zip # renovate: datasource=custom.pio depName=rweather/Crypto packageName=rweather/library/Crypto rweather/Crypto@^0.4.0 + https://github.com/h2zero/esp-nimble-cpp.git#2.2.1 build_src_filter = ${esp32_base.build_src_filter} - diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 267ca7f35..61d5a1560 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -1,3 +1,6 @@ +# # This file configures the ESP-IDF framework for the ESP32 platform. +# It enables BLE functionality using NimBLE and optimizes for minimal power consumption and size. +# Refer to the ESP-IDF Kconfig documentation for more details: https://docs.espressif.com/projects/esp-idf/en/v5.1.6/esp32c6/api-reference/kconfig.html # CONFIG_AUTOSTART_ARDUINO is not set # CONFIG_WS2812_LED_ENABLE is not set CONFIG_FREERTOS_HZ=1000 diff --git a/src/main.cpp b/src/main.cpp index dc9875551..8be3bc0ca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1415,7 +1415,7 @@ void loop() } #endif -#if !defined(CONFIG_AUTOSTART_ARDUINO) && (ESP_IDF_VERSION_MAJOR * 100 + ESP_IDF_VERSION_MINOR * 10 + ESP_IDF_VERSION_PATCH) > 514 +#if !defined(CONFIG_AUTOSTART_ARDUINO) && (ESP_IDF_VERSION_MAJOR * 100 + ESP_IDF_VERSION_MINOR * 10 + ESP_IDF_VERSION_PATCH) > 512 // Define app_main to bridge Arduino and ESP-IDF extern "C" void app_main(void) { diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index caa1c5319..208d8ae3c 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -122,7 +122,7 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks #endif passkeyShowing = true; - NimBLEDevice::injectPassKey(connInfo, passkey); + return passkey; } virtual void onAuthenticationComplete(NimBLEConnInfo &connInfo) diff --git a/variants/seeed_xiao_esp32c6/platformio.ini b/variants/seeed_xiao_esp32c6/platformio.ini index b709d10d7..f47bcd9d7 100644 --- a/variants/seeed_xiao_esp32c6/platformio.ini +++ b/variants/seeed_xiao_esp32c6/platformio.ini @@ -1,19 +1,12 @@ [env:seeed-xiao-esp32c6] extends = esp32c6_base -platform = https://github.com/pioarduino/platform-espressif32.git#d2f1607cb561cf3da3f2cc03ceb94d25255e6fe4 framework = arduino, espidf board = esp32-c6-devkitm-1 board_check = true board_build.partitions = partition-table.csv upload_protocol = esptool upload_speed = 921600 -monitor_speed = 460800 -monitor_filters = esp32_c3_exception_decoder extra_scripts = pre:bin/platformio-custom.py -build_unflags = - -D HAS_BLUETOOTH - -D MESHTASTIC_EXCLUDE_BLUETOOTH - -D HAS_WIFI build_flags = ${esp32c6_base.build_flags} -D PRIVATE_HW @@ -25,16 +18,3 @@ build_flags = -D MESHTASTIC_EXCLUDE_WEBSERVER -D MESHTASTIC_EXCLUDE_MQTT -D CONFIG_NIMBLE_CPP_FREERTOS_TASK_BLOCK_BIT=1 - -board_build.embed_txtfiles = - managed_components/espressif__esp_insights/server_certs/https_server.crt - managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt - managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt - managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt - -lib_deps = - ${esp32c6_base.lib_deps} - https://github.com/h2zero/esp-nimble-cpp.git#2.2.1 - -lib_ignore = - ${esp32c6_base.lib_ignore} \ No newline at end of file diff --git a/variants/seeed_xiao_esp32c6/variant.h b/variants/seeed_xiao_esp32c6/variant.h index 2f9365492..0f24cde47 100644 --- a/variants/seeed_xiao_esp32c6/variant.h +++ b/variants/seeed_xiao_esp32c6/variant.h @@ -40,4 +40,5 @@ #undef GPS_RX_PIN #undef GPS_TX_PIN +// For BLE/WiFi connectivity #define USE_XIAO_ESP32C6_EXTERNAL_ANTENNA \ No newline at end of file diff --git a/variants/tlora_c6/platformio.ini b/variants/tlora_c6/platformio.ini index 8abc955bc..ac2afcb75 100644 --- a/variants/tlora_c6/platformio.ini +++ b/variants/tlora_c6/platformio.ini @@ -1,41 +1,20 @@ [env:tlora-c6] extends = esp32c6_base -platform = https://github.com/pioarduino/platform-espressif32.git#f5d602fa7b4b778604306a149fe474723e79be2d framework = arduino, espidf board = esp32-c6-devkitm-1 +board_check = true board_build.partitions = partition-table.csv upload_protocol = esptool upload_speed = 921600 -monitor_speed = 460800 -monitor_filters = esp32_c3_exception_decoder extra_scripts = pre:bin/platformio-custom.py - -build_unflags = - -D HAS_BLUETOOTH - -D MESHTASTIC_EXCLUDE_BLUETOOTH - -D HAS_WIFI - build_flags = ${esp32c6_base.build_flags} -D TLORA_C6 -I variants/tlora_c6 - -DARDUINO_USB_CDC_ON_BOOT=1 - -DARDUINO_USB_MODE=1 + -D ARDUINO_USB_CDC_ON_BOOT=1 + -D ARDUINO_USB_MODE=1 -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/esp32c3" -D HAS_BLUETOOTH=1 -D MESHTASTIC_EXCLUDE_WEBSERVER -D MESHTASTIC_EXCLUDE_MQTT -D CONFIG_NIMBLE_CPP_FREERTOS_TASK_BLOCK_BIT=1 - -board_build.embed_txtfiles = - managed_components/espressif__esp_insights/server_certs/https_server.crt - managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt - managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt - managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt - -lib_deps = - ${esp32c6_base.lib_deps} - https://github.com/h2zero/esp-nimble-cpp.git#2.0.2 - -lib_ignore = - ${esp32c6_base.lib_ignore} From 9874c5c696bf9eeff50bec63d120f2cf861f643a Mon Sep 17 00:00:00 2001 From: Alexander Begoon Date: Sat, 19 Apr 2025 12:00:20 +0200 Subject: [PATCH 4/9] Fix lint --- boards/seeed_xiao_nrf52840_kit.json | 4 +--- src/gps/GPS.cpp | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/boards/seeed_xiao_nrf52840_kit.json b/boards/seeed_xiao_nrf52840_kit.json index 4c5fdbeda..676733874 100644 --- a/boards/seeed_xiao_nrf52840_kit.json +++ b/boards/seeed_xiao_nrf52840_kit.json @@ -7,9 +7,7 @@ "cpu": "cortex-m4", "extra_flags": "-DARDUINO_MDBT50Q_RX -DNRF52840_XXAA", "f_cpu": "64000000L", - "hwids": [ - ["0x2886", "0x0166"] - ], + "hwids": [["0x2886", "0x0166"]], "usb_product": "XIAO-BOOT", "mcu": "nrf52840", "variant": "seeed_xiao_nrf52840_kit", diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 15568809e..3abff8e4f 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -11,8 +11,8 @@ #include "PowerMon.h" #include "Throttle.h" #include "buzz.h" -#include "gps/RTC.h" #include "concurrency/Periodic.h" +#include "gps/RTC.h" #include "meshUtils.h" #include "main.h" // pmu_found From ba0f5688ae1078a812449f4d2049cc660983e32d Mon Sep 17 00:00:00 2001 From: Alexander Begoon Date: Sat, 19 Apr 2025 12:01:22 +0200 Subject: [PATCH 5/9] Fix lint --- .github/pull_request_template.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a15b34aae..0142c57a2 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,6 +1,7 @@ ## 🙏 Thank you for sending in a pull request, here's some tips to get started! ### ❌ (Please delete all these tips and replace them with your text) ❌ + - Before starting on some new big chunk of code, it it is optional but highly recommended to open an issue first to say "Hey, I think this idea X should be implemented and I'm starting work on it. My general plan is Y, any feedback is appreciated." This will allow other devs to potentially save you time by not accidentially duplicating work etc... @@ -15,12 +16,12 @@ - If you do not have the affected hardware to test your code changes adequately against regressions, please indicate this, so that contributors and commnunity members can help test your changes. - If your PR gets accepted you can request a "Contributor" role in the Meshtastic Discord - ## 🤝 Attestations + - [ ] I have tested that my proposed changes behave as described. - [ ] I have tested that my proposed changes do not cause any obvious regressions on the following devices: - [ ] Heltec (Lora32) V3 - - [ ] LilyGo T-Deck + - [ ] LilyGo T-Deck - [ ] LilyGo T-Beam - [ ] RAK WisBlock 4631 - [ ] Seeed Studio T-1000E tracker card From 0e95ed2979a36291ce63ce6e1aefa87d1becbf6d Mon Sep 17 00:00:00 2001 From: Alexander Begoon Date: Sun, 20 Apr 2025 14:55:46 +0200 Subject: [PATCH 6/9] Fix a dependency source --- arch/esp32/esp32c6.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/esp32/esp32c6.ini b/arch/esp32/esp32c6.ini index ac1778cfb..5011bf4ec 100644 --- a/arch/esp32/esp32c6.ini +++ b/arch/esp32/esp32c6.ini @@ -30,7 +30,8 @@ lib_deps = https://github.com/meshtastic/ESP32_Codec2/archive/633326c78ac251c059ab3a8c430fcdf25b41672f.zip # renovate: datasource=custom.pio depName=rweather/Crypto packageName=rweather/library/Crypto rweather/Crypto@^0.4.0 - https://github.com/h2zero/esp-nimble-cpp.git#2.2.1 + # renovate: datasource=github-tags depName=esp-nimble-cpp packageName=h2zero/esp-nimble-cpp + https://github.com/h2zero/esp-nimble-cpp/archive/2.2.1.zip build_src_filter = ${esp32_base.build_src_filter} - From 685c8c1df7f72b6238b42d4f9cceda22f64d0801 Mon Sep 17 00:00:00 2001 From: Alexander Begoon Date: Tue, 29 Apr 2025 18:43:41 +0200 Subject: [PATCH 7/9] Add support for CONFIG_NIMBLE_CPP_IDF in NimbleBluetooth callbacks Add support 1.x.x version of NimBLE-Arduino --- src/nimble/NimbleBluetooth.cpp | 67 ++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 009439f25..49a56d8c2 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -49,38 +49,53 @@ static uint8_t lastToRadio[MAX_TO_FROM_RADIO_SIZE]; class NimbleBluetoothToRadioCallback : public NimBLECharacteristicCallbacks { +#ifdef CONFIG_NIMBLE_CPP_IDF + virtual void onWrite(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo &connInfo){ +#else virtual void onWrite(NimBLECharacteristic *pCharacteristic) { +#endif LOG_DEBUG("To Radio onwrite"); - auto val = pCharacteristic->getValue(); + auto val = pCharacteristic->getValue(); - if (memcmp(lastToRadio, val.data(), val.length()) != 0) { - LOG_DEBUG("New ToRadio packet"); - memcpy(lastToRadio, val.data(), val.length()); - bluetoothPhoneAPI->handleToRadio(val.data(), val.length()); - } else { - LOG_DEBUG("Drop dup ToRadio packet we just saw"); - } + if (memcmp(lastToRadio, val.data(), val.length()) != 0) { + LOG_DEBUG("New ToRadio packet"); + memcpy(lastToRadio, val.data(), val.length()); + bluetoothPhoneAPI->handleToRadio(val.data(), val.length()); + } else { + LOG_DEBUG("Drop dup ToRadio packet we just saw"); } -}; +} +} +; class NimbleBluetoothFromRadioCallback : public NimBLECharacteristicCallbacks { +#ifdef CONFIG_NIMBLE_CPP_IDF + virtual void onRead(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo &connInfo){ +#else virtual void onRead(NimBLECharacteristic *pCharacteristic) { +#endif uint8_t fromRadioBytes[meshtastic_FromRadio_size]; - size_t numBytes = bluetoothPhoneAPI->getFromRadio(fromRadioBytes); + size_t numBytes = bluetoothPhoneAPI->getFromRadio(fromRadioBytes); - std::string fromRadioByteString(fromRadioBytes, fromRadioBytes + numBytes); + std::string fromRadioByteString(fromRadioBytes, fromRadioBytes + numBytes); - pCharacteristic->setValue(fromRadioByteString); - } -}; + pCharacteristic->setValue(fromRadioByteString); +} +} +; class NimbleBluetoothServerCallback : public NimBLEServerCallbacks { +#ifdef CONFIG_NIMBLE_CPP_IDF + virtual uint32_t onPassKeyDisplay() + { +#else virtual uint32_t onPassKeyRequest() { +#endif uint32_t passkey = config.bluetooth.fixed_pin; if (config.bluetooth.mode == meshtastic_Config_BluetoothConfig_PairingMode_RANDOM_PIN) { @@ -124,9 +139,13 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks return passkey; } - +#ifdef CONFIG_NIMBLE_CPP_IDF + virtual void onAuthenticationComplete(NimBLEConnInfo &connInfo) + { +#else virtual void onAuthenticationComplete(ble_gap_conn_desc *desc) { +#endif LOG_INFO("BLE authentication complete"); bluetoothStatus->updateStatus(new meshtastic::BluetoothStatus(meshtastic::BluetoothStatus::ConnectionState::CONNECTED)); @@ -138,10 +157,15 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks } } +#ifdef CONFIG_NIMBLE_CPP_IDF + virtual void onDisconnect(NimBLEServer *pServer, NimBLEConnInfo &connInfo, int reason) + { + LOG_INFO("BLE disconnect. Reason: %i", reason); +#else virtual void onDisconnect(NimBLEServer *pServer, ble_gap_conn_desc *desc) { LOG_INFO("BLE disconnect"); - +#endif bluetoothStatus->updateStatus( new meshtastic::BluetoothStatus(meshtastic::BluetoothStatus::ConnectionState::DISCONNECTED)); @@ -191,7 +215,11 @@ int NimbleBluetooth::getRssi() if (bleServer && isConnected()) { auto service = bleServer->getServiceByUUID(MESH_SERVICE_UUID); uint16_t handle = service->getHandle(); +#ifdef CONFIG_NIMBLE_CPP_IDF + return NimBLEDevice::getClientByHandle(handle)->getRssi(); +#else return NimBLEDevice::getClientByID(handle)->getRssi(); +#endif } return 0; // FIXME figure out where to source this } @@ -216,6 +244,9 @@ void NimbleBluetooth::setup() NimbleBluetoothServerCallback *serverCallbacks = new NimbleBluetoothServerCallback(); bleServer->setCallbacks(serverCallbacks, true); +#ifdef CONFIG_NIMBLE_CPP_IDF + bleServer->advertiseOnDisconnect(true); +#endif setupService(); startAdvertising(); } @@ -259,7 +290,11 @@ void NimbleBluetooth::setupService() BatteryCharacteristic = batteryService->createCharacteristic( // 0x2A19 is the Battery Level characteristic) (uint16_t)0x2a19, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY, 1); +#ifdef CONFIG_NIMBLE_CPP_IDF + NimBLE2904 *batteryLevelDescriptor = (NimBLE2904 *)BatteryCharacteristic->create2904(); +#else NimBLE2904 *batteryLevelDescriptor = (NimBLE2904 *)BatteryCharacteristic->createDescriptor((uint16_t)0x2904); +#endif batteryLevelDescriptor->setFormat(NimBLE2904::FORMAT_UINT8); batteryLevelDescriptor->setNamespace(1); batteryLevelDescriptor->setUnit(0x27ad); From b326fb76f3f3ccc0cdf8455262a53724fb084bff Mon Sep 17 00:00:00 2001 From: Alexander Begoon Date: Sat, 10 May 2025 13:10:08 +0200 Subject: [PATCH 8/9] Reroute to Meshimi pinout Add MAX17261 sensor --- .../Telemetry/Sensor/MAX17261Sensor.cpp | 176 ++++++++++++++++++ src/modules/Telemetry/Sensor/MAX17261Sensor.h | 111 +++++++++++ variants/seeed_xiao_esp32c6/variant.h | 8 +- 3 files changed, 291 insertions(+), 4 deletions(-) create mode 100644 src/modules/Telemetry/Sensor/MAX17261Sensor.cpp create mode 100644 src/modules/Telemetry/Sensor/MAX17261Sensor.h diff --git a/src/modules/Telemetry/Sensor/MAX17261Sensor.cpp b/src/modules/Telemetry/Sensor/MAX17261Sensor.cpp new file mode 100644 index 000000000..6ab96aa57 --- /dev/null +++ b/src/modules/Telemetry/Sensor/MAX17261Sensor.cpp @@ -0,0 +1,176 @@ +#include "MAX17048Sensor.h" + +#if !MESHTASTIC_EXCLUDE_I2C && !defined(ARCH_STM32WL) && __has_include() + +MAX17048Singleton *MAX17048Singleton::GetInstance() +{ + if (pinstance == nullptr) { + pinstance = new MAX17048Singleton(); + } + return pinstance; +} + +MAX17048Singleton::MAX17048Singleton() {} + +MAX17048Singleton::~MAX17048Singleton() {} + +MAX17048Singleton *MAX17048Singleton::pinstance{nullptr}; + +bool MAX17048Singleton::runOnce(TwoWire *theWire) +{ + initialized = begin(theWire); + LOG_DEBUG("%s::runOnce %s", sensorStr, initialized ? "began ok" : "begin failed"); + return initialized; +} + +bool MAX17048Singleton::isBatteryCharging() +{ + float volts = cellVoltage(); + if (isnan(volts)) { + LOG_DEBUG("%s::isBatteryCharging not connected", sensorStr); + return 0; + } + + MAX17048ChargeSample sample; + sample.chargeRate = chargeRate(); // charge/discharge rate in percent/hr + sample.cellPercent = cellPercent(); // state of charge in percent 0 to 100 + chargeSamples.push(sample); // save a sample into a fifo buffer + + // Keep the fifo buffer trimmed + while (chargeSamples.size() > MAX17048_CHARGING_SAMPLES) + chargeSamples.pop(); + + // Based on the past n samples, is the lipo charging, discharging or idle + if (chargeSamples.front().chargeRate > MAX17048_CHARGING_MINIMUM_RATE && + chargeSamples.back().chargeRate > MAX17048_CHARGING_MINIMUM_RATE) { + if (chargeSamples.front().cellPercent > chargeSamples.back().cellPercent) + chargeState = MAX17048ChargeState::EXPORT; + else if (chargeSamples.front().cellPercent < chargeSamples.back().cellPercent) + chargeState = MAX17048ChargeState::IMPORT; + else + chargeState = MAX17048ChargeState::IDLE; + } else { + chargeState = MAX17048ChargeState::IDLE; + } + + LOG_DEBUG("%s::isBatteryCharging %s volts: %.3f soc: %.3f rate: %.3f", sensorStr, chargeLabels[chargeState], volts, + sample.cellPercent, sample.chargeRate); + return chargeState == MAX17048ChargeState::IMPORT; +} + +uint16_t MAX17048Singleton::getBusVoltageMv() +{ + float volts = cellVoltage(); + if (isnan(volts)) { + LOG_DEBUG("%s::getBusVoltageMv is not connected", sensorStr); + return 0; + } + LOG_DEBUG("%s::getBusVoltageMv %.3fmV", sensorStr, volts); + return (uint16_t)(volts * 1000.0f); +} + +uint8_t MAX17048Singleton::getBusBatteryPercent() +{ + float soc = cellPercent(); + LOG_DEBUG("%s::getBusBatteryPercent %.1f%%", sensorStr, soc); + return clamp(static_cast(round(soc)), static_cast(0), static_cast(100)); +} + +uint16_t MAX17048Singleton::getTimeToGoSecs() +{ + float rate = chargeRate(); // charge/discharge rate in percent/hr + float soc = cellPercent(); // state of charge in percent 0 to 100 + soc = clamp(soc, 0.0f, 100.0f); // clamp soc between 0 and 100% + float ttg = ((100.0f - soc) / rate) * 3600.0f; // calculate seconds to charge/discharge + LOG_DEBUG("%s::getTimeToGoSecs %.0f seconds", sensorStr, ttg); + return (uint16_t)ttg; +} + +bool MAX17048Singleton::isBatteryConnected() +{ + float volts = cellVoltage(); + if (isnan(volts)) { + LOG_DEBUG("%s::isBatteryConnected is not connected", sensorStr); + return false; + } + + // if a valid voltage is returned, then battery must be connected + return true; +} + +bool MAX17048Singleton::isExternallyPowered() +{ + float volts = cellVoltage(); + if (isnan(volts)) { + // if the battery is not connected then there must be external power + LOG_DEBUG("%s::isExternallyPowered battery is", sensorStr); + return true; + } + // if the bus voltage is over MAX17048_BUS_POWER_VOLTS, then the external power + // is assumed to be connected + LOG_DEBUG("%s::isExternallyPowered %s connected", sensorStr, volts >= MAX17048_BUS_POWER_VOLTS ? "is" : "is not"); + return volts >= MAX17048_BUS_POWER_VOLTS; +} + +#if (HAS_TELEMETRY && (!MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR || !MESHTASTIC_EXCLUDE_POWER_TELEMETRY)) + +MAX17048Sensor::MAX17048Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_MAX17048, "MAX17048") {} + +int32_t MAX17048Sensor::runOnce() +{ + if (isInitialized()) { + LOG_INFO("Init sensor: %s is already initialised", sensorName); + return true; + } + + LOG_INFO("Init sensor: %s", sensorName); + if (!hasSensor()) { + return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; + } + + // Get a singleton instance and initialise the max17048 + if (max17048 == nullptr) { + max17048 = MAX17048Singleton::GetInstance(); + } + status = max17048->runOnce(nodeTelemetrySensorsMap[sensorType].second); + return initI2CSensor(); +} + +void MAX17048Sensor::setup() {} + +bool MAX17048Sensor::getMetrics(meshtastic_Telemetry *measurement) +{ + LOG_DEBUG("MAX17048 getMetrics id: %i", measurement->which_variant); + + float volts = max17048->cellVoltage(); + if (isnan(volts)) { + LOG_DEBUG("MAX17048 getMetrics battery is not connected"); + return false; + } + + float rate = max17048->chargeRate(); // charge/discharge rate in percent/hr + float soc = max17048->cellPercent(); // state of charge in percent 0 to 100 + soc = clamp(soc, 0.0f, 100.0f); // clamp soc between 0 and 100% + float ttg = (100.0f - soc) / rate; // calculate hours to charge/discharge + + LOG_DEBUG("MAX17048 getMetrics volts: %.3fV soc: %.1f%% ttg: %.1f hours", volts, soc, ttg); + if ((int)measurement->which_variant == meshtastic_Telemetry_power_metrics_tag) { + measurement->variant.power_metrics.has_ch1_voltage = true; + measurement->variant.power_metrics.ch1_voltage = volts; + } else if ((int)measurement->which_variant == meshtastic_Telemetry_device_metrics_tag) { + measurement->variant.device_metrics.has_battery_level = true; + measurement->variant.device_metrics.has_voltage = true; + measurement->variant.device_metrics.battery_level = static_cast(round(soc)); + measurement->variant.device_metrics.voltage = volts; + } + return true; +} + +uint16_t MAX17048Sensor::getBusVoltageMv() +{ + return max17048->getBusVoltageMv(); +}; + +#endif + +#endif \ No newline at end of file diff --git a/src/modules/Telemetry/Sensor/MAX17261Sensor.h b/src/modules/Telemetry/Sensor/MAX17261Sensor.h new file mode 100644 index 000000000..6f61421dc --- /dev/null +++ b/src/modules/Telemetry/Sensor/MAX17261Sensor.h @@ -0,0 +1,111 @@ +#pragma once + +#ifndef MAX17048_SENSOR_H +#define MAX17048_SENSOR_H + +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_I2C && !defined(ARCH_STM32WL) && __has_include() + +// Samples to store in a buffer to determine if the battery is charging or discharging +#define MAX17048_CHARGING_SAMPLES 3 + +// Threshold to determine if the battery is on charge, in percent/hour +#define MAX17048_CHARGING_MINIMUM_RATE 1.0f + +// Threshold to determine if the board has bus power +#define MAX17048_BUS_POWER_VOLTS 4.195f + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "TelemetrySensor.h" +#include "VoltageSensor.h" + +#include "meshUtils.h" +#include +#include + +struct MAX17048ChargeSample { + float cellPercent; + float chargeRate; +}; + +enum MAX17048ChargeState { IDLE, EXPORT, IMPORT }; + +// Singleton wrapper for the Adafruit_MAX17048 class +class MAX17048Singleton : public Adafruit_MAX17048 +{ + private: + static MAX17048Singleton *pinstance; + bool initialized = false; + std::queue chargeSamples; + MAX17048ChargeState chargeState = IDLE; + const String chargeLabels[3] = {F("idle"), F("export"), F("import")}; + const char *sensorStr = "MAX17048Sensor"; + + protected: + MAX17048Singleton(); + ~MAX17048Singleton(); + + public: + // Create a singleton instance (not thread safe) + static MAX17048Singleton *GetInstance(); + + // Singletons should not be cloneable. + MAX17048Singleton(MAX17048Singleton &other) = delete; + + // Singletons should not be assignable. + void operator=(const MAX17048Singleton &) = delete; + + // Initialise the sensor (not thread safe) + virtual bool runOnce(TwoWire *theWire = &Wire); + + // Get the current bus voltage + uint16_t getBusVoltageMv(); + + // Get the state of charge in percent 0 to 100 + uint8_t getBusBatteryPercent(); + + // Calculate the seconds to charge/discharge + uint16_t getTimeToGoSecs(); + + // Returns true if the battery sensor has started + inline virtual bool isInitialised() { return initialized; }; + + // Returns true if the battery is currently on charge (not thread safe) + bool isBatteryCharging(); + + // Returns true if a battery is actually connected + bool isBatteryConnected(); + + // Returns true if there is bus or external power connected + bool isExternallyPowered(); +}; + +#if (HAS_TELEMETRY && (!MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR || !MESHTASTIC_EXCLUDE_POWER_TELEMETRY)) + +class MAX17048Sensor : public TelemetrySensor, VoltageSensor +{ + private: + MAX17048Singleton *max17048 = nullptr; + + protected: + virtual void setup() override; + + public: + MAX17048Sensor(); + + // Initialise the sensor + virtual int32_t runOnce() override; + + // Get the current bus voltage and state of charge + virtual bool getMetrics(meshtastic_Telemetry *measurement) override; + + // Get the current bus voltage + virtual uint16_t getBusVoltageMv() override; +}; + +#endif + +#endif + +#endif \ No newline at end of file diff --git a/variants/seeed_xiao_esp32c6/variant.h b/variants/seeed_xiao_esp32c6/variant.h index 0f24cde47..6b38b5409 100644 --- a/variants/seeed_xiao_esp32c6/variant.h +++ b/variants/seeed_xiao_esp32c6/variant.h @@ -23,9 +23,9 @@ #ifdef USE_SX1262 #define LORA_CS 21 -#define LORA_DIO1 2 -#define LORA_BUSY 0 -#define LORA_RESET 5 +#define LORA_DIO1 7 +#define LORA_BUSY 6 +#define LORA_RESET 2 #define SX126X_CS LORA_CS #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_BUSY @@ -41,4 +41,4 @@ #undef GPS_TX_PIN // For BLE/WiFi connectivity -#define USE_XIAO_ESP32C6_EXTERNAL_ANTENNA \ No newline at end of file +// #define USE_XIAO_ESP32C6_EXTERNAL_ANTENNA \ No newline at end of file From a34cfaee333a3211a2ddd11f52746f2e29c3fcc8 Mon Sep 17 00:00:00 2001 From: Alexander Begoon Date: Sat, 10 May 2025 13:11:00 +0200 Subject: [PATCH 9/9] Add MAX17261 sensor --- src/detect/ScanI2C.h | 1 + src/detect/ScanI2CTwoWire.cpp | 14 +++++++++++++- src/main.cpp | 1 + src/modules/Telemetry/PowerTelemetry.cpp | 2 ++ src/modules/Telemetry/Sensor/MAX17261Sensor.cpp | 2 +- src/modules/Telemetry/Sensor/MAX17261Sensor.h | 4 ++-- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index c363db1b5..ceb7369f8 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -28,6 +28,7 @@ class ScanI2C INA219, INA3221, MAX17048, + MAX17261, MCP9808, SHT31, SHT4X, diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 9781cbf56..080e67429 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -413,6 +413,19 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) #else SCAN_SIMPLE_CASE(PMSA0031_ADDR, PMSA0031, "PMSA0031", (uint8_t)addr.address) #endif + case MAX1704X_ADDR: + // Try to read the MAX17261 DevName register 0x21 first + // See: + // https://www.analog.com/media/en/technical-documentation/user-guides/max1726x-modelgauge-m5-ez-user-guide.pdf + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x21), 2); + if (registerValue == 0x3340) { + logFoundDevice("MAX17261", (uint8_t)addr.address); + type = MAX17261; + } else { + logFoundDevice("MAX17048", (uint8_t)addr.address); + type = MAX17048; + } + break; case BMA423_ADDR: // this can also be LIS3DH_ADDR_ALT registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x0F), 2); if (registerValue == 0x3300 || registerValue == 0x3333) { // RAK4631 WisBlock has LIS3DH register at 0x3333 @@ -431,7 +444,6 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) SCAN_SIMPLE_CASE(TSL25911_ADDR, TSL2591, "TSL2591", (uint8_t)addr.address); SCAN_SIMPLE_CASE(MLX90632_ADDR, MLX90632, "MLX90632", (uint8_t)addr.address); SCAN_SIMPLE_CASE(NAU7802_ADDR, NAU7802, "NAU7802", (uint8_t)addr.address); - SCAN_SIMPLE_CASE(MAX1704X_ADDR, MAX17048, "MAX17048", (uint8_t)addr.address); SCAN_SIMPLE_CASE(DFROBOT_RAIN_ADDR, DFROBOT_RAIN, "DFRobot Rain Gauge", (uint8_t)addr.address); SCAN_SIMPLE_CASE(LTR390UV_ADDR, LTR390UV, "LTR390UV", (uint8_t)addr.address); #ifdef HAS_TPS65233 diff --git a/src/main.cpp b/src/main.cpp index 8be3bc0ca..60cad4f89 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -708,6 +708,7 @@ void setup() scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::INA219, meshtastic_TelemetrySensorType_INA219); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::INA3221, meshtastic_TelemetrySensorType_INA3221); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::MAX17048, meshtastic_TelemetrySensorType_MAX17048); + scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::MAX17261, meshtastic_TelemetrySensorType_CUSTOM_SENSOR); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::MCP9808, meshtastic_TelemetrySensorType_MCP9808); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::SHT31, meshtastic_TelemetrySensorType_SHT31); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::SHTC3, meshtastic_TelemetrySensorType_SHTC3); diff --git a/src/modules/Telemetry/PowerTelemetry.cpp b/src/modules/Telemetry/PowerTelemetry.cpp index 07c21ac60..f7d773b62 100644 --- a/src/modules/Telemetry/PowerTelemetry.cpp +++ b/src/modules/Telemetry/PowerTelemetry.cpp @@ -186,6 +186,8 @@ bool PowerTelemetryModule::getPowerTelemetry(meshtastic_Telemetry *m) valid = ina3221Sensor.getMetrics(m); if (max17048Sensor.hasSensor()) valid = max17048Sensor.getMetrics(m); + if (max17261Sensor.hasSensor()) + valid = max17261Sensor.getMetrics(m); #endif return valid; diff --git a/src/modules/Telemetry/Sensor/MAX17261Sensor.cpp b/src/modules/Telemetry/Sensor/MAX17261Sensor.cpp index 6ab96aa57..91504a725 100644 --- a/src/modules/Telemetry/Sensor/MAX17261Sensor.cpp +++ b/src/modules/Telemetry/Sensor/MAX17261Sensor.cpp @@ -1,4 +1,4 @@ -#include "MAX17048Sensor.h" +#include "MAX17261Sensor.h" #if !MESHTASTIC_EXCLUDE_I2C && !defined(ARCH_STM32WL) && __has_include() diff --git a/src/modules/Telemetry/Sensor/MAX17261Sensor.h b/src/modules/Telemetry/Sensor/MAX17261Sensor.h index 6f61421dc..f01cf7f58 100644 --- a/src/modules/Telemetry/Sensor/MAX17261Sensor.h +++ b/src/modules/Telemetry/Sensor/MAX17261Sensor.h @@ -1,7 +1,7 @@ #pragma once -#ifndef MAX17048_SENSOR_H -#define MAX17048_SENSOR_H +#ifndef MAX17261_SENSOR_H +#define MAX17261_SENSOR_H #include "configuration.h"