Makefile 2 KB
Newer Older
1
2
3
4
5
6
7
8
9
PORT :=
BAUD := 115200

PIOBOARD = esp12e
PIOPROJ = firmware/esplogger
PIODIR = .pio

.PHONY: firmware monitor reset getport

10
all: firmware
11

12
13
14
15
install-platformio:
	wget https://bootstrap.pypa.io/get-pip.py && \
		sudo python get-pip.py && rm get-pip.py
	sudo pip install platformio
16

17
18
19
firmware: build upload monitor

build:
20
	@ echo "$$PIO_BUILD" | sh
21
22
23

upload:
	cd $(PIODIR) && platformio run -t upload
24

25
26
monitor:
	platformio device monitor
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

reset: getport
	@ echo "-----------------------------------------"
	@ echo "Reseting the board"
	esptool.py --port /dev/$(PORT) run
	@ python -c "import time; time.sleep(1)"

getport:
	@ $(eval PORT := `python utils/getport.py`)
	@ echo $(PORT)

example-blink:
	$(eval PIOPROJ := examples/blink)
	@ echo "$$PIO_BUILD" | sh

example-wifiscan:
	$(eval PIOPROJ := examples/wifiscan)
	@ echo "$$PIO_BUILD" | sh
	$(MAKE) monitor

example-sdcardinfo:
	$(eval PIOPROJ := examples/sd_card_info)
	@ echo "$$PIO_BUILD" | sh
	$(MAKE) monitor

help:
	@ echo "$$HELP_MAKEFILE"

55
56
57
clean:
	rm -rfv $(PIODIR)

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
define HELP_MAKEFILE
Usage:  make <target>   where <target> can be:

  firmware        Build and upload the esplogger firmware using platformio
  monitor         Start the picocom serial monitor (autodetect port)
  reset           Attempt a soft reset of the ESP devkit board

  example-____    Build and upload one of the examples/ projects:
                      blink      -- turn on and off the led on pin 2
                      wifiscan   -- detect and print all available SSIDs
endef
export HELP_MAKEFILE


define PY_GET_PORT
import os
ports = [x for x in os.listdir("/dev") if x.startswith("ttyUSB")
									   or x.startswith("ttyACM")]
if ports and isinstance(ports[0], str):
	print(ports[0])
else:
	print("Error: Unable to find a ttyUSB/ttyACM serial port")
	raise SystemExit(1)
endef
export PY_GET_PORT


define PIO_BUILD
	mkdir -p $(PIODIR)
	rm -rf $(PIODIR)/src
	platformio init --board $(PIOBOARD) -d $(PIODIR)
	cp -rf $(PIOPROJ)/* $(PIODIR)/src/
90
	cd $(PIODIR) && platformio run
91
92
endef
export PIO_BUILD