diff --git a/builder/uf2.py b/builder/uf2.py index 21cfc4c..4342fa5 100644 --- a/builder/uf2.py +++ b/builder/uf2.py @@ -14,10 +14,14 @@ def env_uf2ota(env, *args, **kwargs): now = datetime.now() project_dir = env.subst("$PROJECT_DIR") project_name = basename(normpath(project_dir)) - # TODO support specifying custom version project_version = now.strftime("%y.%m.%d") lt_version = platform.version + if platform.custom("fw_name"): + project_name = platform.custom("fw_name") + if platform.custom("fw_version"): + project_version = platform.custom("fw_version") + inputs = " ".join(f'"{";".join(input)}"' for input in env["UF2OTA"]) output = [ project_name, diff --git a/docs/config.md b/docs/config.md index 5eb0799..1a80bcb 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1,4 +1,18 @@ -# LibreTuya API Configuration +# Configuration + +## Project options + +```ini +[env:my_board] +# custom firmware name, present in UF2 output files +# - default: project directory name +custom_fw_name = my_firmware +# custom firmware version +# - default: current date in yy.mm.dd format +custom_fw_version = 1.2.0 +``` + +## LibreTuya API Note: see [LibreTuyaConfig.h](../arduino/libretuya/core/LibreTuyaConfig.h) for most options and their defaults. @@ -9,7 +23,7 @@ build_flags = -D LT_LOGLEVEL=LT_LEVEL_DEBUG ``` -## Logging +### Logging - LT_LOGGER - enable/disable LibreTuya logger globally. Enabled by default. - LT_LOGLEVEL - global LT loglevel: @@ -25,7 +39,7 @@ build_flags = - LT_LOGGER_COLOR - output ANSI terminal colors - LT_PRINTF_BROKEN - whether printf outputs "0." for floats with value 0 -## Debug logging +### Debug logging The following options enable library-specific debugging messages. They are only effective if `LT_LOGLEVEL` is set below INFO. All of them are disabled by default. @@ -37,7 +51,7 @@ Families should generally call i.e. WiFiClient debugging for client-related code - LT_DEBUG_WIFI_STA - `WiFiSTA.cpp` - LT_DEBUG_WIFI_AP - `WiFiAP.cpp` -## Family options +### Family options - LT_HAS_LWIP - whether family SDK has LwIP. This causes `LwIPRxBuffer.cpp` to be compiled for family libraries to use. - LT_HAS_LWIP2 - whether family has LwIP v2.0.0 or newer. This causes `LwIPmDNS.cpp` to be compiled. diff --git a/platform.py b/platform.py index 452fa48..c1fc62b 100644 --- a/platform.py +++ b/platform.py @@ -77,6 +77,7 @@ def find_pkg_root(self, path: str, spec: PackageSpec): class LibretuyaPlatform(PlatformBase): boards_base: Dict[str, dict] = {} + custom_opts: Dict[str, object] = {} def configure_default_packages(self, options, targets): framework = options.get("pioframework")[0] @@ -141,8 +142,18 @@ class LibretuyaPlatform(PlatformBase): global libretuya_packages libretuya_packages = self.packages + # save custom options from env + self.custom_opts = {} + for key, value in options.items(): + if not key.startswith("custom_"): + continue + self.custom_opts[key[7:]] = value + return super().configure_default_packages(options, targets) + def custom(self, key: str) -> object: + return self.custom_opts.get(key, None) + def get_boards(self, id_=None): result = PlatformBase.get_boards(self, id_) if not result: