-
Notifications
You must be signed in to change notification settings - Fork 178
Update BLE documentation #1458
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
ChrisGooch-Arm
merged 7 commits into
ARMmbed:development
from
paul-szczepanek-arm:ble-rewrite
Jul 19, 2021
Merged
Update BLE documentation #1458
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5edd493
replace removed services with the new services repo
paul-szczepanek-arm 56e6c4f
make BLE docs more relevant
paul-szczepanek-arm 8346cf6
reorder ble articles
paul-szczepanek-arm cce83e5
move ble stacks section to the bottom
paul-szczepanek-arm f2121c3
typo
paul-szczepanek-arm 83dd837
add link and note about debugging ble
paul-szczepanek-arm dab0faa
Merge branch 'development' into ble-rewrite
ChrisGooch-Arm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,102 @@ | ||
# BLE | ||
# BLE | ||
|
||
<span class="notes">**Note:** Some functions, variables or types have been deprecated. Please see the class reference linked below for details.</span> | ||
Bluetooth low energy (BLE) is a low power wireless technology standard for building personal area networks. Typical | ||
applications of BLE are health care, fitness trackers, beacons, smart home, security, entertainment, proximity sensors, | ||
industrial and automotive. | ||
|
||
Bluetooth low energy (BLE) is a low power wireless technology standard for building personal area networks. Typical applications of BLE are health care, fitness trackers, beacons, smart home, security, entertainment, proximity sensors, industrial and automotive. | ||
Arm Mbed BLE is the Bluetooth Low Energy software solution for Mbed. Many Mbed | ||
[targets and components](https://os.mbed.com/platforms/?mbed-enabled=15&connectivity=3) support Mbed BLE. Developers can | ||
use it to create new BLE enabled applications. | ||
|
||
Arm Mbed BLE, also called `BLE_API`, is the Bluetooth Low Energy software solution for Mbed. Many Mbed [targets and components](https://os.mbed.com/platforms/?mbed-enabled=15&connectivity=3) support Mbed BLE. Developers can use it to create new BLE enabled applications. | ||
## BLE API | ||
|
||
Mbed’s `BLE_API` interfaces with the BLE controller on the board. It hides the BLE stack’s complexity behind C++ abstractions and is compatible with all BLE-enabled Mbed board. The Mbed OS `BLE_API` automatically configuring the clocks, timers and other hardware peripherals to work at their lowest power consumption. | ||
Mbed's BLE API is available through C++ classes. It hides the BLE stack’s complexity and is compatible with all | ||
BLE-enabled Mbed board. It automatically configures the clocks, timers and other hardware peripherals to work at their | ||
lowest power consumption. | ||
|
||
## `BLE_API`, bridges and stacks | ||
### BLE API headers | ||
|
||
<span class="images"></span> | ||
BLE API is accessible through several header files: | ||
|
||
You can build a BLE application using Mbed OS, `BLE_API` and a controller-specific Bluetooth stack together with some bridge software to adapt it to `BLE_API`: | ||
- [BLE.h](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/BLE.h) - acquire the BLE | ||
instance, perform initialisation | ||
- [Gap.h](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/Gap.h) - advertising, | ||
scanning, connecting | ||
- [GattClient.h](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/GattClient.h) - | ||
GATT operations as client | ||
- [GattServer.h](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/GattServer.h) - | ||
GATT operations as server | ||
- [SecurityManager.h](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/SecurityManager.h) - | ||
authentication, keys, encryption | ||
|
||
- `BLE_API` as described above. | ||
- The bridge software is specific to each vendor’s board. It provides the instantiations for the interfaces `BLE_API` offers and helps drive the underlying controller and Bluetooth stack. | ||
- The Bluetooth stack implements the Bluetooth protocol and is specific to the controller, so a vendor using different controllers may provide different stacks. | ||
Specific documentation for each component is available inside each of these headers. | ||
|
||
## Inside `BLE_API` | ||
### Thread safety | ||
|
||
<span class="images"></span> | ||
BLE implementation does not provide thread safety and assumes single thread execution. Event processing and API calls | ||
must be dispatched from the same thread. | ||
|
||
`BLE_API` offers building blocks to help construct applications. These fall into two broad categories: | ||
### Asynchronous calls | ||
|
||
1. Interfaces under **`ble/`** to express BLE constructs, such as GAP, GATT, services and characteristics. | ||
Many API calls are asynchronous and provide results through callbacks. These are implemented as events. To receive these | ||
events register an EventHandler that is specific to that component. For example to receive events from Gap, use | ||
`Gap::setEventHandler()` passing in your implementation that inherits from `Gap::EventHandler`. Your class will override | ||
the events (methods) you are interested in, the others will inherit the do-nothing implementations provided by the parent. | ||
|
||
1. Classes under `ble/services` to offer reference implementations for many of the commonly used GATT profiles. The code under 'services/' isn't essential, but it’s a useful starting point for prototyping. We continue to implement the standard GATT profiles. | ||
### Instancing a BLE device | ||
|
||
## The BLEDevice class and header | ||
All BLE operations are executed on an instance of BLE accessible through a function in the header `ble/BLE.h`. | ||
|
||
The entry point of Mbed's `BLE_API` is the BLE class accessible using the header `ble/BLE.h`. This class allows you to obtain a BLE object that includes the basic attributes of a spec-compatible BLE device and can work with any BLE radio: | ||
|
||
```c TODO | ||
```c | ||
#include "ble/BLE.h" | ||
|
||
BLE& mydevicename = BLE::Instance(); | ||
``` | ||
|
||
The class's member functions can be divided by purpose: | ||
### BLE stacks | ||
|
||
To build and application using BLE you will be using the Mbed OS BLE API and an implementation of the BLE stack | ||
appropriate for your board. The implementation is split into Host and Controller part. They can both run on the same | ||
chip or two separate ones. They will be both communicating through HCI (Host Controller Interface, a well defined | ||
protocol that is part of the Bluetooth specification). Read more about the HCI interface in Mbed OS | ||
[here](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/driver/doc/HCIAbstraction.md). | ||
|
||
Currently, all implementation use the Cordio stack for the Host part. The Controller implementation may be either also | ||
Cordio or any other vendor supplier one. Each board will have a driver that implements the communication channel | ||
between the Host and its implementation of the controller. To add support for a new board please refer to the | ||
[BLE porting guide](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/driver/doc/PortingGuide.md). | ||
|
||
1. Basic BLE operations, such as initializing the controller. | ||
## Debugging | ||
|
||
1. Accessor to Bluetooth Modules that manage GAP, GATT or the security. | ||
To learn about debugging with mbed go to: | ||
|
||
## Usage | ||
[Debugging Mbed OS](../debug-test/index.html) | ||
|
||
1. Set up advertising and connection modes. | ||
1. Assign UUIDs to the service and its characteristic. | ||
1. Create an input characteristic. | ||
1. Construct a service class and add it to the BLE stack. | ||
1. Push notifications when the characteristic's value changes. | ||
However, keep in mind when trying to debug connectivity issues that if more than one device is involved it might | ||
not be possible to stop your target without the communication breaking down. A less invasive way to help you understand | ||
what is happening might be to use tracing. | ||
|
||
## Tracing | ||
|
||
To debug issues (or to understand what the stack is doing) it may be helpful to enable tracing. | ||
|
||
Traces can be turned on by overriding configuration options in you mbed_app.json: | ||
To enable traces override configuration options in you mbed_app.json: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a note about debugging ? |
||
|
||
``` | ||
"target_overrides": { | ||
"*": { | ||
"mbed-trace.enable": true, | ||
"mbed-trace.max-level": "TRACE_LEVEL_DEBUG", | ||
"cordio.trace-hci-packets": true, | ||
"cordio.trace-cordio-wsf-traces": true, | ||
"cordio.trace-hci-packets": false, | ||
"cordio.trace-cordio-wsf-traces": false, | ||
"ble.trace-human-readable-enums": true | ||
} | ||
} | ||
``` | ||
|
||
and compiling your application with `--profile debug`. Please note that with all options enabled your application may become too big - disable some options or lower the `mbed-trace.max-level`. Detailed documentation is available in the tracing [README.md](https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed-trace/README.md). | ||
Compile your application with `--profile debug`. Please note that with all options enabled your application may become | ||
too big - disable some options or lower the `mbed-trace.max-level`. Detailed documentation is available in the tracing | ||
[README.md](https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed-trace/README.md). | ||
|
||
All BLE modules contain tracing, each of the modules prefixed with a unique tag: | ||
- `BLE ` - general BLE traces | ||
|
@@ -86,11 +112,16 @@ All BLE modules contain tracing, each of the modules prefixed with a unique tag: | |
|
||
Any contributions to BLE should include appropriate tracing code. | ||
|
||
## BLE class reference | ||
## BLE examples | ||
|
||
[](https://os.mbed.com/docs/mbed-os/development/mbed-os-api-doxy/classble_1_1_b_l_e.html) | ||
We have placed all of our BLE examples in a single GitHub repository: | ||
- [GitHub repository](https://github.com/ARMmbed/mbed-os-example-ble) | ||
|
||
## Related content | ||
Use the release version matching the mbed-os version you plan to use. | ||
|
||
- Mbed Enabled [targets and components](https://os.mbed.com/platforms/?mbed-enabled=15&connectivity=3) that support BLE. | ||
- [BLE example on GitHub](https://github.com/ARMmbed/mbed-os-example-ble/). | ||
Development happens on the `development` branch. If you report an issue or open a PR, please check the version on the | ||
`development` branch and target it for any proposed changes. | ||
|
||
## BLE class reference | ||
|
||
[](https://os.mbed.com/docs/mbed-os/development/mbed-os-api-doxy/classble_1_1_b_l_e.html) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# BLE Services | ||
|
||
Mbed OS BLE implementation isn't bundled with any BLE services. Services are in an external repository. Please go to: | ||
- [ble-services](https://github.com/ARMmbed/mbed-os-experimental-ble-services) | ||
|
||
This is a community led effort to provide implementations of services both from the official BLE spec and user defined | ||
ones. It contains libraries which you can import into your project to use the services. Please refer to documentation | ||
inside the repository: | ||
- [README.md](https://github.com/ARMmbed/mbed-os-experimental-ble-services/blob/main/README.md) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 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 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 file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can adopt a more logical organization:
What do you think ?