Skip to content

Commit 411503b

Browse files
committed
drv/bluetooth/btstack: update to develop branch
This pulls in some changes so that we can detect when notifications of the Nordic UART service are disabled. This is needed to work around a Chromium Linux bug where we have to disable and enable notifications more than once while the device is connected. There were also some changes in logging that had to be fixed.
1 parent b933bf2 commit 411503b

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed

.editorconfig

+7
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ tab_width = 4
1414
[{Makefile,*.mk}]
1515
indent_style = tab
1616
tab_width = 8
17+
18+
[/lib/btstack/**]
19+
end_of_line = unset
20+
insert_final_newline = unset
21+
trim_trailing_whitespace = unset
22+
indent_style = unset
23+
indent_size = unset

.vscode/c_cpp_properties.json

+1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@
296296
"includePath": [
297297
"${workspaceFolder}/micropython/lib/tinytest",
298298
"${workspaceFolder}/lib/btstack/chipset/cc256x",
299+
"${workspaceFolder}/lib/btstack/platform/posix",
299300
"${workspaceFolder}/lib/btstack/src",
300301
"${workspaceFolder}/lib/contiki-core",
301302
"${workspaceFolder}/lib/lego",

bricks/stm32/stm32.mk

-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ BTSTACK_SRC_C = $(addprefix lib/btstack/src/,\
300300

301301
BTSTACK_SRC_C += $(addprefix lib/btstack/src/ble/,\
302302
gatt-service/nordic_spp_service_server.c \
303-
ancs_client.c \
304303
att_db_util.c \
305304
att_db.c \
306305
att_dispatch.c \

lib/btstack

Submodule btstack updated 1180 files

lib/pbio/drv/bluetooth/bluetooth_btstack.c

+27-9
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,32 @@ static void nordic_can_send(void *context) {
7777
tx->done(tx);
7878
}
7979

80-
static void nordic_data_received(hci_con_handle_t tx_con_handle, const uint8_t *data, uint16_t size) {
81-
// TODO: need upstream change to be able to detect when notifications are disabled
82-
if (size == 0 && uart_con_handle == HCI_CON_HANDLE_INVALID) {
83-
uart_con_handle = tx_con_handle;
84-
} else {
85-
if (handle_rx) {
86-
handle_rx(PBDRV_BLUETOOTH_CONNECTION_UART, data, size);
87-
}
80+
static void nordic_spp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) {
81+
switch (packet_type) {
82+
case HCI_EVENT_PACKET:
83+
if (hci_event_packet_get_type(packet) != HCI_EVENT_GATTSERVICE_META) {
84+
break;
85+
}
86+
87+
switch (hci_event_gattservice_meta_get_subevent_code(packet)) {
88+
case GATTSERVICE_SUBEVENT_SPP_SERVICE_CONNECTED:
89+
uart_con_handle = gattservice_subevent_spp_service_connected_get_con_handle(packet);
90+
break;
91+
case GATTSERVICE_SUBEVENT_SPP_SERVICE_DISCONNECTED:
92+
uart_con_handle = HCI_CON_HANDLE_INVALID;
93+
break;
94+
default:
95+
break;
96+
}
97+
98+
break;
99+
case RFCOMM_DATA_PACKET:
100+
if (handle_rx) {
101+
handle_rx(PBDRV_BLUETOOTH_CONNECTION_UART, packet, size);
102+
}
103+
break;
104+
default:
105+
break;
88106
}
89107
}
90108

@@ -139,7 +157,7 @@ void pbdrv_bluetooth_init(void) {
139157
att_server_init(profile_data, NULL, NULL);
140158

141159
pybricks_service_server_init(pybricks_data_received, pybricks_configured);
142-
nordic_spp_service_server_init(nordic_data_received);
160+
nordic_spp_service_server_init(nordic_spp_packet_handler);
143161
}
144162

145163
void pbdrv_bluetooth_power_on(bool on) {

lib/pbio/test/Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ LWRB_SRC = $(shell find $(LWRB_DIR)/lwrb -name "*.c")
6868

6969
# pbio depedency
7070
BTSTACK_DIR = ../../btstack
71-
BTSTACK_INC = -I$(BTSTACK_DIR)/src -I$(BTSTACK_DIR)/chipset/cc256x
71+
BTSTACK_INC = -I$(BTSTACK_DIR)/src -I$(BTSTACK_DIR)/chipset/cc256x -I$(BTSTACK_DIR)/platform/posix
7272
BTSTACK_SRC = $(addprefix $(BTSTACK_DIR)/src/,\
7373
btstack_linked_list.c \
7474
btstack_run_loop.c \
@@ -101,7 +101,6 @@ BTSTACK_SRC += $(addprefix $(BTSTACK_DIR)/src/,\
101101

102102
BTSTACK_SRC += $(addprefix $(BTSTACK_DIR)/src/ble/,\
103103
gatt-service/nordic_spp_service_server.c \
104-
ancs_client.c \
105104
att_db_util.c \
106105
att_db.c \
107106
att_dispatch.c \
@@ -115,6 +114,10 @@ BTSTACK_SRC += $(addprefix $(BTSTACK_DIR)/chipset/cc256x/,\
115114
btstack_chipset_cc256x.c \
116115
)
117116

117+
BTSTACK_SRC += $(addprefix $(BTSTACK_DIR)/platform/posix/,\
118+
hci_dump_posix_stdout.c \
119+
)
120+
118121
# pbio library
119122
PBIO_DIR = ..
120123
PBIO_INC = -I$(PBIO_DIR)/include -I$(PBIO_DIR)

lib/pbio/test/test-pbio.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <unistd.h>
88

99
#include <btstack.h>
10+
#include <hci_dump_posix_stdout.h>
1011
#include <tinytest.h>
1112
#include <tinytest_macros.h>
1213

@@ -37,7 +38,7 @@ void pbio_test_run_thread(void *env) {
3738
}
3839

3940
if (debug) {
40-
hci_dump_open(NULL, HCI_DUMP_STDOUT);
41+
hci_dump_init(hci_dump_posix_stdout_get_instance());
4142
}
4243
hci_dump_enable_log_level(HCI_DUMP_LOG_LEVEL_DEBUG, debug);
4344
hci_dump_enable_log_level(HCI_DUMP_LOG_LEVEL_INFO, debug);

0 commit comments

Comments
 (0)