Skip to content

nrf: Split the ble module into a shared part and the port implementation #1014

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 1 commit into from
Jul 13, 2018

Conversation

arturo182
Copy link
Collaborator

This allows other ports to implement these shared bindings.

This is one part of #995

@arturo182 arturo182 requested review from tannewt and dhalbert July 10, 2018 19:56
@dhalbert
Copy link
Collaborator

This is very clean. I am thinking that maybe we want to make a class that lives under ble, like ble.Bluetooth, ble.Device, or ble.BLE. Better suggestions welcomed. Then we have a singleton instance that is the device. We can then use properties, which we can't do with a regular module. So

if ble.bluetooth.enabled:
    ...
ble.bluetooth.enabled = False
print(ble.bluetooth.address)

etc.

Later there could be other things that live under ble, maybe message classes?? I don't know enough now to make good suggestions. Maybe ble should be bleio??

Some other examples of this kind of singleton class in CircuitPython are microcontroller.cpu (instance of microcontroller.Processor) and nvm.Bytearray.

@arturo182
Copy link
Collaborator Author

Yes, I wanted to use a property for enabled and address but had two hesitations: 1. would need a class, 2. would break the current API.

Regarding having a class, I think best name would be Adapter, pretty common terminology in the BT world. We could keep all other classes like Central, Peripheral, Service, Characteristic inside a bleio module as well, but that would break compatibility with bluepy.

@arturo182
Copy link
Collaborator Author

Let me know if you want me to move the functions to a Adapter singleton.

@tannewt
Copy link
Member

tannewt commented Jul 11, 2018

I vote to use a singleton.

We'll break compatibility with upstream due to our use of properties anyway. We'll break with bluepy because we need more APIs and their methods are non-standard camel case.

So, lets do what we think is best. Thanks!

@arturo182
Copy link
Collaborator Author

Woo, let the Bluetooth overhaul begin! Expect many PRs soon :D

@arturo182
Copy link
Collaborator Author

So we agree on bleio?

@tannewt
Copy link
Member

tannewt commented Jul 11, 2018

Ya, bleio works for me. *io is kinda lame but its consistent with our previous stuff and helps make it a unique name.

@dhalbert
Copy link
Collaborator

bleio is better than bleah :)

@arturo182
Copy link
Collaborator Author

bleep? ;)

@arturo182 arturo182 force-pushed the nrf_shared_ble branch 2 times, most recently from 3e4ee5c to b8ca21d Compare July 11, 2018 21:05
@arturo182
Copy link
Collaborator Author

@tannewt @dhalbert Updated :)

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 excellent to me! Just query and one minor change.

STATIC mp_obj_t bleio_adapter_get_enabled(mp_obj_t self) {
const bool enabled = common_hal_bleio_adapter_get_enabled();

return enabled ? mp_const_true : mp_const_false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can do return mp_obj_new_bool(common_hal_bleio_adapter_get_enabled());. This is common in other shared-bindings implementations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Didn't know that one, will fix!

#ifndef MICROPY_PY_BLE_NUS
#define MICROPY_PY_BLE_NUS (0)
#ifndef MICROPY_PY_UBLUEPY
#define MICROPY_PY_UBLUEPY (0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: are we going to get rid of ubluepy at some point or does it serve some purpose in other nrf ports?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, next step is port ubluepy classes to bleio, I just like to keep things separated and do them one step at a time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, sounds good!

This allows other ports to implement these shared bindings.
@arturo182
Copy link
Collaborator Author

@dhalbert Fixed!

@dhalbert dhalbert merged commit bfe14ff into adafruit:master Jul 13, 2018
@arturo182 arturo182 deleted the nrf_shared_ble branch July 13, 2018 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants