VENV = poetry run ESP_TOOL = $(VENV) esptool.py --port $(ESP_PORT) MPYCROSS = $(VENV) mpy-cross AMPY = $(VENV) ampy --port $(ESP_PORT) JUPYTER_PYTHON_FILES = $(shell find src/*.ipynb | sed "s/ipynb/py/g") # Downloaded from https://micropython.org/download/ESP8266_GENERIC/ MICRO_PYTHON_FIRMWARE = ESP8266_GENERIC-20240222-v1.22.2.bin ESP_PORT = /dev/ttyUSB0 src/%.py: src/%.ipynb $(VENV) jupyter nbconvert --to python $? \ --TagRemovePreprocessor.enabled=True \ --TagRemovePreprocessor.remove_cell_tags remove_cell src/%.mpy: src/%.py @for f in $(filter-out src/main.py,$?); do \ echo Compile $$f; \ $(MPYCROSS) $$f; \ done check: src/*.mpy $(VENV) python3 -m py_compile src/*.py erase_flash: $(ESP_TOOL) erase_flash flash_esp: erase_flash $(ESP_TOOL) --baud 460800 write_flash --flash_size=detect 0 $(MICRO_PYTHON_FIRMWARE) install: check $(JUPYTER_PYTHON_FILES) $(AMPY) put src/main.py @for f in $(filter-out check,$?); do \ echo Uploading $$f; \ $(AMPY) put $$f; \ done ifeq ($(MAKELEVEL),0) uninstall: @echo $(filter-out /boot.py,$(shell $(AMPY) ls --recursive)) for f in $(filter-out /boot.py,$(shell $(AMPY) ls --recursive)); do \ echo Deleting file $$f; \ $(AMPY) rm $$f; \ done $(MAKE) uninstall else uninstall: @echo $(filter-out /boot.py,$(shell $(AMPY) ls --recursive)) for f in $(filter-out /boot.py,$(shell $(AMPY) ls)); do \ echo Deleting directory $$f; \ $(AMPY) rmdir $$f; \ done endif clean: rm -rf src/__pycache__ rm -f src/*.pyc rm -f src/*.mpy rm -f $(JUPYTER_PYTHON_FILES) env: poetry install $(VENV) python -m jupyter_micropython_kernel.install .PHONY: check erase_flash flash_esp install uninstall clean env