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

_bleio HCI implementation #3310

Merged
merged 43 commits into from
Sep 1, 2020
Merged

_bleio HCI implementation #3310

merged 43 commits into from
Sep 1, 2020

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Aug 21, 2020

Adds _bleio support for UART-based HCI adapters. Tested with ESP32 firmware on Metro M4 Airlift and with an ESP32 breakout. Firmware used is attached to this PR.

This version supports operation as a peripheral only. Specifically it has been tested with UARTService, using the Bluefruit LE Connect app. Scanning, initiating a connection, access to remote characteristics, and bonding/pairing are not yet implemented. Code to be rewritten is commented out and mostly marked as //FIX.

The HCI and ATT protocol code here was derived from ArduinoBLE (our fork), and from include files from Zephyr BLE support. It was converted from C++ to C, and restructured in various ways. Ad hoc packet packing and unpacking was replaced with the use of structs from the Zephyr include files.

The ESP32 firmware used does not have extended advertising enabled. There is latent support for extended advertising in this PR, but it has not been tested.

The ESP32 needs initialization before use in BLE mode. That code is not here, but will be added in a shortly forthcoming PR to the https://github.com/adafruit/Adafruit_CircuitPython_BLE library.

Use this firmware (unzip first) to test:

NINA HCI BT.bin.zip

You will need adafruit/Adafruit_CircuitPython_BLE#103, or the latest version of adafruit_ble, after that PR is merged.

Fixes #3228 (list inconsistency).
Fixes #1292 (use HCI).

@dhalbert dhalbert requested a review from tannewt August 21, 2020 15:12
@dhalbert
Copy link
Collaborator Author

Use this firmware (unzip first) to test:

NINA HCI BT.bin.zip

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Here are my comments wrt/shared-bindings only.

shared-bindings/_bleio/Adapter.c Outdated Show resolved Hide resolved
supervisor/shared/bluetooth.c Show resolved Hide resolved
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Just a few questions. Nothing major.

@jerryneedell
Copy link
Collaborator

jerryneedell commented Aug 31, 2020

Tested ble_uart_echo_test on a metro_m4_airlift_lite with the NINA HCI BT.bin firmware -- works!

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

One question here plus one on the library. Should this take native pins only? Is it prepared for a DigitalInOut-like class?

shared-bindings/_bleio/__init__.c Show resolved Hide resolved
Copy link
Collaborator Author

@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.

One question here plus one on the library. Should this take native pins only? Is it prepared for a DigitalInOut-like class?

I am taking DigitalInOuts because the calling library already needs to use them to do the initial hard reset of the adapter. It's not prepared for a duck-type DigitalInOut class, but I think we can code for that internally when we need to. I could imagine that there's an internal software HCI adapter that has rts and cts signals that are not actual pins, so I don't think it should take pins. I'm thinking about how displayio takes abstractions rather than pins, for instance.

shared-bindings/_bleio/Adapter.c Outdated Show resolved Hide resolved
@dhalbert dhalbert requested a review from tannewt September 1, 2020 17:06
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you!

@tannewt tannewt merged commit f0e60da into adafruit:main Sep 1, 2020
@ladyada
Copy link
Member

ladyada commented Sep 1, 2020

woohoo

@dhalbert dhalbert deleted the ble_hci branch September 2, 2020 21:24
jepler pushed a commit to jepler/circuitpython that referenced this pull request Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants