diff --git a/builder/libs/lwip.py b/builder/libs/lwip.py new file mode 100644 index 0000000..c2bafdc --- /dev/null +++ b/builder/libs/lwip.py @@ -0,0 +1,49 @@ +# Copyright (c) Kuba SzczodrzyƄski 2022-05-18. + +from SCons.Script import DefaultEnvironment + +env = DefaultEnvironment() +platform = env.PioPlatform() + + +def env_add_lwip( + env, + version: str, + port: str, +): + # version = env["LIB_LWIP_VERSION"] if "LIB_LWIP_VERSION" in env else version_default + package_dir = platform.get_package_dir(f"library-lwip@{version}-{port}") + port_srcs = [] + port_includes = [] + + if port in ["amb1"]: + port_srcs = [ + "+", + "+", + ] + port_includes = [ + "+", + "+", + ] + + env.AddLibrary( + name=f"lwip{version}_{port}", + base_dir=package_dir, + srcs=[ + "+", + "+", + "+", + "+", # 2.0.x + "+", # 1.4.x + *port_srcs, + ], + includes=[ + "+", + "+", + "+", + *port_includes, + ], + ) + + +env.AddMethod(env_add_lwip, "AddLibraryLwIP") diff --git a/builder/main.py b/builder/main.py index f07ed14..057f06d 100644 --- a/builder/main.py +++ b/builder/main.py @@ -7,6 +7,8 @@ board = env.BoardConfig() # Utilities env.SConscript("utils.py", exports="env") +# Vendor-specific library ports +env.SConscript("libs/lwip.py", exports="env") # Firmware name if env.get("PROGNAME", "program") == "program": diff --git a/platform.json b/platform.json index 5e8f954..07a7191 100644 --- a/platform.json +++ b/platform.json @@ -40,6 +40,14 @@ "description": "Hardware independent layer of the Arduino cores" } }, + "library-lwip": { + "type": "framework", + "optional": true, + "base_url": "https://github.com/libretuya/lwip", + "manifest": { + "description": "lwIP - A Lightweight TCPIP stack" + } + }, "toolchain-gccarmnoneeabi": { "type": "toolchain", "optionalVersions": [ diff --git a/platform.py b/platform.py index 6fcccca..fe45386 100644 --- a/platform.py +++ b/platform.py @@ -99,6 +99,28 @@ class LibretuyaPlatform(PlatformBase): if framework.startswith("realtek-ambz"): self.packages["toolchain-gccarmnoneeabi"]["version"] = "~1.50401.0" + # use appropriate vendor library versions + sdk_package_name = self.frameworks[framework]["package"] + sdk_package = self.packages[sdk_package_name] + sdk_libraries = sdk_package["libraries"] if "libraries" in sdk_package else {} + packages_new = {} + for name, package in self.packages.items(): + if not name.startswith("library-"): + continue + name = name[8:] # strip "library-" + if name not in sdk_libraries: + continue + lib_version = sdk_libraries[name][-1] # get latest version tag + package = dict(**package) # clone the base package + package["version"] = ( + package["base_url"] + "#" + lib_version + ) # use the specific version + package["optional"] = False # make it required + lib_version = lib_version.lstrip("v") # strip "v" in target name + name = f"library-{name}@{lib_version}" + packages_new[name] = package # put the package under a new name + self.packages.update(packages_new) + # make ArduinoCore-API required if "arduino" in framework: self.packages["framework-arduino-api"]["optional"] = False