[core] Allow specifying custom UF2 firmware name and version

This commit is contained in:
Kuba Szczodrzyński
2022-06-03 12:11:12 +02:00
parent 4c27aa57b1
commit 17dc1dcf8c
3 changed files with 34 additions and 5 deletions

View File

@@ -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,

View File

@@ -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.

View File

@@ -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: