2015-06-11 16:22:15 +08:00
|
|
|
.. _bluetooth:
|
|
|
|
|
|
|
|
Bluetooth Implementation
|
|
|
|
########################
|
|
|
|
|
|
|
|
Initialization
|
|
|
|
**************
|
|
|
|
|
2015-10-14 22:40:41 +08:00
|
|
|
Initialize the Bluetooth subsystem using :c:func:`bt_init()`. Caller shall
|
|
|
|
be either task or a fiber. Caller must ensure that function succeeds by
|
|
|
|
checking return code for errors.
|
|
|
|
|
|
|
|
APIs
|
|
|
|
****
|
|
|
|
|
|
|
|
The following Bluetooth APIs are provided:
|
|
|
|
|
2015-10-16 18:38:05 +08:00
|
|
|
:c:func:`bt_enable()`
|
|
|
|
Enables the Bluetooth subsystem.
|
2015-10-14 22:40:41 +08:00
|
|
|
|
2015-12-03 16:19:38 +08:00
|
|
|
:c:func:`bt_le_adv_start()`
|
2015-10-14 22:40:41 +08:00
|
|
|
Sets up advertisement, scans for data, and starts advertising.
|
|
|
|
|
|
|
|
.. todo:: Describe all API
|
2015-06-11 16:22:15 +08:00
|
|
|
|
|
|
|
Bluetooth Application Example
|
|
|
|
*****************************
|
|
|
|
|
|
|
|
A simple Bluetooth beacon application is shown below. The application
|
|
|
|
initializes a Bluetooth Subsystem and enables non-connectable advertising.
|
|
|
|
It acts as a Bluetooth Low Energy broadcaster.
|
|
|
|
|
2015-08-14 17:34:03 +08:00
|
|
|
.. literalinclude:: ../../../samples/bluetooth/beacon/src/main.c
|
2015-06-11 16:22:15 +08:00
|
|
|
:language: c
|
2015-10-16 17:23:44 +08:00
|
|
|
:lines: 19-
|
2015-06-11 16:22:15 +08:00
|
|
|
:linenos:
|
|
|
|
|
|
|
|
Testing with QEMU
|
|
|
|
*****************
|
|
|
|
|
|
|
|
A Bluetooth application might be tested with QEMU. In order to do so,
|
|
|
|
a Bluetooth controller needs to be connected to the emulator.
|
|
|
|
|
|
|
|
Using Host System Bluetooth Controller in QEMU
|
|
|
|
==============================================
|
|
|
|
|
|
|
|
The host system's Bluetooth controller is connected to the second QEMU
|
2015-08-19 13:41:58 +08:00
|
|
|
serial line using a UNIX socket. This socket employs the QEMU option
|
|
|
|
:literal:`-serial unix:/tmp/bt-server-bredr`. This option is already
|
|
|
|
added to QEMU through :makevar:`QEMU_EXTRA_FLAGS` in the Makefile.
|
2015-06-11 16:22:15 +08:00
|
|
|
|
|
|
|
On the Host side, BlueZ allows to "connect" Bluetooth controller through
|
|
|
|
a so-called user channel.
|
|
|
|
|
|
|
|
#. Use the btproxy tool to open the listening UNIX socket, type:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
$ sudo tools/btproxy -u
|
|
|
|
Listening on /tmp/bt-server-bredr
|
|
|
|
|
|
|
|
.. note:: Ensure that the Bluetooth controller is down before using the
|
|
|
|
btproxy command.
|
|
|
|
|
|
|
|
|
2015-08-14 17:29:33 +08:00
|
|
|
#. To run Bluetooth application in the QEMU, go to application folder and type:
|
2015-06-11 16:22:15 +08:00
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
$ make qemu
|
|
|
|
|
2015-08-14 17:29:33 +08:00
|
|
|
.. note:: Bluetooth sample applications are located in
|
|
|
|
:literal:`samples/bluetooth` folder.
|
|
|
|
|
2015-06-11 16:22:15 +08:00
|
|
|
Running QEMU now results in a connection with the second serial line to
|
|
|
|
:literal:`bt-server-bredr` UNIX socket.
|
|
|
|
Now, an application can use the Bluetooth device.
|