Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: cyw43 / Pico W bluetooth, take 2 #2865

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

WIP: cyw43 / Pico W bluetooth, take 2 #2865

wants to merge 3 commits into from

Conversation

Dirbaio
Copy link
Member

@Dirbaio Dirbaio commented Apr 24, 2024

Based on #1820, rebased and cleaned up a bit.

cc issue #1516

Current status is

  • Bluetooth init works
  • Sending/receiving HCI packets works
  • There's an example using the trouble bluetooth stack that works up to advertising. There's some impedance mismatch in how to glue it with trouble's HCI traits.

Major roadblocks left are:

  • Properly integrate bluetooth into the cyw43 event loop, so you can concurrently use it with WiFi. It'd probably need setting up HCI packet queues with ZerocopyChannel similar to how ethernet packets are handled, allowing the user to run Trouble in a separate "bluetooth task"
  • Design a good API for constructing the cyw43 driver in either "just wifi", "just bluetooth" or "wifi+bluetooth" modes. The API should be designed so that you don't pay for what you don't use, ie if you initialize just wifi you don't need bluetooth firmware on flash, and the bluetooth-specific code from cyw43 doesn't get compiled-in. Can be done with either "mode" generics, or Cargo features. Cargo features is probably easier.
  • Get it properly hooked up to Trouble, so that more than just advertising works.

I don't have the bandwidth to work on this, and probably won't for a while (months). If you want to jump in and carry this over the finish line, ping me on Embassy's Matrix chat.

@Dirbaio Dirbaio marked this pull request as draft April 24, 2024 17:58
@lulf
Copy link
Member

lulf commented Apr 24, 2024

Quick update: i've update the bluetooth_trouble example to use the latest developments from trouble and bt-hci would should simplify the integration quite a bit.

@Dirbaio
Copy link
Member Author

Dirbaio commented Apr 24, 2024

nie 🚀

(note: when this is finished, we probably want the example to live in the trouble repo. I think that's where most of the "API evolution" will be, so it'll be easier to keep it up to date there. The cyw43 API is just "hci read, hci write" so probably won't change much once done.)

@brandonros
Copy link
Contributor

Would you be interested in merging this (so it doesn't go stale) now and let the "combined WiFi mode" related features sit in a backlog?

I'm down to try this part:

Get it properly hooked up to Trouble, so that more than just advertising works.

Copy link
Contributor

Choose a reason for hiding this comment

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

did you want to check this in?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes oops

}

if bluetooth_enabled {
// TODO: call runner.init_bluetooth somehow and pass it bluetooth_firmware?
Copy link
Contributor

Choose a reason for hiding this comment

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

is this TODO i put still accurate?


impl embedded_io_async::Read for HciConnector {
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, HciConnectorError> {
// TODO: how to get all the way to runner.hci_read()?
Copy link
Contributor

Choose a reason for hiding this comment

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

i feel like in the PR description you said HCI read + write is working so this TODO has to be wrong?

let version_length = firmware[0];
let _version = &firmware[1..=version_length as usize];
// skip version + 1 extra byte as per cybt_shared_bus_driver.c
let firmware = &firmware[version_length as usize + 2..];
Copy link
Contributor

@soypat soypat May 18, 2024

Choose a reason for hiding this comment

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

Is comment dated? It seems to me this is skipping 2 bytes, not one

edit: ah the first length byte is included in the 2

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.

None yet

4 participants