refactor: migrate ESP32 firmware to task-managed services

Split the header-based firmware into services for OpenTherm, heating control, sensors, networking, logging, and the portal. Run these services with MycilaTaskManager and use ESP32OT for the boiler bus.

Move MQTT and Home Assistant discovery to Mycila libraries, expose native crash metrics, and align the board profiles and build hooks with the new dependencies.
This commit is contained in:
Yurii committed 2026-11-22 02:34:37 +03:00
1 parent b10d91b8fa
commit 3fb433d3eb
48 files changed
+14464 -12650

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
"""Apply environment flags after SDK compile environments are prepared."""
from pathlib import Path
import re
Import("env")
build_frameworks = env.BuildFrameworks
def no_exception_link_flags(sdk_directory):
cmake = (Path(sdk_directory) / "components/cxx/CMakeLists.txt").read_text()
wrappers = re.findall(r"set\(WRAP_FUNCTIONS\s+([^)]*)\)", cmake, re.S)
forced = re.findall(
r'if\(NOT CONFIG_COMPILER_CXX_EXCEPTIONS\)\s+'
r'target_link_libraries\(\$\{COMPONENT_LIB\} INTERFACE "(-u [A-Za-z_][A-Za-z0-9_]*)"\)\s+endif\(\)',
cmake
)
if len(wrappers) != 1 or len(forced) != 1:
raise RuntimeError("ESP-IDF C++ linker metadata changed; review tools/after_build_sdk.py")
symbols = wrappers[0].split()
if (not symbols or len(symbols) != len(set(symbols))
or not all(re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", symbol) for symbol in symbols)):
raise RuntimeError("Unsupported ESP-IDF C++ wrapper list")
return ["-Wl,--wrap=" + symbol for symbol in symbols] + forced[0].split()
def configure_after_build_sdk_flags(build_env, frameworks):
result = build_frameworks(frameworks)
# SDK environments are already cloned; project libraries are configured later.
flags = build_env.GetProjectOption("custom_app_flags", "")
build_env.ProcessFlags(flags)
link_flags = build_env.GetProjectOption("custom_link_flags", "").split()
sdkconfig = build_env.GetProjectOption("custom_sdkconfig", "")
if any(line.strip().strip("'\"") == "# CONFIG_COMPILER_CXX_EXCEPTIONS is not set"
for line in sdkconfig.splitlines()):
# HybridCompile does not transfer this component's interface linker flags.
sdk_directory = build_env.PioPlatform().get_package_dir("framework-espidf")
if not sdk_directory:
raise RuntimeError("ESP-IDF package is required for the C++ linker bridge")
link_flags += no_exception_link_flags(sdk_directory)
build_env.Append(LINKFLAGS=link_flags)
return result
env.AddMethod(configure_after_build_sdk_flags, "BuildFrameworks")
+10 -8
View File
@@ -6,17 +6,19 @@ Import("env")
def post_build(source, target, env):
copy_to_build_dir({
source[0].get_abspath(): "firmware_%s_%s.bin" % (env["PIOENV"], env.GetProjectOption("version")),
env.subst("$BUILD_DIR/${PROGNAME}.factory.bin"): "firmware_%s_%s.factory.bin" % (env["PIOENV"], env.GetProjectOption("version")),
env.subst("$BUILD_DIR/${PROGNAME}.elf"): "firmware_%s_%s.elf" % (env["PIOENV"], env.GetProjectOption("version"))
source[0].get_abspath(): "firmware_%s_%s.bin" % (env["PIOENV"], env.GetProjectOption("custom_version")),
env.subst("$BUILD_DIR/${PROGNAME}.factory.bin"): "firmware_%s_%s.factory.bin" % (env["PIOENV"], env.GetProjectOption("custom_version")),
env.subst("$BUILD_DIR/${PROGNAME}.elf"): "firmware_%s_%s.elf" % (env["PIOENV"], env.GetProjectOption("custom_version"))
}, os.path.join(env["PROJECT_DIR"], "build"));
env.Execute("pio run --target buildfs --environment %s" % env["PIOENV"]);
return env.Execute('"$PYTHONEXE" -m platformio run --target buildfs --environment "$PIOENV"')
def before_buildfs(source, target, env):
env.Execute("npm install --silent")
env.Execute("npx gulp build_all --no-deprecation")
result = env.Execute("npm install --silent")
if result:
return result
return env.Execute("npx gulp build_all --no-deprecation")
"""
src = os.path.join(env["PROJECT_DIR"], "src_data")
dst = os.path.join(env["PROJECT_DIR"], "data")
@@ -40,7 +42,7 @@ def before_buildfs(source, target, env):
def after_buildfs(source, target, env):
copy_to_build_dir({
source[0].get_abspath(): "filesystem_%s_%s.bin" % (env["PIOENV"], env.GetProjectOption("version")),
source[0].get_abspath(): "filesystem_%s_%s.bin" % (env["PIOENV"], env.GetProjectOption("custom_version")),
}, os.path.join(env["PROJECT_DIR"], "build"));
@@ -59,4 +61,4 @@ def copy_to_build_dir(files, build_dir):
env.AddPostAction("buildprog", post_build)
env.AddPreAction("$BUILD_DIR/spiffs.bin", before_buildfs)
env.AddPreAction("$BUILD_DIR/littlefs.bin", before_buildfs)
env.AddPostAction("buildfs", after_buildfs)
env.AddPostAction("buildfs", after_buildfs)
+64
View File
@@ -0,0 +1,64 @@
"""Provide Arduino TinyUSB for the ESP32-S2 HybridCompile SDK."""
from pathlib import Path
import shutil
import subprocess
Import("env")
def checkout(repository, revision, directory):
if not (directory / ".git").is_dir():
subprocess.run(["git", "clone", "--filter=blob:none", "--no-checkout",
repository, str(directory)], check=True)
current = subprocess.run(["git", "-C", str(directory), "rev-parse", "HEAD"],
check=True, capture_output=True, text=True).stdout.strip()
if not current.startswith(revision):
subprocess.run(["git", "-C", str(directory), "checkout", "--detach", revision], check=True)
platform = env.PioPlatform()
project = Path(env.subst("$PROJECT_DIR"))
framework = Path(platform.get_package_dir("framework-arduinoespressif32"))
dummy = project / ".dummy"
sdk = Path(platform.get_package_dir("framework-arduinoespressif32-libs"))
versions = {}
for line in (sdk / "versions.txt").read_text(encoding="utf-8").splitlines():
if ": " in line:
name, value = line.split(": ", 1)
versions[name] = value.split()[-1]
builder_revision = versions["lib-builder"]
tinyusb_revision = versions["tinyusb"]
cache = project / ".pio/tinyusb-s2"
cache.mkdir(parents=True, exist_ok=True)
builder = cache / ("lib-builder-" + builder_revision)
tinyusb = cache / ("tinyusb-" + tinyusb_revision)
checkout("https://github.com/espressif/esp32-arduino-lib-builder.git", builder_revision, builder)
checkout("https://github.com/hathach/tinyusb.git", tinyusb_revision, tinyusb)
original = builder / "components/arduino_tinyusb"
component = cache / ("component-" + builder_revision + "-" + tinyusb_revision) / "arduino_tinyusb"
cmake_file = component / "CMakeLists.txt"
if not cmake_file.is_file():
component.mkdir(parents=True, exist_ok=True)
shutil.copytree(original / "include", component / "include", dirs_exist_ok=True)
shutil.copytree(tinyusb / "src", component / "tinyusb/src", dirs_exist_ok=True)
shutil.copytree(tinyusb / "hw/bsp", component / "tinyusb/hw/bsp", dirs_exist_ok=True)
shutil.copyfile(original / "Kconfig.projbuild", component / "Kconfig.projbuild")
# Adapt only the generated build description to HybridCompile component names.
cmake = (original / "CMakeLists.txt").read_text(encoding="utf-8")
requires = "set(priv_requires arduino main)"
if requires not in cmake:
raise RuntimeError("Unsupported Arduino TinyUSB component dependencies")
cmake = cmake.replace(requires, f"set(priv_requires {framework.name} {dummy.name})")
if not cmake_file.is_file() or cmake_file.read_text(encoding="utf-8") != cmake:
cmake_file.write_text(cmake, encoding="utf-8")
# Keep HybridCompile's two default components when extending the CMake list.
dummy.mkdir(exist_ok=True)
directories = [dummy, framework, component]
arguments = env.BoardConfig().get("build.cmake_extra_args", "") or ""
arguments += ' "-DEXTRA_COMPONENT_DIRS:PATH=' + ";".join(path.as_posix() for path in directories) + '"'
env.BoardConfig().update("build.cmake_extra_args", arguments.strip())