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.
This commit is contained in:
Damien George 2020-02-20 14:27:30 +11:00
parent 44aa5b2200
commit c44d52f33e
6 changed files with 33 additions and 18 deletions

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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/,\

View File

@ -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 =

View File

@ -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);