Skip to content

Commit bdbeab5

Browse files
andrewleechpi-anl
authored andcommitted
windows/bluetooth: Add support for nimble BLE to windows port.
1 parent 27b7bf3 commit bdbeab5

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
@@ -65,6 +65,11 @@ SRC_C = \
6565
ports/unix/main.c \
6666
ports/unix/input.c \
6767
ports/unix/gccollect.c \
68+
ports/unix/mpbtstackport_common.c \
69+
ports/unix/mpbtstackport_h4.c \
70+
ports/unix/mpbtstackport_usb.c \
71+
ports/unix/mpnimbleport.c \
72+
mpbthciport.c \
6873
windows_mphal.c \
6974
realpath.c \
7075
init.c \
@@ -78,6 +83,7 @@ SHARED_SRC_C += $(addprefix shared/,\
7883
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
7984
OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o))
8085
OBJ += $(addprefix $(BUILD)/, $(SHARED_SRC_C:.c=.o))
86+
OBJ += $(addprefix $(BUILD)/, $(EXTMOD_SRC_C:.c=.o))
8187
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
8288

8389
ifeq ($(MICROPY_USE_READLINE),1)
@@ -88,7 +94,7 @@ endif
8894
LIB += -lws2_32
8995

9096
# List of sources for qstr extraction
91-
SRC_QSTR += $(SRC_C) $(SRC_CXX) $(SHARED_SRC_C)
97+
SRC_QSTR += $(SRC_C) $(SRC_CXX) $(SHARED_SRC_C) $(EXTMOD_SRC_C)
9298

9399
ifneq ($(FROZEN_MANIFEST),)
94100
CFLAGS += -DMPZ_DIG_SIZE=16
@@ -103,8 +109,63 @@ ifeq ($(shell $(CC) -dumpmachine),i686-w64-mingw32)
103109
CFLAGS += -msse -mfpmath=sse -march=pentium4
104110
endif
105111

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

168+
108169
include $(TOP)/py/mkrules.mk
109170

110171
.PHONY: test test_full

0 commit comments

Comments
 (0)