shermp / Pico-ASHA

ASHA on a Pico
BSD 3-Clause "New" or "Revised" License
29 stars 1 forks source link

Stream stability improvements #6

Closed shermp closed 2 months ago

shermp commented 2 months ago

This PR has several changes to drastically improve stream stability.

Btstack has added an API to obtain the number of outgoing credits from a L2CAP CoC connection. This allows detecting when Pico-ASHA runs out of credits. When this happens, Pico-ASHA stops and restarts the stream using the AudioControlPoint characteristic. It won't start streaming until the number of available credits increases. As more hearing device brands are tested, this may need to be modified.

This PR switches to using a (temporary) custom fork of btstack which implements this outgoing credit API.

It turns out, the way I was running the main BT audio streaming loop was causing issues. I believe it was competing with btstack for execution time, which caused issues such as random device disconnects. I have switched to running the code using pico_async_context, which is how btstack is implemented on the Pico. I am using the same async context that btstack is, which should allow for proper scheduling.

Some logging improvements have been made, especially when HCI dump is enabled. It should no longer be necessary to filter out Pico-ASHA log entries from the HCI dump.