summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2020-01-20 11:52:25 +0100
committerjaseg <git@jaseg.net>2020-01-20 11:52:25 +0100
commit5291970420560f232edaef99ef8149a4ccaffd64 (patch)
tree07df35b50073c06b83d6944eaa8390c56ea341b8 /Makefile
downloadiot-sensor-5291970420560f232edaef99ef8149a4ccaffd64.tar.gz
iot-sensor-5291970420560f232edaef99ef8149a4ccaffd64.tar.bz2
iot-sensor-5291970420560f232edaef99ef8149a4ccaffd64.zip
Initial commit
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile41
1 files changed, 41 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..dd83a4b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,41 @@
+ESPTOOL = esptool.py
+# TOOL can be 'mpfshell' or 'ampy'
+TOOL = mpfshell
+FIRMWARE = esp32-idf3-20191220-v1.12.bin
+PORT = /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0
+SHELL = /bin/sh
+MPY := $(patsubst %.py,%.mpy,$(wildcard *.py))
+
+
+.PHONY: erase flash all install clean repl help sanitize
+
+all: $(MPY)
+
+%.mpy: %.py ## Compile all python files
+ mpy-cross -march=xtensa -o $@ $<
+
+install: $(MPY) ## Copy all compiled python files to the ESP32
+ if [ "${TOOL}" = "mpfshell" ]; then ${TOOL} -n -c "open ${PORT:/dev/%=%}; mput ${MPY}"; fi
+ if [ "${TOOL}" = "ampy" ]; then ${TOOL} -p ${PORT} put *.mpy; fi
+
+sanitize: main.py.example
+
+%.py.example: %.py
+ sed -n '/#### CONFIG ####/,/#### END ####/{/^#/p;d};p' $< > $@
+
+clean: ## Delete all compiled python files
+ rm -f *.mpy
+
+erase: ## Erase the flash of the ESP32
+ ${ESPTOOL} --chip esp32 --port ${PORT} erase_flash
+
+flash: ## Download micropython firmware and flash to ESP32
+ curl -sSLO https://micropython.org/resources/firmware/${FIRMWARE}
+ ${ESPTOOL} --chip esp32 --port ${PORT} --baud 460800 write_flash -z 0x1000 ${FIRMWARE}
+
+repl: ## Start repl shell
+ if [ "${TOOL}" = "mpfshell" ]; then ${TOOL} -n -o ${BOARD} -c repl; fi
+ if [ "${TOOL}" != "mpfshell" ]; then screen /dev/${BOARD} ; fi
+
+help: ## Show this help
+ grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'