Skip to content

Commit 4e21ddb

Browse files
jaguilarlaurensvalk
andcommitted
pbio/drv/bluetooth_btstack: Add POSIX variant for virtualhub.
- Changes pbdrv_bluetooth_btstack_set_chipset to convey all necessary information to set the correct chipset both from the read local version information command as well as events from the USB subsystem. - Adds a POSIX implementation for pbdrv_bluetooth_btstack_set_chipset. This supports TP-LINK UB500. - Sets up the virtualhub platform to use this chipset. - Adjusts the runloop to check for readability and writability of file descriptors, which is required for the libusb transport. Co-authored-by: Laurens Valk <laurens@pybricks.com>
1 parent a17c1d2 commit 4e21ddb

10 files changed

Lines changed: 437 additions & 3 deletions

File tree

.vscode/c_cpp_properties.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@
386386
"${workspaceFolder}/bricks/virtualhub",
387387
"${workspaceFolder}/bricks/virtualhub/build",
388388
"${workspaceFolder}/bricks/virtualhub/build-debug",
389+
"${workspaceFolder}/lib/btstack/chipset/realtek",
390+
"${workspaceFolder}/lib/btstack/platform/libusb",
391+
"${workspaceFolder}/lib/btstack/platform/posix",
392+
"${workspaceFolder}/lib/btstack/src",
389393
"${workspaceFolder}/lib/lego",
390394
"${workspaceFolder}/lib/lwrb/src/include",
391395
"${workspaceFolder}/lib/pbio",
@@ -394,7 +398,8 @@
394398
"${workspaceFolder}/micropython",
395399
"${workspaceFolder}",
396400
"${workspaceFolder}/lib/umm_malloc/src",
397-
"/usr/include/python3.10"
401+
"/usr/include/python3.10",
402+
"/usr/include/libusb-1.0"
398403
],
399404
"defines": [
400405
"MICROPY_MODULE_FROZEN_MPY",

.vscode/launch.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
"name": "PBIO_TEST_CONNECT_SOCKET",
7676
"value": "true"
7777
},
78+
{
79+
"name": "UB500_INDEX",
80+
"value": "0"
81+
}
7882
],
7983
"externalConsole": false,
8084
"MIMode": "gdb",

bricks/_common/common.mk

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ endif
124124
ifneq ($(strip $(PB_LIB_BTSTACK)),)
125125
INC += -I$(PBTOP)/lib/btstack/chipset/cc256x
126126
INC += -I$(PBTOP)/lib/btstack/src
127+
ifeq ($(PBIO_PLATFORM),virtual_hub)
128+
INC += -I$(PBTOP)/lib/btstack/platform/posix
129+
INC += -I$(PBTOP)/lib/btstack/platform/embedded
130+
INC += -I$(PBTOP)/lib/btstack/3rd-party/tinydir
131+
INC += -I$(PBTOP)/lib/btstack/3rd-party/rijndael
132+
INC += -I$(PBTOP)/lib/btstack/3rd-party/micro-ecc
133+
INC += -I$(PBTOP)/lib/btstack/chipset/bcm
134+
INC += -I$(PBTOP)/lib/btstack/chipset/intel
135+
INC += -I$(PBTOP)/lib/btstack/chipset/realtek
136+
INC += -I$(PBTOP)/lib/btstack/chipset/zephyr
137+
INC += $(shell pkg-config libusb-1.0 --cflags)
138+
endif
127139
endif
128140
ifeq ($(PB_LIB_LSM6DS3TR_C),1)
129141
INC += -I$(PBTOP)/lib/lsm6ds3tr_c_STdC/driver
@@ -162,6 +174,9 @@ else ifeq ($(UNAME_S),Darwin)
162174
LDFLAGS += -Wl,-map,$@.map -Wl,-dead_strip
163175
endif
164176
LIBS = -lm
177+
ifeq ($(PB_LIB_BTSTACK),lowenergy)
178+
LIBS += $(shell pkg-config libusb-1.0 --libs)
179+
endif
165180
else # end native, begin embedded
166181
CROSS_COMPILE ?= arm-none-eabi-
167182
ifeq ($(PB_MCU_FAMILY),STM32)
@@ -395,6 +410,25 @@ BTSTACK_SRC_C += $(addprefix lib/btstack/chipset/cc256x/,\
395410
btstack_chipset_cc256x.c \
396411
)
397412

413+
# libusb-specific BTStack sources for virtual_hub
414+
ifeq ($(PBIO_PLATFORM),virtual_hub)
415+
BTSTACK_SRC_C += $(addprefix lib/btstack/,\
416+
platform/libusb/hci_transport_h2_libusb.c \
417+
platform/posix/hci_dump_posix_stdout.c \
418+
platform/posix/btstack_tlv_posix.c \
419+
src/classic/btstack_link_key_db_tlv.c \
420+
src/ble/le_device_db_tlv.c \
421+
chipset/zephyr/btstack_chipset_zephyr.c \
422+
chipset/realtek/btstack_chipset_realtek.c \
423+
chipset/bcm/btstack_chipset_bcm.c \
424+
chipset/intel/btstack_chipset_intel_firmware.c \
425+
3rd-party/rijndael/rijndael.c \
426+
3rd-party/micro-ecc/uECC.c \
427+
)
428+
# Suppress unused variable warning for this file
429+
$(BUILD)/lib/btstack/platform/libusb/hci_transport_h2_libusb.o: CFLAGS += -Wno-unused-variable
430+
endif
431+
398432
# STM32 HAL
399433

400434
COPT += -DUSE_FULL_LL_DRIVER
@@ -529,11 +563,13 @@ endif
529563

530564
ifeq ($(PB_LIB_BTSTACK),classic)
531565
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_SRC_C:.c=.o))
566+
$(BUILD)/lib/btstack/%.o: CFLAGS += -Wno-error
532567
endif
533568

534569
ifeq ($(PB_LIB_BTSTACK),lowenergy)
535570
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_SRC_C:.c=.o))
536571
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_BLE_SRC_C:.c=.o))
572+
$(BUILD)/lib/btstack/%.o: CFLAGS += -Wno-error
537573
endif
538574

539575
ifeq ($(PB_LIB_STM32_HAL),1)

bricks/_common/sources.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
115115
drv/block_device/block_device_test.c \
116116
drv/block_device/block_device_w25qxx_stm32.c \
117117
drv/bluetooth/bluetooth.c \
118-
drv/bluetooth/bluetooth_btstack_stm32_hal.c \
119118
drv/bluetooth/bluetooth_btstack.c \
120119
drv/bluetooth/bluetooth_btstack_ev3.c \
120+
drv/bluetooth/bluetooth_btstack_posix.c \
121+
drv/bluetooth/bluetooth_btstack_stm32_hal.c \
121122
drv/bluetooth/bluetooth_simulation.c \
122123
drv/bluetooth/bluetooth_stm32_bluenrg.c \
123124
drv/bluetooth/bluetooth_stm32_cc2640.c \

bricks/virtualhub/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ PB_MCU_FAMILY = native
66
PB_FROZEN_MODULES = 1
77
MICROPY_ROM_TEXT_COMPRESSION = 1
88
PB_LIB_UMM_MALLOC = 1
9+
PB_LIB_BTSTACK = lowenergy
910

1011
include ../_common/common.mk

0 commit comments

Comments
 (0)