Skip to content

Commit 855ea36

Browse files
committed
pbio/drv/bluetooth: Full overhaul.
This moves the remaining functionality of pbsys/bluetooth to pbdrv/bluetooth to be consistent with the USB drivers. This way, bluetooth and usb don't have to depend on the system status and runtime. This drops one level of abstraction, so that printing with stdout no longer goes through two cascaded processess/ This replaces scheduling arbitrary Bluetooth tasks with dedicated scheduling of stdout/status/peripheral/scan task categories. This allows all categories to be simultaneously scheduled, while also immediately copying configuration data and raising if a conflicting operation is already in progress. For example, you can now set the remote bluetooth light or broadcasting data without clashes. When the operation is available for scheduling, data is copied right away so we avoid issues with using MicroPython data after free, simplifying the module code. The pbio_task queue is replaced with a single loop that will go over the above task categories and execute it if something was scheduled. This also gives us deterministic control over the order of operations. Procedures such as ascan and connect and disconnect are now also awaitable, so a dedicated connect() method could now be added trivially. Throughput of stdout is improved slightly for short messages as there is no longer a double-buffer in pbsys that would block if a send operation was already queued. Data can now be queued whenever there is room in the buffer, and the main Bluetooth process will drain as much as it can the next time it gets around the loop of Bluetooth tasks. While we are doing all this, replace the Contiki protothreads with pbio/os protothreads.
1 parent 204f5cb commit 855ea36

30 files changed

+2299
-2944
lines changed

bricks/_common/sources.mk

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
123123
drv/block_device/block_device_flash_stm32.c \
124124
drv/block_device/block_device_test.c \
125125
drv/block_device/block_device_w25qxx_stm32.c \
126+
drv/bluetooth/bluetooth.c \
126127
drv/bluetooth/bluetooth_btstack_control_gpio.c \
127-
drv/bluetooth/bluetooth_btstack_run_loop_contiki.c \
128128
drv/bluetooth/bluetooth_btstack_uart_block_stm32_hal.c \
129129
drv/bluetooth/bluetooth_btstack.c \
130130
drv/bluetooth/bluetooth_init_cc2564C_1.4.c \
@@ -229,12 +229,10 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
229229
src/protocol/pybricks.c \
230230
src/servo.c \
231231
src/tacho.c \
232-
src/task.c \
233232
src/trajectory.c \
234233
src/util.c \
235234
sys/battery_temp.c \
236235
sys/battery.c \
237-
sys/bluetooth.c \
238236
sys/command.c \
239237
sys/core.c \
240238
sys/hmi.c \

0 commit comments

Comments
 (0)