diff --git a/Makefile.include b/Makefile.include index 7b0295605e89..3e73ed8f82aa 100644 --- a/Makefile.include +++ b/Makefile.include @@ -172,6 +172,8 @@ CLEAN = $(filter clean, $(MAKECMDGOALS)) include $(RIOTMAKE)/utils/variables.mk include $(RIOTMAKE)/utils/strings.mk +# include nimble makefile tools +include $(RIOTMAKE)/pkg/nimble.adv.mk # UNAME is always needed so use simple variable expansion so only evaluated once UNAME := $(shell uname -m -s) diff --git a/makefiles/pkg/nimble.adv.mk b/makefiles/pkg/nimble.adv.mk new file mode 100644 index 000000000000..23686383406b --- /dev/null +++ b/makefiles/pkg/nimble.adv.mk @@ -0,0 +1,15 @@ +# Adds an external Advertisement Instance +# Parameter 1: The value for the advertisement instance without the CONFIG_ prefix +# Result: +# - Increases BLE_MULTI_ADV_INSTANCES count by 1, note that the actual amount +# of advertisement instances is MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES + 1, which +# is why BLE_MULTI_ADV_INSTANCES starts at -1 +# - Sets the adv instance for CONFIG_$1 index to $(BLE_MULTI_ADV_INSTANCES) +BLE_MULTI_ADV_INSTANCES ?= -1 +define _add_ext_adv_instance + # Increase the count in one + BLE_MULTI_ADV_INSTANCES := $$(shell echo $$$$(($(BLE_MULTI_ADV_INSTANCES) + 1))) + # Export the definition in CFLAGS + $(1) := $$(BLE_MULTI_ADV_INSTANCES) + CFLAGS += -DCONFIG_$(1)=$$($(1)) +endef diff --git a/pkg/nimble/Makefile.include b/pkg/nimble/Makefile.include index 8d9a0e22246f..75da027ad935 100644 --- a/pkg/nimble/Makefile.include +++ b/pkg/nimble/Makefile.include @@ -94,7 +94,6 @@ ifneq (,$(filter nimble_autoconn,$(USEMODULE))) INCLUDES += -I$(RIOTPKG)/nimble/autoconn/include endif - ifneq (,$(filter nimble_adv_ext,$(USEMODULE))) CFLAGS += -DMYNEWT_VAL_BLE_EXT_ADV=1 CFLAGS += -DMYNEWT_VAL_BLE_LL_EXT_ADV_AUX_PTR_CNT=2 @@ -102,14 +101,16 @@ ifneq (,$(filter nimble_adv_ext,$(USEMODULE))) ifneq (,$(filter nimble_controller,$(USEMODULE))) CFLAGS += -DMYNEWT_VAL_BLE_LL_CFG_FEAT_LL_EXT_ADV=1 endif - NIMBLE_ADVERTISING_INSTANCES ?= 0 ifneq (,$(filter nimble_netif,$(USEMODULE))) - ifneq (,$(filter nimble_autoadv,$(USEMODULE))) - NIMBLE_ADVERTISING_INSTANCES = 1 - CFLAGS += -DCONFIG_NIMBLE_AUTO_ADV_INST=1 - endif + $(eval $(call _add_ext_adv_instance,NIMBLE_NETIF_ADV_INSTANCE)) + endif + ifneq (,$(filter nimble_autoadv,$(USEMODULE))) + $(eval $(call _add_ext_adv_instance,NIMBLE_AUTOADV_INSTANCE)) + endif + # check that an advertisement instances was configured + ifneq (-1,$(BLE_MULTI_ADV_INSTANCES)) + CFLAGS += -DMYNEWT_VAL_BLE_MULTI_ADV_INSTANCES=$(BLE_MULTI_ADV_INSTANCES) endif - CFLAGS += -DMYNEWT_VAL_BLE_MULTI_ADV_INSTANCES=$(NIMBLE_ADVERTISING_INSTANCES) endif ifneq (,$(filter nimble_netif,$(USEMODULE)))