aboutsummaryrefslogtreecommitdiff
path: root/ports/unix/Makefile
diff options
context:
space:
mode:
authorJim Mussared2020-08-14 15:46:53 +1000
committerDamien George2020-09-08 12:53:24 +1000
commit1b1b22905e1aa7676c51078f75b1bd73d8383a4a (patch)
treec813cb7f867e55f6ae3b7e53be1de0d4af9376fd /ports/unix/Makefile
parentfeed69aa5c4e9fda037497a1b63c05a27b164920 (diff)
unix: Implement BLE H4 HCI UART for btstack/nimble.
This commit adds support for using Bluetooth on the unix port via a H4 serial interface (distinct from a USB dongle), with both BTstack and NimBLE Bluetooth stacks. Note that MICROPY_PY_BLUETOOTH is now disabled for the coverage variant. Prior to this commit Bluetooth was anyway not being built on Travis because libusb was not detected. But now that bluetooth works in H4 mode it will be built, and will lead to a large decrease in coverage because Bluetooth tests cannot be run on Travis.
Diffstat (limited to 'ports/unix/Makefile')
-rw-r--r--ports/unix/Makefile45
1 files changed, 40 insertions, 5 deletions
diff --git a/ports/unix/Makefile b/ports/unix/Makefile
index 090b58d8e..ff5f35502 100644
--- a/ports/unix/Makefile
+++ b/ports/unix/Makefile
@@ -134,24 +134,57 @@ CFLAGS_MOD += -DMICROPY_PY_THREAD=1 -DMICROPY_PY_THREAD_GIL=0
LDFLAGS_MOD += $(LIBPTHREAD)
endif
-# If the variant enables it and we have libusb, enable BTStack support for USB adaptors.
+# If the variant enables it, enable modbluetooth.
ifeq ($(MICROPY_PY_BLUETOOTH),1)
HAVE_LIBUSB := $(shell (which pkg-config > /dev/null && pkg-config --exists libusb-1.0) 2>/dev/null && echo '1')
-ifeq ($(HAVE_LIBUSB),1)
+
+# Only one stack can be enabled.
+ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1)
+ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1)
+$(error Cannot enable both NimBLE and BTstack at the same time)
+endif
+endif
+
+# Default to btstack, but a variant (or make command line) can set NimBLE
+# explicitly (which is always via H4 UART).
+ifneq ($(MICROPY_BLUETOOTH_NIMBLE),1)
+ifneq ($(MICROPY_BLUETOOTH_BTSTACK),1)
+MICROPY_BLUETOOTH_BTSTACK ?= 1
+endif
+endif
CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH=1
CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE=1
# Runs in a thread, cannot make calls into the VM.
CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_GATTS_ON_READ_CALLBACK=0
-MICROPY_BLUETOOTH_BTSTACK ?= 1
+ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1)
+
+# Figure out which BTstack transport to use.
+ifeq ($(MICROPY_BLUETOOTH_BTSTACK_H4),1)
+ifeq ($(MICROPY_BLUETOOTH_BTSTACK_USB),1)
+$(error Cannot enable BTstack support for USB and H4 UART at the same time)
+endif
+else
+ifeq ($(HAVE_LIBUSB),1)
+# Default to btstack-over-usb.
MICROPY_BLUETOOTH_BTSTACK_USB ?= 1
+else
+# Fallback to HCI controller via a H4 UART (e.g. Zephyr on nRF) over a /dev/tty serial port.
+MICROPY_BLUETOOTH_BTSTACK_H4 ?= 1
+endif
+endif
-ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1)
+# BTstack is enabled.
GIT_SUBMODULES += lib/btstack
include $(TOP)/extmod/btstack/btstack.mk
-endif
+
+else
+
+# NimBLE is enabled.
+GIT_SUBMODULES += lib/mynewt-nimble
+include $(TOP)/extmod/nimble/nimble.mk
endif
@@ -201,7 +234,9 @@ SRC_C = \
alloc.c \
coverage.c \
fatfs_port.c \
+ mpbthciport.c \
mpbtstackport_common.c \
+ mpbtstackport_h4.c \
mpbtstackport_usb.c \
mpnimbleport.c \
$(SRC_MOD) \