Skip to content

Commit 1f047b7

Browse files
authored
Tasmota Platform 241130
1 parent 1600284 commit 1f047b7

File tree

8 files changed

+176
-99
lines changed

8 files changed

+176
-99
lines changed

.github/workflows/examples.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- "examples/arduino-blink"
1818
- "examples/arduino-rmt-blink"
1919
- "examples/arduino-wifiscan"
20+
- "examples/arduino-usb-keyboard"
2021
- "examples/espidf-arduino-blink"
2122
- "examples/espidf-arduino-littlefs"
2223
- "examples/espidf-blink"
@@ -44,7 +45,7 @@ jobs:
4445
python -m pip install --upgrade pip
4546
pip install wheel
4647
pip install -U https://github.com/Jason2866/platformio-core/archive/refs/tags/v6.1.16.tar.gz
47-
pio pkg install --global --platform symlink://.
48+
pio pkg install --global --platform file://.
4849
- name: git clone Tasmota and add to examples
4950
if: "matrix.example == 'examples/tasmota' && matrix.os != 'windows-2022'"
5051
run: |

builder/frameworks/arduino.py

Lines changed: 87 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -36,88 +36,47 @@
3636
from platformio.package.manager.tool import ToolPackageManager
3737

3838
env = DefaultEnvironment()
39+
pm = ToolPackageManager()
3940
platform = env.PioPlatform()
4041
config = env.GetProjectConfig()
4142
board = env.BoardConfig()
4243
mcu = board.get("build.mcu", "esp32")
4344
flag_custom_sdkconfig = config.has_option("env:"+env["PIOENV"], "custom_sdkconfig")
44-
framework_reinstall = False
45-
46-
extra_flags = ''.join([element.replace("-D", " ") for element in board.get("build.extra_flags", "")])
45+
extra_flags = (''.join([element for element in board.get("build.extra_flags", "")])).replace("-D", " ")
4746
build_flags = ''.join([element.replace("-D", " ") for element in env.GetProjectOption("build_flags")])
48-
pm = ToolPackageManager()
49-
50-
SConscript("_embed_files.py", exports="env")
47+
framework_reinstall = False
48+
flag_any_custom_sdkconfig = False
5149

52-
if ("CORE32SOLO1" in extra_flags or "FRAMEWORK_ARDUINO_SOLO1" in build_flags) and ("arduino" in env.subst("$PIOFRAMEWORK")) and flag_custom_sdkconfig == False:
50+
if ("CORE32SOLO1" in extra_flags or "FRAMEWORK_ARDUINO_SOLO1" in build_flags) and ("arduino" in env.subst("$PIOFRAMEWORK")) and not flag_custom_sdkconfig:
5351
FRAMEWORK_DIR = platform.get_package_dir("framework-arduino-solo1")
54-
elif ("CORE32ITEAD" in extra_flags or "FRAMEWORK_ARDUINO_ITEAD" in build_flags) and ("arduino" in env.subst("$PIOFRAMEWORK")) and flag_custom_sdkconfig == False:
52+
elif ("CORE32ITEAD" in extra_flags or "FRAMEWORK_ARDUINO_ITEAD" in build_flags) and ("arduino" in env.subst("$PIOFRAMEWORK")) and not flag_custom_sdkconfig:
5553
FRAMEWORK_DIR = platform.get_package_dir("framework-arduino-ITEAD")
5654
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:
5755
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
58-
elif "arduino" in env.subst("$PIOFRAMEWORK") and flag_custom_sdkconfig == True:
56+
elif "arduino" in env.subst("$PIOFRAMEWORK") and flag_custom_sdkconfig:
5957
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
6058

61-
flag_any_custom_sdkconfig = os.path.exists(join(FRAMEWORK_DIR,"tools","esp32-arduino-libs","sdkconfig"))
62-
63-
def get_MD5_hash(phrase):
64-
import hashlib
65-
return hashlib.md5((phrase).encode('utf-8')).hexdigest()[:16]
66-
67-
68-
def matching_custom_sdkconfig():
69-
# check if current env is matching to existing sdkconfig
70-
cust_sdk_is_present = False
71-
matching_sdkconfig = False
72-
last_sdkconfig_path = join(env.subst("$PROJECT_DIR"),"sdkconfig.defaults")
73-
if flag_any_custom_sdkconfig == False:
74-
matching_sdkconfig = True
75-
return matching_sdkconfig, cust_sdk_is_present
76-
if os.path.exists(last_sdkconfig_path) == False:
77-
return matching_sdkconfig, cust_sdk_is_present
78-
if flag_custom_sdkconfig == False:
79-
matching_sdkconfig = False
80-
return matching_sdkconfig, cust_sdk_is_present
81-
with open(last_sdkconfig_path) as src:
82-
line = src.readline()
83-
if line.startswith("# TASMOTA__"):
84-
cust_sdk_is_present = True;
85-
costum_options = env.GetProjectOption("custom_sdkconfig")
86-
if (line.split("__")[1]).strip() == get_MD5_hash((costum_options).strip() + mcu):
87-
matching_sdkconfig = True
88-
89-
return matching_sdkconfig, cust_sdk_is_present
90-
91-
def check_reinstall_frwrk():
92-
framework_reinstall = False
93-
cust_sdk_is_present = False
94-
matching_sdkconfig = False
95-
if flag_custom_sdkconfig:
96-
matching_sdkconfig, cust_sdk_is_present = matching_custom_sdkconfig()
97-
if flag_custom_sdkconfig == False and flag_any_custom_sdkconfig == True:
98-
# case custom sdkconfig exists and a env without "custom_sdkconfig"
99-
framework_reinstall = True
100-
if flag_custom_sdkconfig == True and matching_sdkconfig == False:
101-
# check if current custom sdkconfig is different from existing
102-
framework_reinstall = True
103-
return framework_reinstall
104-
105-
def call_compile_libs():
106-
print("*** Compile Arduino IDF libs for %s ***" % env["PIOENV"])
107-
SConscript("espidf.py")
108-
109-
if check_reinstall_frwrk() == True:
110-
print("*** Reinstall Arduino framework ***")
111-
shutil.rmtree(FRAMEWORK_DIR)
112-
ARDUINO_FRMWRK_URL = str(platform.get_package_spec("framework-arduinoespressif32")).split("uri=",1)[1][:-1]
113-
pm.install(ARDUINO_FRMWRK_URL)
114-
if flag_custom_sdkconfig == True:
115-
call_compile_libs()
116-
flag_custom_sdkconfig = False
117-
118-
if flag_custom_sdkconfig == True and flag_any_custom_sdkconfig == False:
119-
call_compile_libs()
59+
SConscript("_embed_files.py", exports="env")
12060

61+
if "framework-arduinoespressif32" in FRAMEWORK_DIR:
62+
flag_any_custom_sdkconfig = os.path.exists(join(platform.get_package_dir("framework-arduinoespressif32"),"tools","esp32-arduino-libs","sdkconfig"))
63+
64+
# Esp32-solo1 libs needs adopted settings
65+
if flag_custom_sdkconfig and "CORE32SOLO1" in extra_flags and "CONFIG_FREERTOS_UNICORE=y" in env.GetProjectOption("custom_sdkconfig"):
66+
if len(str(env.GetProjectOption("build_flags"))) > 2:
67+
build_flags = " ".join(env['BUILD_FLAGS'])
68+
build_flags = build_flags + " -Tesp32.rom.newlib-funcs.ld"
69+
new_build_flags = build_flags.split()
70+
env.Replace(
71+
BUILD_FLAGS=new_build_flags
72+
)
73+
if len(str(env.GetProjectOption("build_unflags"))) > 2:
74+
build_unflags = " ".join(env['BUILD_UNFLAGS'])
75+
build_unflags = build_unflags + " -mdisable-hardware-atomics -ustart_app_other_cores"
76+
new_build_unflags = build_unflags.split()
77+
env.Replace(
78+
BUILD_UNFLAGS=new_build_unflags
79+
)
12180

12281
def install_python_deps():
12382
def _get_installed_pip_packages():
@@ -176,6 +135,65 @@ def _get_installed_pip_packages():
176135
)
177136
return
178137

138+
install_python_deps()
139+
140+
def get_MD5_hash(phrase):
141+
import hashlib
142+
return hashlib.md5((phrase).encode('utf-8')).hexdigest()[:16]
143+
144+
145+
def matching_custom_sdkconfig():
146+
# check if current env is matching to existing sdkconfig
147+
cust_sdk_is_present = False
148+
matching_sdkconfig = False
149+
last_sdkconfig_path = join(env.subst("$PROJECT_DIR"),"sdkconfig.defaults")
150+
if flag_any_custom_sdkconfig == False:
151+
matching_sdkconfig = True
152+
return matching_sdkconfig, cust_sdk_is_present
153+
if os.path.exists(last_sdkconfig_path) == False:
154+
return matching_sdkconfig, cust_sdk_is_present
155+
if flag_custom_sdkconfig == False:
156+
matching_sdkconfig = False
157+
return matching_sdkconfig, cust_sdk_is_present
158+
with open(last_sdkconfig_path) as src:
159+
line = src.readline()
160+
if line.startswith("# TASMOTA__"):
161+
cust_sdk_is_present = True;
162+
costum_options = env.GetProjectOption("custom_sdkconfig")
163+
if (line.split("__")[1]).strip() == get_MD5_hash((costum_options).strip() + mcu):
164+
matching_sdkconfig = True
165+
166+
return matching_sdkconfig, cust_sdk_is_present
167+
168+
def check_reinstall_frwrk():
169+
framework_reinstall = False
170+
cust_sdk_is_present = False
171+
matching_sdkconfig = False
172+
if flag_custom_sdkconfig:
173+
matching_sdkconfig, cust_sdk_is_present = matching_custom_sdkconfig()
174+
if flag_custom_sdkconfig == False and flag_any_custom_sdkconfig == True:
175+
# case custom sdkconfig exists and a env without "custom_sdkconfig"
176+
framework_reinstall = True
177+
if flag_custom_sdkconfig == True and matching_sdkconfig == False:
178+
# check if current custom sdkconfig is different from existing
179+
framework_reinstall = True
180+
return framework_reinstall
181+
182+
def call_compile_libs():
183+
print("*** Compile Arduino IDF libs for %s ***" % env["PIOENV"])
184+
SConscript("espidf.py")
185+
186+
if check_reinstall_frwrk() == True:
187+
print("*** Reinstall Arduino framework ***")
188+
shutil.rmtree(platform.get_package_dir("framework-arduinoespressif32"))
189+
ARDUINO_FRMWRK_URL = str(platform.get_package_spec("framework-arduinoespressif32")).split("uri=",1)[1][:-1]
190+
pm.install(ARDUINO_FRMWRK_URL)
191+
if flag_custom_sdkconfig == True:
192+
call_compile_libs()
193+
flag_custom_sdkconfig = False
194+
195+
if flag_custom_sdkconfig == True and flag_any_custom_sdkconfig == False:
196+
call_compile_libs()
197+
179198
if "arduino" in env.subst("$PIOFRAMEWORK") and "espidf" not in env.subst("$PIOFRAMEWORK") and env.subst("$ARDUINO_LIB_COMPILE_FLAG") in ("Inactive", "True"):
180-
install_python_deps()
181199
SConscript(join(FRAMEWORK_DIR, "tools", "platformio-build.py"))

builder/frameworks/espidf.py

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
board = env.BoardConfig()
6363
mcu = board.get("build.mcu", "esp32")
6464
idf_variant = mcu.lower()
65+
flag_custom_sdkonfig = False
66+
flag_custom_component_add = False
67+
flag_custom_component_remove = False
6568

6669
IDF5 = (
6770
platform.get_package_version("framework-espidf")
@@ -90,7 +93,7 @@
9093

9194
# Arduino framework as a component is not compatible with ESP-IDF >5.3
9295
if "arduino" in env.subst("$PIOFRAMEWORK"):
93-
ARDUINO_FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") # todo Tasmota ?
96+
ARDUINO_FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
9497
# Possible package names in 'package@version' format is not compatible with CMake
9598
if "@" in os.path.basename(ARDUINO_FRAMEWORK_DIR):
9699
new_path = os.path.join(
@@ -115,8 +118,13 @@
115118
#
116119
if config.has_option("env:"+env["PIOENV"], "custom_sdkconfig"):
117120
flag_custom_sdkonfig = True
118-
else:
119-
flag_custom_sdkonfig = False
121+
122+
if config.has_option("env:"+env["PIOENV"], "custom_component_add"):
123+
flag_custom_component_add = True
124+
125+
if config.has_option("env:"+env["PIOENV"], "custom_component_remove"):
126+
flag_custom_component_remove = True
127+
120128

121129
def HandleArduinoIDFsettings(env):
122130
def get_MD5_hash(phrase):
@@ -125,7 +133,10 @@ def get_MD5_hash(phrase):
125133

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

131142
def get_flag(line):
@@ -162,6 +173,51 @@ def get_flag(line):
162173
else:
163174
return
164175

176+
def HandleArduinoCOMPONENTsettings(env):
177+
if flag_custom_component_add == True or flag_custom_component_remove == True: # todo remove duplicated
178+
import yaml
179+
from yaml import SafeLoader
180+
print("*** \"custom_component\" is used to select managed idf components ***")
181+
if flag_custom_component_remove == True:
182+
idf_custom_component_remove = env.GetProjectOption("custom_component_remove").splitlines()
183+
else:
184+
idf_custom_component_remove = ""
185+
if flag_custom_component_add == True:
186+
idf_custom_component_add = env.GetProjectOption("custom_component_add").splitlines()
187+
else:
188+
idf_custom_component_add = ""
189+
idf_component_yml_src = os.path.join(ARDUINO_FRAMEWORK_DIR, "idf_component.yml")
190+
if not bool(os.path.isfile(join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml.orig"))):
191+
shutil.copy(join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml"),join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml.orig"))
192+
yaml_file=open(idf_component_yml_src,"r")
193+
idf_component=yaml.load(yaml_file, Loader=SafeLoader)
194+
idf_component_str=json.dumps(idf_component) # convert to json string
195+
idf_component_json=json.loads(idf_component_str) # convert string to json dict
196+
197+
if idf_custom_component_remove != "":
198+
for entry in idf_custom_component_remove:
199+
# checking if the entry exists before removing
200+
if entry in idf_component_json["dependencies"]:
201+
print("*** Removing component:",entry)
202+
del idf_component_json["dependencies"][entry]
203+
204+
if idf_custom_component_add != "":
205+
for entry in idf_custom_component_add:
206+
# add entrys to json
207+
print("*** Adding component:",entry)
208+
# todo idf_component_json["dependencies"][entry]
209+
210+
idf_component_yml_file = open(os.path.join(ARDUINO_FRAMEWORK_DIR, "idf_component.yml"),"w")
211+
yaml.dump(idf_component_json, idf_component_yml_file)
212+
idf_component_yml_file.close()
213+
# print("JSON from modified idf_component.yml:")
214+
# print(json.dumps(idf_component_json))
215+
return
216+
return
217+
218+
if flag_custom_component_add == True or flag_custom_component_remove == True:
219+
HandleArduinoCOMPONENTsettings(env)
220+
165221
if flag_custom_sdkonfig:
166222
HandleArduinoIDFsettings(env)
167223
LIB_SOURCE = os.path.join(env.subst("$PROJECT_CORE_DIR"), "platforms", "espressif32", "builder", "build_lib")
@@ -1874,6 +1930,9 @@ def idf_lib_copy(source, target, env):
18741930
"*** Starting Arduino compile %s with custom libraries ***" % pio_cmd,
18751931
)
18761932
)
1933+
if flag_custom_component_add == True or flag_custom_component_remove == True:
1934+
shutil.copy(join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml.orig"),join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml"))
1935+
print("*** Original Arduino \"idf_component.yml\" restored ***")
18771936
env.AddPostAction("checkprogsize", idf_lib_copy)
18781937

18791938
#

builder/main.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,24 @@
2525
env = DefaultEnvironment()
2626
platform = env.PioPlatform()
2727
config = env.GetProjectConfig()
28-
29-
#
30-
# Helpers
31-
#
32-
28+
extra_flags = ''.join([element.replace("-D", " ") for element in env.BoardConfig().get("build.extra_flags", "")])
29+
build_flags = ''.join([element.replace("-D", " ") for element in env.GetProjectOption("build_flags")])
3330
flag_custom_sdkonfig = False
3431
if config.has_option("env:"+env["PIOENV"], "custom_sdkconfig"):
3532
flag_custom_sdkonfig = True
3633

37-
extra_flags = ''.join([element.replace("-D", " ") for element in env.BoardConfig().get("build.extra_flags", "")])
38-
build_flags = ''.join([element.replace("-D", " ") for element in env.GetProjectOption("build_flags")])
34+
#
35+
# Helpers
36+
#
3937

40-
if "CORE32SOLO1" in extra_flags or "FRAMEWORK_ARDUINO_SOLO1" in build_flags and flag_custom_sdkonfig == False:
38+
if "CORE32SOLO1" in extra_flags or "FRAMEWORK_ARDUINO_SOLO1" in build_flags and flag_custom_sdkonfig is False:
4139
FRAMEWORK_DIR = platform.get_package_dir("framework-arduino-solo1")
42-
elif "CORE32ITEAD" in extra_flags or "FRAMEWORK_ARDUINO_ITEAD" in build_flags and flag_custom_sdkonfig == False:
40+
elif "CORE32ITEAD" in extra_flags or "FRAMEWORK_ARDUINO_ITEAD" in build_flags and flag_custom_sdkonfig is False:
4341
FRAMEWORK_DIR = platform.get_package_dir("framework-arduino-ITEAD")
4442
else:
4543
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
4644

45+
4746
def BeforeUpload(target, source, env):
4847
upload_options = {}
4948
if "BOARD" in env:

examples/arduino-blink/platformio.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
platform = espressif32
1212
framework = arduino
1313
board = esp32-solo1
14-
build_flags = -DFRAMEWORK_ARDUINO_SOLO1
15-
-DLED_BUILTIN=2
14+
build_flags = -DLED_BUILTIN=2
15+
custom_sdkconfig = CONFIG_FREERTOS_UNICORE=y
1616

1717
[env:esp32-s3-120]
1818
platform = espressif32
@@ -42,5 +42,5 @@ monitor_speed = 115200
4242
platform = espressif32
4343
framework = arduino
4444
board = esp32-p4
45-
monitor_speed = 115200
4645
build_flags = -DLED_BUILTIN=2
46+
monitor_speed = 115200

examples/tasmota_platformio_override.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ default_envs =
66
tasmota32c2
77

88
[env:tasmota32_base]
9-
platform = symlink://.
9+
platform = file://.

0 commit comments

Comments
 (0)