Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rp2040 pio tool download #4994

Merged
merged 3 commits into from Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 9 additions & 16 deletions esphome/components/rp2040/__init__.py
Expand Up @@ -16,8 +16,7 @@
KEY_TARGET_PLATFORM,
)
from esphome.core import CORE, coroutine_with_priority, EsphomeError
from esphome.helpers import mkdir_p, write_file
import esphome.platformio_api as api
from esphome.helpers import mkdir_p, write_file, copy_file_if_changed

from .const import KEY_BOARD, KEY_PIO_FILES, KEY_RP2040, rp2040_ns

Expand Down Expand Up @@ -193,25 +192,19 @@ def generate_pio_files() -> bool:
pio_path = CORE.relative_build_path(f"src/pio/{key}.pio")
mkdir_p(os.path.dirname(pio_path))
write_file(pio_path, data)
_LOGGER.info("Assembling PIO assembly code")
retval = api.run_platformio_cli(
"pkg",
"exec",
"--package",
"earlephilhower/tool-pioasm-rp2040-earlephilhower",
"--",
"pioasm",
pio_path,
pio_path + ".h",
)
includes.append(f"pio/{key}.pio.h")
if retval != 0:
raise EsphomeError("PIO assembly failed")

write_file(
CORE.relative_build_path("src/pio_includes.h"),
"#pragma once\n" + "\n".join([f'#include "{include}"' for include in includes]),
)

dir = os.path.dirname(__file__)
build_pio_file = os.path.join(dir, "build_pio.py.script")
copy_file_if_changed(
build_pio_file,
CORE.relative_build_path("build_pio.py"),
)

return True


Expand Down
47 changes: 47 additions & 0 deletions esphome/components/rp2040/build_pio.py.script
@@ -0,0 +1,47 @@
"""
Custom pioasm compiler script for platformio.
(c) 2022 by P.Z.

Sourced 2023/06/23 from https://gist.github.com/hexeguitar/f4533bc697c956ac1245b6843e2ef438

Modified by jesserockz 2023/06/23
"""

from os.path import join
import glob
import sys

import subprocess

# pylint: disable=E0602
Import("env") # noqa

from SCons.Script import ARGUMENTS


platform = env.PioPlatform()
PROJ_SRC = env["PROJECT_SRC_DIR"]
PIO_FILES = glob.glob(join(PROJ_SRC, "**", "*.pio"), recursive=True)

verbose = bool(int(ARGUMENTS.get("PIOVERBOSE", "0")))


if PIO_FILES:
if verbose:
print("==============================================")
print("PIO ASSEMBLY COMPILER")
try:
PIOASM_DIR = platform.get_package_dir("tool-pioasm-rp2040-earlephilhower")
except:
print("tool-pioasm-rp2040-earlephilhower not supported on your system!")
sys.exit()

PIOASM_EXE = join(PIOASM_DIR, "pioasm")
if verbose:
print("PIO files found:")
for filename in PIO_FILES:
if verbose:
print(f" {filename}")
subprocess.run([PIOASM_EXE, "-o", "c-sdk", filename, "{filename}.h"])
jesserockz marked this conversation as resolved.
Show resolved Hide resolved
if verbose:
print("==============================================")
40 changes: 40 additions & 0 deletions esphome/components/rp2040_pio/__init__.py
@@ -0,0 +1,40 @@
import platform

import esphome.codegen as cg


DEPENDENCIES = ["rp2040"]


PIOASM_REPO_VERSION = "1.5.0-b"
PIOASM_REPO_BASE = f"https://github.com/earlephilhower/pico-quick-toolchain/releases/download/{PIOASM_REPO_VERSION}"
PIOASM_VERSION = "pioasm-2e6142b.230216"
PIOASM_DOWNLOADS = {
"linux": {
"aarch64": f"aarch64-linux-gnu.{PIOASM_VERSION}.tar.gz",
"armv7l": f"arm-linux-gnueabihf.{PIOASM_VERSION}.tar.gz",
"x86_64": f"x86_64-linux-gnu.{PIOASM_VERSION}.tar.gz",
},
"windows": {
"amd64": f"x86_64-w64-mingw32.{PIOASM_VERSION}.zip",
},
"darwin": {
"x86_64": f"x86_64-apple-darwin14.{PIOASM_VERSION}.tar.gz",
"arm64": f"x86_64-apple-darwin14.{PIOASM_VERSION}.tar.gz",
},
}


async def to_code(config):
# cg.add_platformio_option(
# "platform_packages",
# [
# "earlephilhower/tool-pioasm-rp2040-earlephilhower",
# ],
# )
file = PIOASM_DOWNLOADS[platform.system().lower()][platform.machine().lower()]
cg.add_platformio_option(
"platform_packages",
[f"earlephilhower/tool-pioasm-rp2040-earlephilhower@{PIOASM_REPO_BASE}/{file}"],
)
cg.add_platformio_option("extra_scripts", ["pre:build_pio.py"])
7 changes: 1 addition & 6 deletions esphome/components/rp2040_pio_led_strip/light.py
Expand Up @@ -127,6 +127,7 @@ def time_to_cycles(time_us):

CONF_PIO = "pio"

AUTO_LOAD = ["rp2040_pio"]
CODEOWNERS = ["@Papa-DMan"]
DEPENDENCIES = ["rp2040"]

Expand Down Expand Up @@ -265,9 +266,3 @@ async def to_code(config):
time_to_cycles(config[CONF_BIT1_LOW]),
),
)
cg.add_platformio_option(
"platform_packages",
[
"earlephilhower/tool-pioasm-rp2040-earlephilhower",
],
)