-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
134 lines (112 loc) · 5.97 KB
/
Copy pathMakefile
File metadata and controls
134 lines (112 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
55
56
57
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
ARDUINO_CLI := arduino-cli
SKETCH := aikb.ino
CACHE_DIR := $(HOME)/Library/Caches/arduino/sketches
# Per-device build directories to avoid cache conflicts
BUILD_DIR_C := build/stickc
BUILD_DIR_CP := build/stickc-plus
BUILD_DIR_CARD := build/cardputer
FQBN_C := m5stack:esp32:m5stack_stickc
FQBN_CP := m5stack:esp32:m5stack_stickc_plus
FQBN_CARD := m5stack:esp32:m5stack_cardputer:PartitionScheme=huge_app,PSRAM=opi
PORT_C ?= /dev/cu.usbserial-6D4EA1CE41
PORT_CP ?= /dev/cu.usbserial-45D22F506E
PORT_CARD ?= /dev/cu.usbmodem1101
BAUD ?= 115200
UPLOAD_BAUD ?= 1500000
# Version. Single source of truth = the VERSION file (SemVer 2.0.0:
# MAJOR.MINOR.PATCH[-PRE] e.g. 0.1.0, or 0.2.0-dev between releases).
# Build metadata (git short hash + dirty marker) is appended automatically.
# Release flow:
# 1. ensure VERSION matches the intended SemVer (drop -dev suffix)
# 2. update CHANGELOG.md
# 3. commit, then `git tag v$(cat VERSION)`
# 4. bump VERSION to next "X.Y.Z-dev"
PKG_VERSION := $(shell cat $(CURDIR)/VERSION 2>/dev/null || echo 0.0.0-unknown)
GIT_SHA := $(shell git -C $(CURDIR) rev-parse --short HEAD 2>/dev/null || echo unknown)
GIT_DIRTY := $(shell git -C $(CURDIR) diff --quiet HEAD -- 2>/dev/null || echo -dirty)
FW_VERSION := v$(PKG_VERSION)+$(GIT_SHA)$(GIT_DIRTY)
# Last commit's ISO 8601 committer date — a clean rebuild from the same commit
# produces a byte-for-byte identical binary. Falls back to current UTC if not
# in a git repo.
BUILD_DATE := $(shell git -C $(CURDIR) log -1 --format=%cI 2>/dev/null || date -u '+%Y-%m-%dT%H:%MZ')
VERSION_FLAGS := "-DFW_VERSION=\"$(FW_VERSION)\"" "-DFW_BUILD_DATE=\"$(BUILD_DATE)\""
# arduino-cli's M5Stack core lives in different paths on Linux vs macOS;
# pick the first boot_app0.bin we find under either.
BOOT_APP0 := $(shell ls $(HOME)/.arduino15/packages/m5stack/hardware/esp32/*/tools/partitions/boot_app0.bin 2>/dev/null \
$(HOME)/Library/Arduino15/packages/m5stack/hardware/esp32/*/tools/partitions/boot_app0.bin 2>/dev/null \
| head -1)
# esptool's bundled pyserial crashes on macOS when a USB device has
# non-UTF8 characters in its IOKit name. scripts/esptool-utf8-safe.py
# monkey-patches IORegistryEntryGetName to decode with errors='replace';
# we call it via esptool's own bundled python so module paths line up.
ESPTOOL_PYTHON := /opt/homebrew/Cellar/esptool/5.1.0/libexec/bin/python
ESPTOOL_HELPER := $(CURDIR)/scripts/esptool-utf8-safe.py
ESPTOOL_CMD = $(ESPTOOL_PYTHON) $(ESPTOOL_HELPER) $(1)
.PHONY: help build-c build-cp build-card upload-c upload-cp upload-card flash-c flash-cp flash-card monitor-c monitor-cp monitor-card clean
help:
@echo "aikb firmware — M5StickC / M5StickC Plus / M5Cardputer"
@echo ""
@echo " make build-c compile for M5StickC"
@echo " make build-cp compile for M5StickC Plus"
@echo " make build-card compile for M5Cardputer"
@echo " make upload-c [PORT_C=...] upload to M5StickC"
@echo " make upload-cp [PORT_CP=...] upload to M5StickC Plus"
@echo " make upload-card [PORT_CARD=...] upload to M5Cardputer"
@echo " make flash-c [PORT_C=...] compile + upload (M5StickC)"
@echo " make flash-cp [PORT_CP=...] compile + upload (M5StickC Plus)"
@echo " make flash-card [PORT_CARD=...] compile + upload (M5Cardputer)"
@echo " make monitor-c [PORT_C=...] serial monitor M5StickC"
@echo " make monitor-cp [PORT_CP=...] serial monitor M5StickC Plus"
@echo " make monitor-card [PORT_CARD=...] serial monitor M5Cardputer"
@echo " make clean remove per-device build dirs"
@echo ""
@echo "Default serial ports:"
@echo " M5StickC: $(PORT_C)"
@echo " M5StickC Plus: $(PORT_CP)"
@echo " CardPuter: $(PORT_CARD)"
build-c:
$(ARDUINO_CLI) compile --fqbn $(FQBN_C) --build-path $(BUILD_DIR_C) \
--build-property "compiler.cpp.extra_flags=$(VERSION_FLAGS)" $(SKETCH)
build-cp:
$(ARDUINO_CLI) compile --fqbn $(FQBN_CP) --build-path $(BUILD_DIR_CP) \
--build-property "compiler.cpp.extra_flags=$(VERSION_FLAGS)" $(SKETCH)
build-card:
$(ARDUINO_CLI) compile --fqbn $(FQBN_CARD) --build-path $(BUILD_DIR_CARD) \
--build-property "compiler.cpp.extra_flags=$(VERSION_FLAGS)" $(SKETCH)
# Upload using arduino-cli first; if it hits the pyserial UTF-8 bug,
# fall back to esptool with monkey-patched pyserial.
# Uses per-partition writes (not merged.bin) to preserve NVS/bonding data.
upload-c:
@$(ARDUINO_CLI) upload --fqbn $(FQBN_C) -p $(PORT_C) --input-dir $(BUILD_DIR_C) \
--upload-property upload.speed=$(UPLOAD_BAUD) 2>&1 \
|| { echo "arduino-cli upload failed, falling back to patched esptool..."; \
$(call ESPTOOL_CMD,--chip esp32 --port $(PORT_C) --baud $(UPLOAD_BAUD) \
write-flash \
0x1000 $(BUILD_DIR_C)/$(SKETCH).bootloader.bin \
0x8000 $(BUILD_DIR_C)/$(SKETCH).partitions.bin \
0xe000 $(BOOT_APP0) \
0x10000 $(BUILD_DIR_C)/$(SKETCH).bin); }
upload-cp:
@$(ARDUINO_CLI) upload --fqbn $(FQBN_CP) -p $(PORT_CP) --input-dir $(BUILD_DIR_CP) \
--upload-property upload.speed=$(UPLOAD_BAUD) 2>&1 \
|| { echo "arduino-cli upload failed, falling back to patched esptool..."; \
$(call ESPTOOL_CMD,--chip esp32 --port $(PORT_CP) --baud $(UPLOAD_BAUD) \
write-flash \
0x1000 $(BUILD_DIR_CP)/$(SKETCH).bootloader.bin \
0x8000 $(BUILD_DIR_CP)/$(SKETCH).partitions.bin \
0xe000 $(BOOT_APP0) \
0x10000 $(BUILD_DIR_CP)/$(SKETCH).bin); }
upload-card:
$(ARDUINO_CLI) upload --fqbn $(FQBN_CARD) -p $(PORT_CARD) --input-dir $(BUILD_DIR_CARD)
flash-c: build-c upload-c
flash-cp: build-cp upload-cp
flash-card: build-card upload-card
monitor-card:
$(ARDUINO_CLI) monitor -p $(PORT_CARD) -c baudrate=$(BAUD)
monitor-c:
stty -f "$(PORT_C)" $(BAUD) && cat "$(PORT_C)"
monitor-cp:
stty -f "$(PORT_CP)" $(BAUD) && cat "$(PORT_CP)"
clean:
@rm -rf $(BUILD_DIR_C) $(BUILD_DIR_CP) $(BUILD_DIR_CARD)
@echo "build dirs cleaned"