diff --git a/pico/.gitignore b/pico/.gitignore index bea566b..e3974e3 100644 --- a/pico/.gitignore +++ b/pico/.gitignore @@ -1,3 +1,4 @@ +build .venv typings src/secret.py \ No newline at end of file diff --git a/pico/Makefile b/pico/Makefile index 24842cd..beac495 100644 --- a/pico/Makefile +++ b/pico/Makefile @@ -1,6 +1,27 @@ +SRC_DIR := src +BUILD_DIR := build + +SRC_FILES := $(wildcard $(SRC_DIR)/*.py) $(wildcard $(SRC_DIR)/**/*.py) +BUILD_FILES := $(patsubst $(SRC_DIR)/%.py,$(BUILD_DIR)/%.mpy, $(SRC_FILES)) + +$(BUILD_DIR)/%.mpy: $(SRC_DIR)/%.py + @mkdir -p `dirname $@` + mpy-cross $< -o $@ + +.PHONY: build +build: $(BUILD_FILES) + +.PHONY: clean +clean: + rm -rf $(BUILD_DIR) + .PHONY: deploy -deploy: - mpremote fs cp src/* : +deploy: $(BUILD_FILES) + mpremote fs cp -r $(BUILD_DIR)/* : + +.PHONY: purge +purge: + mpremote run purge.py .PHONY: run run: deploy diff --git a/pico/README.md b/pico/README.md index 08eba16..af5b628 100644 --- a/pico/README.md +++ b/pico/README.md @@ -1,6 +1,20 @@ # Setup: -``` -$ python -m venv .venv -$ source .venv/bin/activate -$ pip install -U micropython-rp2-pico_w-stubs --no-user --target typings -``` +1. Set up the virtual environment: + ``` + $ python -m venv .venv + $ source .venv/bin/activate + ``` + +2. Install the type stubs: + ``` + $ pip install -U micropython-rp2-pico_w-stubs --no-user --target typings + ``` + +3. Ensure `mpy-cross` is available: + ``` + $ git clone https://github.com/micropython/micropython.git /tmp/micropython + $ pushd /tmp/micropython/mpy-cross + $ make + $ mv build/mpy-cross ~/.local/bin/ + $ popd + ``` \ No newline at end of file diff --git a/pico/purge.py b/pico/purge.py new file mode 100644 index 0000000..a0bea29 --- /dev/null +++ b/pico/purge.py @@ -0,0 +1,14 @@ +import os + +def rm(p: str, cwd: str = "/"): + path = cwd+p + print(f"rm {path=}") + try: + os.unlink(path) + except OSError: + for f in os.listdir(path): # pyright: ignore[reportAny] + rm(f, path+"/") # pyright: ignore[reportAny] + os.unlink(path) + +for f in os.listdir(): # pyright: ignore[reportAny] + rm(f) # pyright: ignore[reportAny]