Makefile 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # OpenPuck developer convenience targets.
  2. # Pin to clang-format 18 to match CI; output differs between versions, so a
  3. # mismatch would make CI reject locally-formatted code. Resolve the binary in
  4. # order of preference: the apt-style versioned name (CI / Linux), the Homebrew
  5. # llvm@18 keg (macOS), then a bare clang-format as a last resort. Override with
  6. # `make format CLANG_FORMAT=/path/to/clang-format` if yours lives elsewhere.
  7. CLANG_FORMAT ?= $(shell command -v clang-format-18 \
  8. || ([ -x /opt/homebrew/opt/llvm@18/bin/clang-format ] && echo /opt/homebrew/opt/llvm@18/bin/clang-format) \
  9. || ([ -x /usr/local/opt/llvm@18/bin/clang-format ] && echo /usr/local/opt/llvm@18/bin/clang-format) \
  10. || command -v clang-format)
  11. # All hand-written C/C++ sources. Generated headers (git_version.h) are
  12. # gitignored and excluded here so formatting never touches them.
  13. FORMAT_FILES := $(shell find OpenPuck ReversePuckFirmware puck_sniffer pairtui \
  14. \( -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' -o -name '*.ino' \) \
  15. -not -name 'git_version.h')
  16. # --- firmware build ---------------------------------------------------------
  17. # The OpenPuck firmware needs two TinyUSB config values that differ from the Adafruit nRF52 core defaults:
  18. # CFG_TUD_HID=4 -- four HID interfaces (Steam mode exposes four puck slots); core default is 2.
  19. # CFG_TUD_TASK_QUEUE_SZ=64 -- deeper usbd event queue; the default 16 deadlocks the loop task under comms
  20. # load -> watchdog reset (see OpenPuck.ino + docs/BUILD_AND_DEPLOY.md).
  21. # They're baked in here so a normal build is just `make build` -- no need to remember the flags. Override any
  22. # on the command line, e.g. make build CFG_TUD_HID=6 CFG_TUD_TASK_QUEUE_SZ=128
  23. # or add your own defines: make build EXTRA_FLAGS="-DOPK_LOG=1"
  24. FQBN ?= adafruit:nrf52:feather52840
  25. CFG_TUD_HID ?= 4
  26. CFG_TUD_TASK_QUEUE_SZ ?= 64
  27. EXTRA_FLAGS ?=
  28. # {build.flags.usb} is expanded by arduino-cli (VID/PID/strings); pass it through verbatim.
  29. USB_EXTRA_FLAGS = -DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=$(CFG_TUD_HID) -DCFG_TUD_TASK_QUEUE_SZ=$(CFG_TUD_TASK_QUEUE_SZ) $(EXTRA_FLAGS)
  30. .PHONY: format format-check check build build-recovery
  31. ## Compile the firmware with the required USB flags baked in. Override CFG_TUD_HID / CFG_TUD_TASK_QUEUE_SZ /
  32. ## EXTRA_FLAGS / FQBN as make variables if needed.
  33. build:
  34. arduino-cli compile -b $(FQBN) --build-property "build.extra_flags=$(USB_EXTRA_FLAGS)" OpenPuck
  35. ## One-time factory-reset recovery image (wipes persistent storage once on first boot). See §6 of the build doc.
  36. build-recovery:
  37. $(MAKE) build EXTRA_FLAGS="$(EXTRA_FLAGS) -DOPK_FACTORY_RESET=1"
  38. ## Reformat all C/C++ sources in place using the Linux kernel style.
  39. format:
  40. $(CLANG_FORMAT) -i $(FORMAT_FILES)
  41. ## Verify all C/C++ sources are formatted; exit non-zero if any differ.
  42. ## Used by CI to reject unformatted code.
  43. format-check:
  44. $(CLANG_FORMAT) --dry-run --Werror $(FORMAT_FILES)
  45. ## Everything CI gates on.
  46. check: format-check