-
-
Notifications
You must be signed in to change notification settings - Fork 80
pbio/drv/bluetooth: Full overhaul. #388
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is not yet implemented for the driver side. At the moment, the usb drivers poll the status for partial changes, and the bluetooth status is managed by pbsys/bluetooth, which is to be removed.
65131f9 to
d71fdfa
Compare
d71fdfa to
855ea36
Compare
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.
Otherwise clean always led to errors such as ../drv/bluetooth/bluetooth_btstack.c:25:10: fatal error: genhdr/pybricks_service.h: No such file or directory 25 | #include "genhdr/pybricks_service.h"
855ea36 to
0b30a63
Compare
Member
Author
|
Splitting this into a few separate PRs for future reference. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is one of the last steps in the major overhaul in the past year concerning the UI, HMI, Bluetooth, async, and program start/stop. The long term goals here were to generalize the host interface to facilitate connectivity other than BLE such as USB. This has been added to Prime/Essential Hub, and is key to enabling EV3 and NXT support.
pbio/sys/host: Schedule status update.
pbio/drv/usb: Hook up receive handler and status.
Before we do it for Bluetooth in the next commit, let's start with USB. This removes the
pbio/sysdependency from the USB drivers. Instead we schedule the status and set a callback for callingpbsys/command. Also fixes a minor status timer issue in the EV3 USB driver.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 common process 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. We are also no longer killing the Bluetooth SPI process from
pbsys, potentially in the middle of something.Procedures such as scan 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.
Work in progress
pbdrv_bluetooth_deinit. We used to simply kill the Bluetooth process, but we can now wait for pending tasks and shut down gracefully.Future consideration
With the major overhaul out of the way, we could consider doing the following in future releases.