Skip to content

Commit 967069f

Browse files
Merge pull request #1458 from paul-szczepanek-arm/ble-rewrite
Update BLE documentation
2 parents e8f9ac8 + dab0faa commit 967069f

File tree

10 files changed

+86
-99
lines changed

10 files changed

+86
-99
lines changed

docs.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -814,26 +814,24 @@
814814
},
815815
{
816816
"title": "Bluetooth APIs",
817-
"sources": [{
818-
"path": "docs/api/connectivity/bluetooth/BatteryService.md"
819-
},
817+
"sources": [
820818
{
821819
"path": "docs/api/connectivity/bluetooth/BLE.md"
822820
},
823821
{
824822
"path": "docs/api/connectivity/bluetooth/Gap.md"
825823
},
826824
{
827-
"path": "docs/api/connectivity/bluetooth/GattClient.md"
825+
"path": "docs/api/connectivity/bluetooth/GattServer.md"
828826
},
829827
{
830-
"path": "docs/api/connectivity/bluetooth/GattServer.md"
828+
"path": "docs/api/connectivity/bluetooth/SecurityManager.md"
831829
},
832830
{
833-
"path": "docs/api/connectivity/bluetooth/HeartRateService.md"
831+
"path": "docs/api/connectivity/bluetooth/BLE_services.md"
834832
},
835833
{
836-
"path": "docs/api/connectivity/bluetooth/SecurityManager.md"
834+
"path": "docs/api/connectivity/bluetooth/GattClient.md"
837835
},
838836
{
839837
"path": "docs/api/connectivity/bluetooth/Optimising_for_performance.md"
Lines changed: 69 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,102 @@
1-
# BLE
1+
# BLE
22

3-
<span class="notes">**Note:** Some functions, variables or types have been deprecated. Please see the class reference linked below for details.</span>
3+
Bluetooth low energy (BLE) is a low power wireless technology standard for building personal area networks. Typical
4+
applications of BLE are health care, fitness trackers, beacons, smart home, security, entertainment, proximity sensors,
5+
industrial and automotive.
46

5-
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.
7+
Arm Mbed BLE is the Bluetooth Low Energy software solution for Mbed. Many Mbed
8+
[targets and components](https://os.mbed.com/platforms/?mbed-enabled=15&connectivity=3) support Mbed BLE. Developers can
9+
use it to create new BLE enabled applications.
610

7-
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.
11+
## BLE API
812

9-
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.
13+
Mbed's BLE API is available through C++ classes. It hides the BLE stack’s complexity and is compatible with all
14+
BLE-enabled Mbed board. It automatically configures the clocks, timers and other hardware peripherals to work at their
15+
lowest power consumption.
1016

11-
## `BLE_API`, bridges and stacks
17+
### BLE API headers
1218

13-
<span class="images">![](../../../images/BLEDiagram.png)</span>
19+
BLE API is accessible through several header files:
1420

15-
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`:
21+
- [BLE.h](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/BLE.h) - acquire the BLE
22+
instance, perform initialisation
23+
- [Gap.h](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/Gap.h) - advertising,
24+
scanning, connecting
25+
- [GattClient.h](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/GattClient.h) -
26+
GATT operations as client
27+
- [GattServer.h](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/GattServer.h) -
28+
GATT operations as server
29+
- [SecurityManager.h](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/SecurityManager.h) -
30+
authentication, keys, encryption
1631

17-
- `BLE_API` as described above.
18-
- 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.
19-
- The Bluetooth stack implements the Bluetooth protocol and is specific to the controller, so a vendor using different controllers may provide different stacks.
32+
Specific documentation for each component is available inside each of these headers.
2033

21-
## Inside `BLE_API`
34+
### Thread safety
2235

23-
<span class="images">![](../../../images/Inside_API.png)</span>
36+
BLE implementation does not provide thread safety and assumes single thread execution. Event processing and API calls
37+
must be dispatched from the same thread.
2438

25-
`BLE_API` offers building blocks to help construct applications. These fall into two broad categories:
39+
### Asynchronous calls
2640

27-
1. Interfaces under **`ble/`** to express BLE constructs, such as GAP, GATT, services and characteristics.
41+
Many API calls are asynchronous and provide results through callbacks. These are implemented as events. To receive these
42+
events register an EventHandler that is specific to that component. For example to receive events from Gap, use
43+
`Gap::setEventHandler()` passing in your implementation that inherits from `Gap::EventHandler`. Your class will override
44+
the events (methods) you are interested in, the others will inherit the do-nothing implementations provided by the parent.
2845

29-
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.
46+
### Instancing a BLE device
3047

31-
## The BLEDevice class and header
48+
All BLE operations are executed on an instance of BLE accessible through a function in the header `ble/BLE.h`.
3249

33-
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:
34-
35-
```c TODO
50+
```c
3651
#include "ble/BLE.h"
3752

3853
BLE& mydevicename = BLE::Instance();
3954
```
4055

41-
The class's member functions can be divided by purpose:
56+
### BLE stacks
57+
58+
To build and application using BLE you will be using the Mbed OS BLE API and an implementation of the BLE stack
59+
appropriate for your board. The implementation is split into Host and Controller part. They can both run on the same
60+
chip or two separate ones. They will be both communicating through HCI (Host Controller Interface, a well defined
61+
protocol that is part of the Bluetooth specification). Read more about the HCI interface in Mbed OS
62+
[here](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/driver/doc/HCIAbstraction.md).
63+
64+
Currently, all implementation use the Cordio stack for the Host part. The Controller implementation may be either also
65+
Cordio or any other vendor supplier one. Each board will have a driver that implements the communication channel
66+
between the Host and its implementation of the controller. To add support for a new board please refer to the
67+
[BLE porting guide](https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/include/ble/driver/doc/PortingGuide.md).
4268

43-
1. Basic BLE operations, such as initializing the controller.
69+
## Debugging
4470

45-
1. Accessor to Bluetooth Modules that manage GAP, GATT or the security.
71+
To learn about debugging with mbed go to:
4672

47-
## Usage
73+
[Debugging Mbed OS](../debug-test/index.html)
4874

49-
1. Set up advertising and connection modes.
50-
1. Assign UUIDs to the service and its characteristic.
51-
1. Create an input characteristic.
52-
1. Construct a service class and add it to the BLE stack.
53-
1. Push notifications when the characteristic's value changes.
75+
However, keep in mind when trying to debug connectivity issues that if more than one device is involved it might
76+
not be possible to stop your target without the communication breaking down. A less invasive way to help you understand
77+
what is happening might be to use tracing.
5478

5579
## Tracing
5680

5781
To debug issues (or to understand what the stack is doing) it may be helpful to enable tracing.
5882

59-
Traces can be turned on by overriding configuration options in you mbed_app.json:
83+
To enable traces override configuration options in you mbed_app.json:
6084

6185
```
6286
"target_overrides": {
6387
"*": {
6488
"mbed-trace.enable": true,
6589
"mbed-trace.max-level": "TRACE_LEVEL_DEBUG",
66-
"cordio.trace-hci-packets": true,
67-
"cordio.trace-cordio-wsf-traces": true,
90+
"cordio.trace-hci-packets": false,
91+
"cordio.trace-cordio-wsf-traces": false,
6892
"ble.trace-human-readable-enums": true
6993
}
7094
}
7195
```
7296

73-
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).
97+
Compile your application with `--profile debug`. Please note that with all options enabled your application may become
98+
too big - disable some options or lower the `mbed-trace.max-level`. Detailed documentation is available in the tracing
99+
[README.md](https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed-trace/README.md).
74100

75101
All BLE modules contain tracing, each of the modules prefixed with a unique tag:
76102
- `BLE ` - general BLE traces
@@ -86,11 +112,16 @@ All BLE modules contain tracing, each of the modules prefixed with a unique tag:
86112

87113
Any contributions to BLE should include appropriate tracing code.
88114

89-
## BLE class reference
115+
## BLE examples
90116

91-
[![View code](https://www.mbed.com/embed/?type=library)](https://os.mbed.com/docs/mbed-os/development/mbed-os-api-doxy/classble_1_1_b_l_e.html)
117+
We have placed all of our BLE examples in a single GitHub repository:
118+
- [GitHub repository](https://github.com/ARMmbed/mbed-os-example-ble)
92119

93-
## Related content
120+
Use the release version matching the mbed-os version you plan to use.
94121

95-
- Mbed Enabled [targets and components](https://os.mbed.com/platforms/?mbed-enabled=15&connectivity=3) that support BLE.
96-
- [BLE example on GitHub](https://github.com/ARMmbed/mbed-os-example-ble/).
122+
Development happens on the `development` branch. If you report an issue or open a PR, please check the version on the
123+
`development` branch and target it for any proposed changes.
124+
125+
## BLE class reference
126+
127+
[![View code](https://www.mbed.com/embed/?type=library)](https://os.mbed.com/docs/mbed-os/development/mbed-os-api-doxy/classble_1_1_b_l_e.html)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# BLE Services
2+
3+
Mbed OS BLE implementation isn't bundled with any BLE services. Services are in an external repository. Please go to:
4+
- [ble-services](https://github.com/ARMmbed/mbed-os-experimental-ble-services)
5+
6+
This is a community led effort to provide implementations of services both from the official BLE spec and user defined
7+
ones. It contains libraries which you can import into your project to use the services. Please refer to documentation
8+
inside the repository:
9+
- [README.md](https://github.com/ARMmbed/mbed-os-experimental-ble-services/blob/main/README.md)

docs/api/connectivity/bluetooth/BatteryService.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/api/connectivity/bluetooth/EnvironmentalService.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

docs/api/connectivity/bluetooth/Gap.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# GAP
22

3-
<span class="notes">**Note:** Some functions, variables or types have been deprecated. Please see the class reference linked below for details.</span>
4-
53
The Generic Access Profile is the layer of the stack that handles connectivity tasks. This includes link establishment and termination, advertising and scanning.
64

75
Devices with data to publish can use GAP to advertise. They can include the data in the advertisement itself, inside the scan response, or leave a peer device to query it after the connection has been established.

docs/api/connectivity/bluetooth/GattClient.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# GattClient
22

3-
<span class="notes">**Note:** Some functions, variables or types have been deprecated. Please see the class reference linked below for details.</span>
4-
53
You can use Generic Attribute Profile (GATT) to discover services, characteristics and descriptors and to perform operations on them. The interaction happens between two peers, one of which is the client (which initiates interactions) and the other is the server (which responds). You can use Attribute Protocol (ATT) to implement this interaction. `GattClient` defines procedures required for interacting with a remote `GattServer`.
64

75
## Discovery procedures

docs/api/connectivity/bluetooth/GattServer.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# GattServer
22

3-
<span class="notes">**Note:** Some functions, variables or types have been deprecated. Please see the class reference linked below for details.</span>
4-
53
You can use Generic Attribute Profile (GATT) to discover services, characteristics and descriptors and to perform operations on them. The interaction happens between two peers, one of which is the client (which initiates interactions) and the other is the server (which responds). You can use Attribute Protocol (ATT) to implement this interaction.
64

75
`GattServer` is a collection of GattServices. These services contain characteristics that a `GattClient` on the peer connected to the device may read or write. These characteristics may also emit updates to subscribed clients when their values change.
@@ -24,7 +22,9 @@ The Attribute Protocol Maximum Transmission Unit (`ATT_MTU`) is the maximum size
2422

2523
## Events
2624

27-
You can register several event handlers with the GattServer that it will call to notify you of client (remote application connected to the server) and server activities:
25+
You can register your implementation of `GattServer::EventHandler` with the GattServer using
26+
`GattServer::setEventHandler()`. It will call your event handler methods to notify you of client (remote application
27+
connected to the server) and server activity:
2828

2929
- `onDataSent`: Register an event handler with the GattServer that it will call to notify you when it sends a characteristic value update to a client.
3030
- `onDataWriten`: Register an event handler with the GattServer that it will call to notify you when a client has written an attribute of the server.

docs/api/connectivity/bluetooth/HeartRateService.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/api/connectivity/bluetooth/ble_tutorial.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)