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 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/esp32c6.ini b/arch/esp32/esp32c6.ini index 26b5c0f5b..f55566b58 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,7 +30,9 @@ lib_deps = # renovate: datasource=git-refs depName=meshtastic-ESP32_Codec2 packageName=https://github.com/meshtastic/ESP32_Codec2 gitBranch=master 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 + rweather/Crypto@^0.4.0 + # 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} - diff --git a/bin/platformio-custom.py b/bin/platformio-custom.py index 600f9447f..c3782a14b 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,12 +131,13 @@ flags = [ print ("Using flags:") for flag in flags: print(flag) - -projenv.Append( - CCFLAGS=flags, -) + +if projenv: + projenv.Append(CCFLAGS=flags) + +env.Append(CCFLAGS=flags) for lb in env.GetLibBuilders(): if lb.name == "meshtastic-device-ui": lb.env.Append(CPPDEFINES=[("APP_VERSION", verObj["long"])]) - break + break \ No newline at end of file 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/sdkconfig.defaults b/sdkconfig.defaults new file mode 100644 index 000000000..61d5a1560 --- /dev/null +++ b/sdkconfig.defaults @@ -0,0 +1,37 @@ +# # 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 +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 142241c43..22bea21fc 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -9,10 +9,10 @@ #include "GpioLogic.h" #include "NodeDB.h" #include "PowerMon.h" -#include "RTC.h" #include "Throttle.h" #include "buzz.h" #include "concurrency/Periodic.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 2d49b2fbe..5a30cb299 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 @@ -1403,3 +1403,15 @@ void loop() } } #endif + +#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) +{ + 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 297c7b2ed..b7ab84e6c 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 0a79f94a8..3da2df813 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 e2acd8463..35180fb6b 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 fef29388e..c7dbe0b5a 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 789f8ac44..b0ad4342b 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 4005222dc..dac899d9a 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 dc17460f6..bebcef858 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 e072fcb0f..ed258a812 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 0b1bdcc46..d064601fb 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 6f3d69acf..2fa95f0c5 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 8d280581c..032d4b2ef 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 fafb28699..018d4d403 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 43c2dd84c..eefa7d383 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 "memGet.h" #include diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 6d29fecb2..622ce4e7b 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 54ec90dae..07c21ac60 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..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); diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index 3c4faac3e..53651466a 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -117,9 +117,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); @@ -170,8 +175,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); @@ -183,6 +189,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..f47bcd9d7 --- /dev/null +++ b/variants/seeed_xiao_esp32c6/platformio.ini @@ -0,0 +1,20 @@ +[env:seeed-xiao-esp32c6] +extends = esp32c6_base +framework = arduino, espidf +board = esp32-c6-devkitm-1 +board_check = true +board_build.partitions = partition-table.csv +upload_protocol = esptool +upload_speed = 921600 +extra_scripts = pre:bin/platformio-custom.py +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 diff --git a/variants/seeed_xiao_esp32c6/variant.h b/variants/seeed_xiao_esp32c6/variant.h new file mode 100644 index 000000000..0f24cde47 --- /dev/null +++ b/variants/seeed_xiao_esp32c6/variant.h @@ -0,0 +1,44 @@ +#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 + +// 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 2da10138a..ac2afcb75 100644 --- a/variants/tlora_c6/platformio.ini +++ b/variants/tlora_c6/platformio.ini @@ -1,9 +1,20 @@ [env:tlora-c6] extends = esp32c6_base +framework = arduino, espidf board = esp32-c6-devkitm-1 -build_flags = +board_check = true +board_build.partitions = partition-table.csv +upload_protocol = esptool +upload_speed = 921600 +extra_scripts = pre:bin/platformio-custom.py +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