Skip to content

Commit f97f483

Browse files
committed
pbio/drv/bluetooth: Don't wait on power initialization.
Since all Bluetooth commands are buffered and handled by the event loop, we don't need to wait for the driver to fully power on before leaving `pbdrv`. This allows power on to complete in the background while we initialize pbio and do hmi boot animations in pbsys, saving about half the boot time on SPIKE Prime.
1 parent dff7279 commit f97f483

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/pbio/drv/bluetooth/bluetooth.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ void pbdrv_bluetooth_init(void) {
6666
// as soon as the previous one completes + 1 byte for ring buf pointer
6767
static uint8_t stdout_buf[PBDRV_BLUETOOTH_MAX_CHAR_SIZE * 2 + 1];
6868
lwrb_init(&stdout_ring_buf, stdout_buf, PBIO_ARRAY_SIZE(stdout_buf));
69-
pbio_busy_count_up();
7069

7170
pbdrv_bluetooth_init_hci();
7271
}
@@ -435,8 +434,6 @@ pbio_error_t pbdrv_bluetooth_process_thread(pbio_os_state_t *state, void *contex
435434

436435
DEBUG_PRINT("Bluetooth is now on and initialized.\n");
437436

438-
pbio_busy_count_down();
439-
440437
pbio_os_timer_set(&status_timer, PBDRV_BLUETOOTH_STATUS_UPDATE_INTERVAL);
441438

442439
// Service scheduled tasks as long as Bluetooth is enabled.

lib/pbio/test/sys/test_bluetooth.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ static pbio_error_t test_bluetooth(pbio_os_state_t *state, void *context) {
2626

2727
pbsys_host_init();
2828

29-
// power should be initialized by the time pbdrv completes.
30-
tt_want_uint_op(pbio_test_bluetooth_get_control_state(), ==, PBIO_TEST_BLUETOOTH_STATE_ON);
29+
// power should be initialized to off
30+
tt_want_uint_op(pbio_test_bluetooth_get_control_state(), ==, PBIO_TEST_BLUETOOTH_STATE_OFF);
3131

32+
// Power is still off, but it should be possible to schedule this command.
3233
pbdrv_bluetooth_start_advertising(true);
3334
PBIO_OS_AWAIT(state, &sub, pbdrv_bluetooth_await_advertise_or_scan_command(&sub, NULL));
3435

36+
// power should be initialized by the time any command completes.
37+
tt_want_uint_op(pbio_test_bluetooth_get_control_state(), ==, PBIO_TEST_BLUETOOTH_STATE_ON);
38+
3539
tt_want(pbio_test_bluetooth_is_advertising_enabled());
3640

3741
pbio_test_bluetooth_connect();

0 commit comments

Comments
 (0)