Skip to content

Refine _bleio #2236

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 5 commits into from
Nov 5, 2019
Merged

Refine _bleio #2236

merged 5 commits into from
Nov 5, 2019

Conversation

tannewt
Copy link
Member

@tannewt tannewt commented Oct 22, 2019

This PR refines the _bleio API. It was originally motivated by
the addition of a new CircuitPython service that enables reading
and modifying files on the device. Moving the BLE lifecycle outside
of the VM motivated a number of changes to remove heap allocations
in some APIs.

It also motivated unifying connection initiation to the Adapter class
rather than the Central and Peripheral classes which have been removed.
Adapter now handles the GAP portion of BLE including advertising, which
has moved but is largely unchanged, and scanning, which has been enhanced
to return an iterator of filtered results.

Once a connection is created (either by us (aka Central) or a remote
device (aka Peripheral)) it is represented by a new Connection class.
This class knows the current connection state and can discover and
instantiate remote Services along with their Characteristics and
Descriptors.

Relates to #586

This PR refines the _bleio API. It was originally motivated by
the addition of a new CircuitPython service that enables reading
and modifying files on the device. Moving the BLE lifecycle outside
of the VM motivated a number of changes to remove heap allocations
in some APIs.

It also motivated unifying connection initiation to the Adapter class
rather than the Central and Peripheral classes which have been removed.
Adapter now handles the GAP portion of BLE including advertising, which
has moved but is largely unchanged, and scanning, which has been enhanced
to return an iterator of filtered results.

Once a connection is created (either by us (aka Central) or a remote
device (aka Peripheral)) it is represented by a new Connection class.
This class knows the current connection state and can discover and
instantiate remote Services along with their Characteristics and
Descriptors.

Relates to micropython#586
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

This looks really excellent! The refactoring to Connection makes a lot of sense and really presents the right abstraction. Thank you for the big re-think!

@dhalbert
Copy link
Collaborator

The check failures are all in supervisor/shared/bluetooth.c, I think.

tannewt added a commit to tannewt/Adafruit_CircuitPython_BLE that referenced this pull request Oct 23, 2019
This makes Advertisement and Service definitions declarative by
factoring out parsing logic out into shareable descriptor classes
similar to how the Register library works.

This also introduces SmartAdapter and SmartConnection which will
auto-create the correct Advertisements and Services without requiring
any direct use of UUIDs. Instead, classes are used to identify
relevant objects to "recognize".

This requires adafruit/circuitpython#2236 and
relates to adafruit/circuitpython#586.
@tannewt
Copy link
Member Author

tannewt commented Oct 23, 2019

Thanks for the fast review @dhalbert. Please take another look. I'll be on a plane all Wednesday but will try to take a peek Thursday.

@dhalbert
Copy link
Collaborator

dhalbert commented Nov 1, 2019

@tannewt I'm confused about why there are now merge conflicts.

@tannewt
Copy link
Member Author

tannewt commented Nov 1, 2019

@dhalbert Jeff fixed a typo in one of the comments I changed. Merged now.

@dhalbert dhalbert self-requested a review November 1, 2019 20:25
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

OK, great! Merging this to start rewriting other examples and testing with the new API.

Warning: use the correct version of Adafruit_CircuitPython_BLE with builds following this merge.

@dhalbert dhalbert merged commit 8cd2f87 into adafruit:master Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants