Skip to content

Move hub Bluetooth size optimization - #503

Open
dlech wants to merge 2 commits into
pybricks:masterfrom
dlech:bluetooth-const-commands
Open

Move hub Bluetooth size optimization#503
dlech wants to merge 2 commits into
pybricks:masterfrom
dlech:bluetooth-const-commands

Conversation

@dlech

@dlech dlech commented Sep 12, 2026

Copy link
Copy Markdown
Member

Making the code more efficient size-wise to get another 350 bytes or so for other things.

The two functions are identical: both read a 3 byte response with a
status and a handle. Follow the existing hci_le_command_end alias
pattern and keep only one copy. The linker was already merging the
two, so this does not change the binary.
Most HCI commands that the Move Hub sends have parameters that are all
fixed at compile time, but each call site paid for runtime packing via
the aci_*_begin functions plus two protothread checkpoints to wait for
the transport and for command completion. Store those commands as
complete const parameter blobs instead and send them through a shared
child protothread, so each site is a single checkpoint. A shared child
state is safe because at most one HCI command exchange is in flight at
a time, which the global hci_command_complete flag already assumes.

Also derive the advertising scan response from a const template with
only the hub name appended at runtime, introduce a static initializer
for the Device Information Service PnP ID so the GATT characteristic
value can live in flash instead of being packed on the fly, and share
the duplicated stop-scanning failure path in scan and connect.

The command blobs were verified byte for byte against the output of
the original packing code. This saves around 350 bytes on the Move
Hub.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant