Skip to content

Commit 5f28220

Browse files
Comments about btstack_run_loop_execute (#388)
Co-authored-by: Graham Sanderson <[email protected]>
1 parent 9736fcd commit 5f28220

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

pico_w/bt/standalone/client.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,20 @@ int main() {
272272
// turn on!
273273
hci_power_control(HCI_POWER_ON);
274274

275+
// btstack_run_loop_execute is only required when using the 'polling' method (e.g. using pico_cyw43_arch_poll library).
276+
// This example uses the 'threadsafe background` method, where BT work is handled in a low priority IRQ, so it
277+
// is fine to call bt_stack_run_loop_execute() but equally you can continue executing user code.
278+
279+
#if 1 // this is only necessary when using polling (which we aren't, but we're showing it is still safe to call in this case)
275280
btstack_run_loop_execute();
281+
#else
282+
// this core is free to do it's own stuff except when using 'polling' method (in which case you should use
283+
// btstacK_run_loop_ methods to add work to the run loop.
284+
285+
// this is a forever loop in place of where user code would go.
286+
while(true) {
287+
sleep_ms(1000);
288+
}
289+
#endif
276290
return 0;
277291
}

pico_w/bt/standalone/server.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,21 @@ int main() {
7373

7474
// turn on bluetooth!
7575
hci_power_control(HCI_POWER_ON);
76+
77+
// btstack_run_loop_execute is only required when using the 'polling' method (e.g. using pico_cyw43_arch_poll library).
78+
// This example uses the 'threadsafe background` method, where BT work is handled in a low priority IRQ, so it
79+
// is fine to call bt_stack_run_loop_execute() but equally you can continue executing user code.
7680

81+
#if 0 // btstack_run_loop_execute() is not required, so lets not use it
7782
btstack_run_loop_execute();
83+
#else
84+
// this core is free to do it's own stuff except when using 'polling' method (in which case you should use
85+
// btstacK_run_loop_ methods to add work to the run loop.
86+
87+
// this is a forever loop in place of where user code would go.
88+
while(true) {
89+
sleep_ms(1000);
90+
}
91+
#endif
7892
return 0;
7993
}

pico_w/bt/standalone/server_with_wifi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int main() {
8585
// register for ATT event
8686
att_server_register_packet_handler(packet_handler);
8787

88-
// set one-shot btstack timer
88+
// use an async worker for for the led
8989
async_context_add_at_time_worker_in_ms(cyw43_arch_async_context(), &heartbeat_worker, HEARTBEAT_PERIOD_MS);
9090

9191
// Connect to Wi-Fi

0 commit comments

Comments
 (0)