Skip to content

Conversation

@laurensvalk
Copy link
Member

This should help us with #435, so we can avoid inserting POSIX code directly into bluetooth_btstack with #ifs. It also makes us use the standard BTstack IRQ poll mechanism to simplify the next step.

There is also an init hook that runs before any btstack code runs. This should help avoid having to do things like static bool already_ran = false; already_ran = already_ran just to get something to run once. This is where we could parse environment variables or set up logging, etc.

This is needed for the POSIX port, so we don't have to make special handlers to protect init from running twice.
@coveralls
Copy link

coveralls commented Dec 23, 2025

Coverage Status

coverage: 51.058% (-4.8%) from 55.816%
when pulling a17c1d2 on btstack
into d92d07d on master.

laurensvalk and others added 11 commits December 29, 2025 09:24
Most BTstack ports do it this way, including embedded variants. This will let
us use the POSIX libusb variant without modifying it.
This is needed for the POSIX port, which needs to poll files.
Co-authored-by: James Aguilar <aguilar.james@gmail.com>
This will provide stdio even when Bluetooth is not enabled.

The current Bluetooth mock driver does this too so we are currently duplicating it, but this will be replaced by an actual Bluetooth driver shortly.
This lets us test BLE features on the REPL as we enable the new Virtual Hub driver, so we can see it working.
In practice, we are allowing users to reinstantiate the hub. The question is whether we really should, but for now the simulation should be consistent with reality.
The POSIX variant needs to handle specific packets that are not relevant to the other platforms.
This will redirect debug output to usb and uart, when available.
No need to hook directly into the uart driver anymore.
We don't need duplicates for EV3 and the POSIX variants.
We call this again when we discover the local version. We shouldn't be calling this twice.
The pbdrv_bluetooth_is_connected check should protect against this, but if it fails we get a segfault if config was never set, so if no peripheral was ever connected.
On some platforms it may not be enabled, e.g. when the USB Bluetooth dongle is
not plugged in.
Copy link
Member

@dlech dlech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// Proceed to start Bluetooth process only if platform init passes.
pbio_error_t err = pbdrv_bluetooth_btstack_platform_init();
if (err != PBIO_SUCCESS) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful to debug print error code here?

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.

4 participants