drop arduino, support zephyr boards

This commit is contained in:
Tomasz Duda 2024-02-21 23:18:51 +01:00
parent 7a7bcc6ed8
commit fda5d1a052
5 changed files with 43 additions and 30 deletions

View File

@ -42,7 +42,7 @@ AUTO_LOAD = ["zephyr"]
def set_core_data(config):
zephyr_set_core_data(config)
CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = PLATFORM_NRF52
CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = config[CONF_FRAMEWORK][CONF_TYPE]
CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = KEY_ZEPHYR
return config
@ -84,16 +84,12 @@ ZEPHYR_VARIANTS = [
ZEPHYR_VARIANT_NRF_SDK,
]
FRAMEWORK_VARIANTS = [
KEY_ZEPHYR,
"arduino",
]
FRAMEWORK_SCHEMA = cv.All(
cv.Schema(
{
cv.Required(CONF_TYPE): cv.one_of(*FRAMEWORK_VARIANTS, lower=True),
cv.Optional(CONF_VARIANT): cv.one_of(*ZEPHYR_VARIANTS, lower=True),
cv.Optional(CONF_VARIANT, default=ZEPHYR_VARIANT_NRF_SDK): cv.one_of(
*ZEPHYR_VARIANTS, lower=True
),
}
),
_platform_check_versions,
@ -109,21 +105,15 @@ def _detect_bootloader(value):
value = value.copy()
bootloader = None
if value[CONF_FRAMEWORK][CONF_TYPE] == KEY_ZEPHYR:
if (
value[CONF_BOARD] in BOARDS_ZEPHYR
and KEY_BOOTLOADER in BOARDS_ZEPHYR[value[CONF_BOARD]]
):
bootloader = BOARDS_ZEPHYR[value[CONF_BOARD]][KEY_BOOTLOADER]
if (
value[CONF_BOARD] in BOARDS_ZEPHYR
and KEY_BOOTLOADER in BOARDS_ZEPHYR[value[CONF_BOARD]]
):
bootloader = BOARDS_ZEPHYR[value[CONF_BOARD]][KEY_BOOTLOADER]
if KEY_BOOTLOADER not in value:
if bootloader is None:
if value[CONF_FRAMEWORK][CONF_TYPE] == KEY_ZEPHYR:
bootloader = BOOTLOADER_MCUBOOT
elif value[CONF_FRAMEWORK][CONF_TYPE] == "arduino":
bootloader = BOOTLOADER_ADAFRUIT
else:
raise NotImplementedError
bootloader = BOOTLOADER_MCUBOOT
value[KEY_BOOTLOADER] = bootloader
else:
if bootloader is not None and bootloader != value[KEY_BOOTLOADER]:
@ -153,7 +143,7 @@ async def to_code(config):
cg.add_define("ESPHOME_BOARD", config[CONF_BOARD])
cg.add_define("ESPHOME_VARIANT", "NRF52")
conf = config[CONF_FRAMEWORK]
cg.add_platformio_option(CONF_FRAMEWORK, conf[CONF_TYPE])
cg.add_platformio_option(CONF_FRAMEWORK, CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK])
cg.add_platformio_option("platform", conf[CONF_PLATFORM_VERSION])
if config[KEY_BOOTLOADER] == BOOTLOADER_ADAFRUIT:
@ -164,7 +154,9 @@ async def to_code(config):
cg.add_platformio_option("board_upload.require_upload_port", "true")
cg.add_platformio_option("board_upload.wait_for_upload_port", "true")
#
cg.add_platformio_option("extra_scripts", [f"pre:build_{conf[CONF_TYPE]}.py"])
cg.add_platformio_option(
"extra_scripts", [f"pre:build_{CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK]}.py"]
)
if CORE.using_zephyr:
zephyr_to_code(conf)
else:

View File

@ -14,11 +14,15 @@ from .const import (
)
from esphome.const import (
CONF_VARIANT,
CONF_BOARD,
)
KEY_BOARD = "board"
def zephyr_set_core_data(config):
CORE.data[KEY_ZEPHYR] = {}
CORE.data[KEY_ZEPHYR][KEY_BOARD] = config[CONF_BOARD]
CORE.data[KEY_ZEPHYR][KEY_PRJ_CONF] = {}
CORE.data[KEY_ZEPHYR][KEY_OVERLAY] = ""
return config
@ -66,6 +70,8 @@ def zephyr_to_code(conf):
"platformio/toolchain-gccarmnoneeabi@https://github.com/tomaszduda23/toolchain-sdk-ng",
],
)
# build is done by west so bypass board checking in platformio
cg.add_platformio_option("boards_dir", CORE.relative_build_path("boards"))
else:
raise NotImplementedError
# c++ support
@ -117,3 +123,22 @@ def zephyr_copy_files():
CORE.relative_build_path("zephyr/app.overlay"),
CORE.data[KEY_ZEPHYR][KEY_OVERLAY],
)
fake_board_manifest = """
{
"frameworks": [
"zephyr"
],
"name": "esphome nrf52",
"upload": {
"maximum_ram_size": 248832,
"maximum_size": 815104
},
"url": "https://esphome.io/",
"vendor": "esphome"
}
"""
write_file_if_changed(
CORE.relative_build_path(f"boards/{CORE.data[KEY_ZEPHYR][KEY_BOARD]}.json"),
fake_board_manifest,
)

View File

@ -585,6 +585,7 @@ void get_mac_address_raw(uint8_t *mac) { // NOLINT(readability-non-const-parame
#elif defined(USE_LIBRETINY)
WiFi.macAddress(mac);
#endif
//TODO
}
std::string get_mac_address() {
uint8_t mac[6];

View File

@ -2,7 +2,6 @@
nrf52:
board: adafruit_itsybitsy_nrf52840
framework:
type: zephyr
variant: generic
esphome:
@ -64,6 +63,3 @@ text_sensor:
reset_reason:
name: "Reset Reason"
deep_sleep:
run_duration: 10s
sleep_duration: 10s

View File

@ -1,10 +1,9 @@
---
nrf52:
# board: adafruit_itsybitsy_nrf52840
board: adafruit_feather_nrf52840
framework:
type: zephyr
variant: nrf-sdk
# board: adafruit_feather_nrf52840
board: nrf52840dk_nrf52840
# bootloader: adafruit
# bootloader: mcuboot