From c44d52f33e4ec626c7f6293323300baaeb55e856 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 20 Feb 2020 14:27:30 +1100 Subject: [PATCH] extmod/modbluetooth_nimble: Move nimble specific code, factor nimble.mk. Move extmod/modbluetooth_nimble.* to extmod/nimble. And move common Makefile lines to extmod/nimble/nimble.mk (which was previously only used by stm32). This allows (upcoming) btstack to follow a similar structure. Work done in collaboration with Jim Mussared aka @jimmo. --- extmod/{ => nimble}/modbluetooth_nimble.c | 4 ++-- extmod/{ => nimble}/modbluetooth_nimble.h | 6 +++--- extmod/nimble/nimble.mk | 19 +++++++++++++++---- ports/esp32/Makefile | 14 +++++++------- ports/stm32/Makefile | 6 +++++- ports/stm32/nimble.c | 2 +- 6 files changed, 33 insertions(+), 18 deletions(-) rename extmod/{ => nimble}/modbluetooth_nimble.c (99%) rename extmod/{ => nimble}/modbluetooth_nimble.h (91%) diff --git a/extmod/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c similarity index 99% rename from extmod/modbluetooth_nimble.c rename to extmod/nimble/modbluetooth_nimble.c index aa1b032f27..f7602c35fd 100644 --- a/extmod/modbluetooth_nimble.c +++ b/extmod/nimble/modbluetooth_nimble.c @@ -31,8 +31,8 @@ #if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_NIMBLE -#include "modbluetooth_nimble.h" -#include "modbluetooth.h" +#include "extmod/nimble/modbluetooth_nimble.h" +#include "extmod/modbluetooth.h" #include "host/ble_hs.h" #include "host/util/util.h" diff --git a/extmod/modbluetooth_nimble.h b/extmod/nimble/modbluetooth_nimble.h similarity index 91% rename from extmod/modbluetooth_nimble.h rename to extmod/nimble/modbluetooth_nimble.h index e2474a6ee5..c70c3bc90a 100644 --- a/extmod/modbluetooth_nimble.h +++ b/extmod/nimble/modbluetooth_nimble.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_EXTMOD_MODBLUETOOTH_NIMBLE_H -#define MICROPY_INCLUDED_EXTMOD_MODBLUETOOTH_NIMBLE_H +#ifndef MICROPY_INCLUDED_EXTMOD_NIMBLE_MODBLUETOOTH_NIMBLE_H +#define MICROPY_INCLUDED_EXTMOD_NIMBLE_MODBLUETOOTH_NIMBLE_H #define MP_BLUETOOTH_NIMBLE_MAX_SERVICES (8) @@ -51,4 +51,4 @@ void mp_bluetooth_nimble_port_postinit(void); void mp_bluetooth_nimble_port_deinit(void); void mp_bluetooth_nimble_port_start(void); -#endif // MICROPY_INCLUDED_EXTMOD_MODBLUETOOTH_NIMBLE_H +#endif // MICROPY_INCLUDED_EXTMOD_NIMBLE_MODBLUETOOTH_NIMBLE_H diff --git a/extmod/nimble/nimble.mk b/extmod/nimble/nimble.mk index e554e9ff06..4d2c6637a4 100644 --- a/extmod/nimble/nimble.mk +++ b/extmod/nimble/nimble.mk @@ -1,10 +1,21 @@ -# Makefile directives for Apache mynewt nimble BLE component +# Makefile directives for Apache Mynewt NimBLE component ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1) -NIMBLE_LIB_DIR = lib/mynewt-nimble +EXTMOD_SRC_C += extmod/nimble/modbluetooth_nimble.c + +CFLAGS_MOD += -DMICROPY_BLUETOOTH_NIMBLE=1 + NIMBLE_EXTMOD_DIR = extmod/nimble +# Use NimBLE from the submodule in lib/mynewt-nimble by default, +# allowing a port to use their own system version (e.g. ESP32). +MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY ?= 0 + +ifeq ($(MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY),0) + +NIMBLE_LIB_DIR = lib/mynewt-nimble + SRC_LIB += $(addprefix $(NIMBLE_LIB_DIR)/, \ $(addprefix ext/tinycrypt/src/, \ aes_encrypt.c \ @@ -76,8 +87,6 @@ EXTMOD_SRC_C += $(addprefix $(NIMBLE_EXTMOD_DIR)/, \ nimble/hci_uart.c \ ) -CFLAGS_MOD += -DMICROPY_BLUETOOTH_NIMBLE=1 - INC += -I$(TOP)/$(NIMBLE_EXTMOD_DIR) INC += -I$(TOP)/$(NIMBLE_LIB_DIR) INC += -I$(TOP)/$(NIMBLE_LIB_DIR)/ext/tinycrypt/include @@ -93,3 +102,5 @@ INC += -I$(TOP)/$(NIMBLE_LIB_DIR)/porting/nimble/include $(BUILD)/$(NIMBLE_LIB_DIR)/%.o: CFLAGS += -Wno-maybe-uninitialized -Wno-pointer-arith -Wno-unused-but-set-variable -Wno-format endif + +endif diff --git a/ports/esp32/Makefile b/ports/esp32/Makefile index fe4787b7ae..7033a3dd26 100644 --- a/ports/esp32/Makefile +++ b/ports/esp32/Makefile @@ -118,7 +118,12 @@ endif MICROPY_PY_BLUETOOTH ?= 1 ifeq ($(MICROPY_PY_BLUETOOTH),1) SDKCONFIG += boards/sdkconfig.ble -MICROPY_BLUETOOTH_NIMBLE = 1 + +# Use NimBLE on ESP32. +MICROPY_BLUETOOTH_NIMBLE ?= 1 +# Use Nimble bindings, but ESP32 IDF provides the Nimble library. +MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY = 1 +include $(TOP)/extmod/nimble/nimble.mk endif # include sdkconfig to get needed configuration values @@ -244,10 +249,6 @@ INC_NEWLIB += -I$(ESPCOMP)/newlib/include ifeq ($(MICROPY_PY_BLUETOOTH),1) CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH=1 CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE=1 - -ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1) -CFLAGS_MOD += -DMICROPY_BLUETOOTH_NIMBLE=1 -endif endif # these flags are common to C and C++ compilation @@ -354,9 +355,8 @@ SRC_C = \ $(wildcard $(BOARD_DIR)/*.c) \ $(SRC_MOD) -EXTMOD_SRC_C = $(addprefix extmod/,\ +EXTMOD_SRC_C += $(addprefix extmod/,\ modonewire.c \ - modbluetooth_nimble.c \ ) LIB_SRC_C = $(addprefix lib/,\ diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 11db9dfbab..235b251644 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -458,14 +458,18 @@ CFLAGS_MOD += -DMBEDTLS_CONFIG_FILE='"mbedtls/mbedtls_config.h"' SRC_MOD += mbedtls/mbedtls_port.c endif +ifeq ($(MICROPY_PY_BLUETOOTH),1) + ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1) include $(TOP)/extmod/nimble/nimble.mk SRC_C += nimble.c SRC_C += nimble_hci_uart.c -EXTMOD_SRC_C += extmod/modbluetooth_nimble.c +endif + ifeq ($(MICROPY_PY_NETWORK_CYW43),1) DRIVERS_SRC_C += drivers/cyw43/cywbt.c endif + endif OBJ = diff --git a/ports/stm32/nimble.c b/ports/stm32/nimble.c index b8fdc8f886..b21b2bede7 100644 --- a/ports/stm32/nimble.c +++ b/ports/stm32/nimble.c @@ -36,7 +36,7 @@ #include "transport/uart/ble_hci_uart.h" #include "host/ble_hs.h" -#include "extmod/modbluetooth_nimble.h" +#include "extmod/nimble/modbluetooth_nimble.h" extern void nimble_uart_process(void); extern void os_eventq_run_all(void);