Skip to content

Commit 409a60e

Browse files
andrewleechpi-anl
authored andcommitted
windows/bluetooth: Add support for nimble BLE to windows port.
1 parent f498a16 commit 409a60e

File tree

4 files changed

+460
-1
lines changed

4 files changed

+460
-1
lines changed

extmod/nimble/syscfg/syscfg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ void *nimble_realloc(void *ptr, size_t size);
1414
#define free(ptr) nimble_free(ptr)
1515
#define realloc(ptr, size) nimble_realloc(ptr, size)
1616

17+
#ifndef __MINGW32__
1718
int nimble_sprintf(char *str, const char *fmt, ...);
1819
#define sprintf(str, fmt, ...) nimble_sprintf(str, fmt, __VA_ARGS__)
20+
#endif
1921

2022
#define MYNEWT_VAL(x) MYNEWT_VAL_ ## x
2123

ports/windows/Makefile

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ SRC_C = \
6161
ports/unix/main.c \
6262
ports/unix/input.c \
6363
ports/unix/gccollect.c \
64+
ports/unix/mpbtstackport_common.c \
65+
ports/unix/mpbtstackport_h4.c \
66+
ports/unix/mpbtstackport_usb.c \
67+
ports/unix/mpnimbleport.c \
68+
mpbthciport.c \
6469
windows_mphal.c \
6570
realpath.c \
6671
init.c \
@@ -74,6 +79,7 @@ SHARED_SRC_C += $(addprefix shared/,\
7479
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
7580
OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o))
7681
OBJ += $(addprefix $(BUILD)/, $(SHARED_SRC_C:.c=.o))
82+
OBJ += $(addprefix $(BUILD)/, $(EXTMOD_SRC_C:.c=.o))
7783
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
7884

7985
ifeq ($(MICROPY_USE_READLINE),1)
@@ -84,7 +90,7 @@ endif
8490
LIB += -lws2_32
8591

8692
# List of sources for qstr extraction
87-
SRC_QSTR += $(SRC_C) $(SRC_CXX) $(SHARED_SRC_C)
93+
SRC_QSTR += $(SRC_C) $(SRC_CXX) $(SHARED_SRC_C) $(EXTMOD_SRC_C)
8894

8995
ifneq ($(FROZEN_MANIFEST),)
9096
CFLAGS += -DMPZ_DIG_SIZE=16
@@ -99,8 +105,63 @@ ifeq ($(shell $(CC) -dumpmachine),i686-w64-mingw32)
99105
CFLAGS += -msse -mfpmath=sse -march=pentium4
100106
endif
101107

108+
# If the variant enables it, enable modbluetooth.
109+
ifeq ($(MICROPY_PY_BLUETOOTH),1)
110+
111+
# Only one stack can be enabled.
112+
ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1)
113+
ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1)
114+
$(error Cannot enable both NimBLE and BTstack at the same time)
115+
endif
116+
endif
117+
118+
# Default to btstack, but a variant (or make command line) can set NimBLE
119+
# explicitly (which is always via H4 UART).
120+
ifneq ($(MICROPY_BLUETOOTH_NIMBLE),1)
121+
ifneq ($(MICROPY_BLUETOOTH_BTSTACK),1)
122+
MICROPY_BLUETOOTH_BTSTACK ?= 1
123+
endif
124+
endif
125+
126+
CFLAGS += -mno-ms-bitfields
127+
CFLAGS += -DMICROPY_PY_BLUETOOTH=1
128+
CFLAGS += -DMICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE=1
129+
130+
ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1)
131+
132+
# Figure out which BTstack transport to use.
133+
ifeq ($(MICROPY_BLUETOOTH_BTSTACK_H4),1)
134+
ifeq ($(MICROPY_BLUETOOTH_BTSTACK_USB),1)
135+
$(error Cannot enable BTstack support for USB and H4 UART at the same time)
136+
endif
137+
else
138+
ifeq ($(HAVE_LIBUSB),1)
139+
# Default to btstack-over-usb.
140+
MICROPY_BLUETOOTH_BTSTACK_USB ?= 1
141+
else
142+
# Fallback to HCI controller via a H4 UART (e.g. Zephyr on nRF) over a /dev/tty serial port.
143+
MICROPY_BLUETOOTH_BTSTACK_H4 ?= 1
144+
endif
145+
endif
146+
147+
# BTstack is enabled.
148+
GIT_SUBMODULES += lib/btstack
149+
include $(TOP)/extmod/btstack/btstack.mk
150+
SRC_BTSTACK += lib/btstack/platform/embedded/btstack_run_loop_embedded.c
151+
152+
else
153+
154+
# NimBLE is enabled.
155+
GIT_SUBMODULES += lib/mynewt-nimble
156+
CFLAGS += -DMICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS=1
157+
include $(TOP)/extmod/nimble/nimble.mk
158+
159+
endif
160+
endif
161+
102162
CXXFLAGS += $(filter-out -std=gnu99,$(CFLAGS))
103163

164+
104165
include $(TOP)/py/mkrules.mk
105166

106167
.PHONY: test test_full

0 commit comments

Comments
 (0)