Skip to content

Commit

Permalink
Tasmota Platform 241130
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2866 authored Oct 30, 2024
1 parent 1600284 commit 1f047b7
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 99 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- "examples/arduino-blink"
- "examples/arduino-rmt-blink"
- "examples/arduino-wifiscan"
- "examples/arduino-usb-keyboard"
- "examples/espidf-arduino-blink"
- "examples/espidf-arduino-littlefs"
- "examples/espidf-blink"
Expand Down Expand Up @@ -44,7 +45,7 @@ jobs:
python -m pip install --upgrade pip
pip install wheel
pip install -U https://github.com/Jason2866/platformio-core/archive/refs/tags/v6.1.16.tar.gz
pio pkg install --global --platform symlink://.
pio pkg install --global --platform file://.
- name: git clone Tasmota and add to examples
if: "matrix.example == 'examples/tasmota' && matrix.os != 'windows-2022'"
run: |
Expand Down
156 changes: 87 additions & 69 deletions builder/frameworks/arduino.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,88 +36,47 @@
from platformio.package.manager.tool import ToolPackageManager

env = DefaultEnvironment()
pm = ToolPackageManager()
platform = env.PioPlatform()
config = env.GetProjectConfig()
board = env.BoardConfig()
mcu = board.get("build.mcu", "esp32")
flag_custom_sdkconfig = config.has_option("env:"+env["PIOENV"], "custom_sdkconfig")
framework_reinstall = False

extra_flags = ''.join([element.replace("-D", " ") for element in board.get("build.extra_flags", "")])
extra_flags = (''.join([element for element in board.get("build.extra_flags", "")])).replace("-D", " ")
build_flags = ''.join([element.replace("-D", " ") for element in env.GetProjectOption("build_flags")])
pm = ToolPackageManager()

SConscript("_embed_files.py", exports="env")
framework_reinstall = False
flag_any_custom_sdkconfig = False

if ("CORE32SOLO1" in extra_flags or "FRAMEWORK_ARDUINO_SOLO1" in build_flags) and ("arduino" in env.subst("$PIOFRAMEWORK")) and flag_custom_sdkconfig == False:
if ("CORE32SOLO1" in extra_flags or "FRAMEWORK_ARDUINO_SOLO1" in build_flags) and ("arduino" in env.subst("$PIOFRAMEWORK")) and not flag_custom_sdkconfig:
FRAMEWORK_DIR = platform.get_package_dir("framework-arduino-solo1")
elif ("CORE32ITEAD" in extra_flags or "FRAMEWORK_ARDUINO_ITEAD" in build_flags) and ("arduino" in env.subst("$PIOFRAMEWORK")) and flag_custom_sdkconfig == False:
elif ("CORE32ITEAD" in extra_flags or "FRAMEWORK_ARDUINO_ITEAD" in build_flags) and ("arduino" in env.subst("$PIOFRAMEWORK")) and not flag_custom_sdkconfig:
FRAMEWORK_DIR = platform.get_package_dir("framework-arduino-ITEAD")
elif "arduino" in env.subst("$PIOFRAMEWORK") and "CORE32SOLO1" not in extra_flags and "FRAMEWORK_ARDUINO_SOLO1" not in build_flags and "CORE32ITEAD" not in extra_flags and "FRAMEWORK_ARDUINO_ITEAD" not in build_flags:
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
elif "arduino" in env.subst("$PIOFRAMEWORK") and flag_custom_sdkconfig == True:
elif "arduino" in env.subst("$PIOFRAMEWORK") and flag_custom_sdkconfig:
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")

flag_any_custom_sdkconfig = os.path.exists(join(FRAMEWORK_DIR,"tools","esp32-arduino-libs","sdkconfig"))

def get_MD5_hash(phrase):
import hashlib
return hashlib.md5((phrase).encode('utf-8')).hexdigest()[:16]


def matching_custom_sdkconfig():
# check if current env is matching to existing sdkconfig
cust_sdk_is_present = False
matching_sdkconfig = False
last_sdkconfig_path = join(env.subst("$PROJECT_DIR"),"sdkconfig.defaults")
if flag_any_custom_sdkconfig == False:
matching_sdkconfig = True
return matching_sdkconfig, cust_sdk_is_present
if os.path.exists(last_sdkconfig_path) == False:
return matching_sdkconfig, cust_sdk_is_present
if flag_custom_sdkconfig == False:
matching_sdkconfig = False
return matching_sdkconfig, cust_sdk_is_present
with open(last_sdkconfig_path) as src:
line = src.readline()
if line.startswith("# TASMOTA__"):
cust_sdk_is_present = True;
costum_options = env.GetProjectOption("custom_sdkconfig")
if (line.split("__")[1]).strip() == get_MD5_hash((costum_options).strip() + mcu):
matching_sdkconfig = True

return matching_sdkconfig, cust_sdk_is_present

def check_reinstall_frwrk():
framework_reinstall = False
cust_sdk_is_present = False
matching_sdkconfig = False
if flag_custom_sdkconfig:
matching_sdkconfig, cust_sdk_is_present = matching_custom_sdkconfig()
if flag_custom_sdkconfig == False and flag_any_custom_sdkconfig == True:
# case custom sdkconfig exists and a env without "custom_sdkconfig"
framework_reinstall = True
if flag_custom_sdkconfig == True and matching_sdkconfig == False:
# check if current custom sdkconfig is different from existing
framework_reinstall = True
return framework_reinstall

def call_compile_libs():
print("*** Compile Arduino IDF libs for %s ***" % env["PIOENV"])
SConscript("espidf.py")

if check_reinstall_frwrk() == True:
print("*** Reinstall Arduino framework ***")
shutil.rmtree(FRAMEWORK_DIR)
ARDUINO_FRMWRK_URL = str(platform.get_package_spec("framework-arduinoespressif32")).split("uri=",1)[1][:-1]
pm.install(ARDUINO_FRMWRK_URL)
if flag_custom_sdkconfig == True:
call_compile_libs()
flag_custom_sdkconfig = False

if flag_custom_sdkconfig == True and flag_any_custom_sdkconfig == False:
call_compile_libs()
SConscript("_embed_files.py", exports="env")

if "framework-arduinoespressif32" in FRAMEWORK_DIR:
flag_any_custom_sdkconfig = os.path.exists(join(platform.get_package_dir("framework-arduinoespressif32"),"tools","esp32-arduino-libs","sdkconfig"))

# Esp32-solo1 libs needs adopted settings
if flag_custom_sdkconfig and "CORE32SOLO1" in extra_flags and "CONFIG_FREERTOS_UNICORE=y" in env.GetProjectOption("custom_sdkconfig"):
if len(str(env.GetProjectOption("build_flags"))) > 2:
build_flags = " ".join(env['BUILD_FLAGS'])
build_flags = build_flags + " -Tesp32.rom.newlib-funcs.ld"
new_build_flags = build_flags.split()
env.Replace(
BUILD_FLAGS=new_build_flags
)
if len(str(env.GetProjectOption("build_unflags"))) > 2:
build_unflags = " ".join(env['BUILD_UNFLAGS'])
build_unflags = build_unflags + " -mdisable-hardware-atomics -ustart_app_other_cores"
new_build_unflags = build_unflags.split()
env.Replace(
BUILD_UNFLAGS=new_build_unflags
)

def install_python_deps():
def _get_installed_pip_packages():
Expand Down Expand Up @@ -176,6 +135,65 @@ def _get_installed_pip_packages():
)
return

install_python_deps()

def get_MD5_hash(phrase):
import hashlib
return hashlib.md5((phrase).encode('utf-8')).hexdigest()[:16]


def matching_custom_sdkconfig():
# check if current env is matching to existing sdkconfig
cust_sdk_is_present = False
matching_sdkconfig = False
last_sdkconfig_path = join(env.subst("$PROJECT_DIR"),"sdkconfig.defaults")
if flag_any_custom_sdkconfig == False:
matching_sdkconfig = True
return matching_sdkconfig, cust_sdk_is_present
if os.path.exists(last_sdkconfig_path) == False:
return matching_sdkconfig, cust_sdk_is_present
if flag_custom_sdkconfig == False:
matching_sdkconfig = False
return matching_sdkconfig, cust_sdk_is_present
with open(last_sdkconfig_path) as src:
line = src.readline()
if line.startswith("# TASMOTA__"):
cust_sdk_is_present = True;
costum_options = env.GetProjectOption("custom_sdkconfig")
if (line.split("__")[1]).strip() == get_MD5_hash((costum_options).strip() + mcu):
matching_sdkconfig = True

return matching_sdkconfig, cust_sdk_is_present

def check_reinstall_frwrk():
framework_reinstall = False
cust_sdk_is_present = False
matching_sdkconfig = False
if flag_custom_sdkconfig:
matching_sdkconfig, cust_sdk_is_present = matching_custom_sdkconfig()
if flag_custom_sdkconfig == False and flag_any_custom_sdkconfig == True:
# case custom sdkconfig exists and a env without "custom_sdkconfig"
framework_reinstall = True
if flag_custom_sdkconfig == True and matching_sdkconfig == False:
# check if current custom sdkconfig is different from existing
framework_reinstall = True
return framework_reinstall

def call_compile_libs():
print("*** Compile Arduino IDF libs for %s ***" % env["PIOENV"])
SConscript("espidf.py")

if check_reinstall_frwrk() == True:
print("*** Reinstall Arduino framework ***")
shutil.rmtree(platform.get_package_dir("framework-arduinoespressif32"))
ARDUINO_FRMWRK_URL = str(platform.get_package_spec("framework-arduinoespressif32")).split("uri=",1)[1][:-1]
pm.install(ARDUINO_FRMWRK_URL)
if flag_custom_sdkconfig == True:
call_compile_libs()
flag_custom_sdkconfig = False

if flag_custom_sdkconfig == True and flag_any_custom_sdkconfig == False:
call_compile_libs()

if "arduino" in env.subst("$PIOFRAMEWORK") and "espidf" not in env.subst("$PIOFRAMEWORK") and env.subst("$ARDUINO_LIB_COMPILE_FLAG") in ("Inactive", "True"):
install_python_deps()
SConscript(join(FRAMEWORK_DIR, "tools", "platformio-build.py"))
67 changes: 63 additions & 4 deletions builder/frameworks/espidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
board = env.BoardConfig()
mcu = board.get("build.mcu", "esp32")
idf_variant = mcu.lower()
flag_custom_sdkonfig = False
flag_custom_component_add = False
flag_custom_component_remove = False

IDF5 = (
platform.get_package_version("framework-espidf")
Expand Down Expand Up @@ -90,7 +93,7 @@

# Arduino framework as a component is not compatible with ESP-IDF >5.3
if "arduino" in env.subst("$PIOFRAMEWORK"):
ARDUINO_FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") # todo Tasmota ?
ARDUINO_FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
# Possible package names in 'package@version' format is not compatible with CMake
if "@" in os.path.basename(ARDUINO_FRAMEWORK_DIR):
new_path = os.path.join(
Expand All @@ -115,8 +118,13 @@
#
if config.has_option("env:"+env["PIOENV"], "custom_sdkconfig"):
flag_custom_sdkonfig = True
else:
flag_custom_sdkonfig = False

if config.has_option("env:"+env["PIOENV"], "custom_component_add"):
flag_custom_component_add = True

if config.has_option("env:"+env["PIOENV"], "custom_component_remove"):
flag_custom_component_remove = True


def HandleArduinoIDFsettings(env):
def get_MD5_hash(phrase):
Expand All @@ -125,7 +133,10 @@ def get_MD5_hash(phrase):

if flag_custom_sdkonfig == True:
print("*** Add \"custom_sdkconfig\" settings to IDF sdkconfig.defaults ***")
idf_config_flags = env.GetProjectOption("custom_sdkconfig").splitlines()
idf_config_flags = env.GetProjectOption("custom_sdkconfig")
if mcu in ("esp32") and "CONFIG_FREERTOS_UNICORE=y" in idf_config_flags:
idf_config_flags = idf_config_flags + "\n# CONFIG_SPIRAM is not set\n"
idf_config_flags = idf_config_flags.splitlines()
sdkconfig_src = join(ARDUINO_FRAMEWORK_DIR,"tools","esp32-arduino-libs",mcu,"sdkconfig")

def get_flag(line):
Expand Down Expand Up @@ -162,6 +173,51 @@ def get_flag(line):
else:
return

def HandleArduinoCOMPONENTsettings(env):
if flag_custom_component_add == True or flag_custom_component_remove == True: # todo remove duplicated
import yaml
from yaml import SafeLoader
print("*** \"custom_component\" is used to select managed idf components ***")
if flag_custom_component_remove == True:
idf_custom_component_remove = env.GetProjectOption("custom_component_remove").splitlines()
else:
idf_custom_component_remove = ""
if flag_custom_component_add == True:
idf_custom_component_add = env.GetProjectOption("custom_component_add").splitlines()
else:
idf_custom_component_add = ""
idf_component_yml_src = os.path.join(ARDUINO_FRAMEWORK_DIR, "idf_component.yml")
if not bool(os.path.isfile(join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml.orig"))):
shutil.copy(join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml"),join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml.orig"))
yaml_file=open(idf_component_yml_src,"r")
idf_component=yaml.load(yaml_file, Loader=SafeLoader)
idf_component_str=json.dumps(idf_component) # convert to json string
idf_component_json=json.loads(idf_component_str) # convert string to json dict

if idf_custom_component_remove != "":
for entry in idf_custom_component_remove:
# checking if the entry exists before removing
if entry in idf_component_json["dependencies"]:
print("*** Removing component:",entry)
del idf_component_json["dependencies"][entry]

if idf_custom_component_add != "":
for entry in idf_custom_component_add:
# add entrys to json
print("*** Adding component:",entry)
# todo idf_component_json["dependencies"][entry]

idf_component_yml_file = open(os.path.join(ARDUINO_FRAMEWORK_DIR, "idf_component.yml"),"w")
yaml.dump(idf_component_json, idf_component_yml_file)
idf_component_yml_file.close()
# print("JSON from modified idf_component.yml:")
# print(json.dumps(idf_component_json))
return
return

if flag_custom_component_add == True or flag_custom_component_remove == True:
HandleArduinoCOMPONENTsettings(env)

if flag_custom_sdkonfig:
HandleArduinoIDFsettings(env)
LIB_SOURCE = os.path.join(env.subst("$PROJECT_CORE_DIR"), "platforms", "espressif32", "builder", "build_lib")
Expand Down Expand Up @@ -1874,6 +1930,9 @@ def idf_lib_copy(source, target, env):
"*** Starting Arduino compile %s with custom libraries ***" % pio_cmd,
)
)
if flag_custom_component_add == True or flag_custom_component_remove == True:
shutil.copy(join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml.orig"),join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml"))
print("*** Original Arduino \"idf_component.yml\" restored ***")
env.AddPostAction("checkprogsize", idf_lib_copy)

#
Expand Down
17 changes: 8 additions & 9 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,24 @@
env = DefaultEnvironment()
platform = env.PioPlatform()
config = env.GetProjectConfig()

#
# Helpers
#

extra_flags = ''.join([element.replace("-D", " ") for element in env.BoardConfig().get("build.extra_flags", "")])
build_flags = ''.join([element.replace("-D", " ") for element in env.GetProjectOption("build_flags")])
flag_custom_sdkonfig = False
if config.has_option("env:"+env["PIOENV"], "custom_sdkconfig"):
flag_custom_sdkonfig = True

extra_flags = ''.join([element.replace("-D", " ") for element in env.BoardConfig().get("build.extra_flags", "")])
build_flags = ''.join([element.replace("-D", " ") for element in env.GetProjectOption("build_flags")])
#
# Helpers
#

if "CORE32SOLO1" in extra_flags or "FRAMEWORK_ARDUINO_SOLO1" in build_flags and flag_custom_sdkonfig == False:
if "CORE32SOLO1" in extra_flags or "FRAMEWORK_ARDUINO_SOLO1" in build_flags and flag_custom_sdkonfig is False:
FRAMEWORK_DIR = platform.get_package_dir("framework-arduino-solo1")
elif "CORE32ITEAD" in extra_flags or "FRAMEWORK_ARDUINO_ITEAD" in build_flags and flag_custom_sdkonfig == False:
elif "CORE32ITEAD" in extra_flags or "FRAMEWORK_ARDUINO_ITEAD" in build_flags and flag_custom_sdkonfig is False:
FRAMEWORK_DIR = platform.get_package_dir("framework-arduino-ITEAD")
else:
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")


def BeforeUpload(target, source, env):
upload_options = {}
if "BOARD" in env:
Expand Down
6 changes: 3 additions & 3 deletions examples/arduino-blink/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
platform = espressif32
framework = arduino
board = esp32-solo1
build_flags = -DFRAMEWORK_ARDUINO_SOLO1
-DLED_BUILTIN=2
build_flags = -DLED_BUILTIN=2
custom_sdkconfig = CONFIG_FREERTOS_UNICORE=y

[env:esp32-s3-120]
platform = espressif32
Expand Down Expand Up @@ -42,5 +42,5 @@ monitor_speed = 115200
platform = espressif32
framework = arduino
board = esp32-p4
monitor_speed = 115200
build_flags = -DLED_BUILTIN=2
monitor_speed = 115200
2 changes: 1 addition & 1 deletion examples/tasmota_platformio_override.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ default_envs =
tasmota32c2

[env:tasmota32_base]
platform = symlink://.
platform = file://.
Loading

0 comments on commit 1f047b7

Please sign in to comment.