From a181c0dbcd6a8d8bc2ed8bb5d340a2d4e9e5a80a Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 17 Feb 2020 09:30:42 +0100 Subject: [PATCH] usb: Use separate Makefile for configuration and checks --- Makefile.include | 37 +++---------------------------------- makefiles/usb-codes.inc.mk | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 34 deletions(-) create mode 100644 makefiles/usb-codes.inc.mk diff --git a/Makefile.include b/Makefile.include index 884e722cd2..e04e79849c 100644 --- a/Makefile.include +++ b/Makefile.include @@ -662,40 +662,6 @@ endif @$(COLOR_ECHO) '$(COLOR_GREEN)Building application "$(APPLICATION)" for "$(BOARD)" with MCU "$(MCU)".$(COLOR_RESET)' @$(COLOR_ECHO) -# Set USB VID/PID via CFLAGS if not being set via Kconfig -ifndef CONFIG_USB_VID - ifdef USB_VID - CFLAGS += -DCONFIG_USB_VID=0x$(USB_VID) - endif -else - USB_VID = $(patsubst 0x%,%,$(CONFIG_USB_VID)) -endif - -ifndef CONFIG_USB_PID - ifdef USB_PID - CFLAGS += -DCONFIG_USB_PID=0x$(USB_PID) - endif -else - USB_PID = $(patsubst 0x%,%,$(CONFIG_USB_PID)) -endif - -# Exported for the benefit of Kconfig -export USB_VID_TESTING = 1209 -export USB_PID_TESTING = 7D01 -usb_id_check: - @if grep --quiet --ignore-case "^$(USB_VID) $(USB_PID)$$" $(RIOTBASE)/dist/usb_id_testing; then \ - $(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2 ; \ - $(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2 ; \ - fi - @if [ "$(USB_VID) $(subst D,d,$(USB_PID))" = "1209 7d00" ]; then \ - $(COLOR_ECHO) "$(COLOR_RED)RIOT standard peripherals code (1209/7D00) cannot be set explicitly.$(COLOR_RESET)" 1>&2 ; \ - $(COLOR_ECHO) "$(COLOR_RED)Unset USB_VID / USB_PID for the code to be picked automatically, or set$(COLOR_RESET)" 1>&2 ; \ - $(COLOR_ECHO) "$(COLOR_RED)them to \$${USB_VID_TESTING} / \$${USB_PID_TESTING} during development.$(COLOR_RESET)" 1>&2 ; \ - exit 1; \ - fi -.PHONY: usb_id_check -all: | usb_id_check - # The `clean` needs to be serialized before everything else. all $(BASELIBS) $(BUILDDEPS) ..in-docker-container: | $(CLEAN) @@ -839,6 +805,9 @@ include $(RIOTMAKE)/vars.inc.mk # Include build targets for selected tools include $(RIOTMAKE)/tools/targets.inc.mk +# Checks and defaults for USB Vendor and Product ID +include $(RIOTMAKE)/usb-codes.inc.mk + # Warn if the selected board and drivers don't provide all needed features: ifneq (, $(filter all flash, $(if $(MAKECMDGOALS), $(MAKECMDGOALS), all))) EXPECT_ERRORS := diff --git a/makefiles/usb-codes.inc.mk b/makefiles/usb-codes.inc.mk new file mode 100644 index 0000000000..3161b809f7 --- /dev/null +++ b/makefiles/usb-codes.inc.mk @@ -0,0 +1,33 @@ +# Set USB VID/PID via CFLAGS if not being set via Kconfig +ifndef CONFIG_USB_VID + ifdef USB_VID + CFLAGS += -DCONFIG_USB_VID=0x$(USB_VID) + endif +else + USB_VID = $(patsubst 0x%,%,$(CONFIG_USB_VID)) +endif + +ifndef CONFIG_USB_PID + ifdef USB_PID + CFLAGS += -DCONFIG_USB_PID=0x$(USB_PID) + endif +else + USB_PID = $(patsubst 0x%,%,$(CONFIG_USB_PID)) +endif + +# Exported for the benefit of Kconfig +export USB_VID_TESTING = 1209 +export USB_PID_TESTING = 7D01 +usb_id_check: + @if grep --quiet --ignore-case "^$(USB_VID) $(USB_PID)$$" $(RIOTBASE)/dist/usb_id_testing; then \ + $(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2 ; \ + $(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2 ; \ + fi + @if [ "$(USB_VID) $(subst D,d,$(USB_PID))" = "1209 7d00" ]; then \ + $(COLOR_ECHO) "$(COLOR_RED)RIOT standard peripherals code (1209/7D00) cannot be set explicitly.$(COLOR_RESET)" 1>&2 ; \ + $(COLOR_ECHO) "$(COLOR_RED)Unset USB_VID / USB_PID for the code to be picked automatically, or set$(COLOR_RESET)" 1>&2 ; \ + $(COLOR_ECHO) "$(COLOR_RED)them to \$${USB_VID_TESTING} / \$${USB_PID_TESTING} during development.$(COLOR_RESET)" 1>&2 ; \ + exit 1; \ + fi +.PHONY: usb_id_check +all: | usb_id_check