xref: /aosp_15_r20/external/pigweed/pw_bluetooth_profiles/docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_bluetooth_profiles:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker=====================
4*61c4878aSAndroid Build Coastguard Workerpw_bluetooth_profiles
5*61c4878aSAndroid Build Coastguard Worker=====================
6*61c4878aSAndroid Build Coastguard Worker.. pigweed-module::
7*61c4878aSAndroid Build Coastguard Worker   :name: pw_bluetooth_profiles
8*61c4878aSAndroid Build Coastguard Worker
9*61c4878aSAndroid Build Coastguard Worker.. attention::
10*61c4878aSAndroid Build Coastguard Worker
11*61c4878aSAndroid Build Coastguard Worker   :bdg-ref-primary-line:`module-pw_bluetooth_profiles` is under construction,
12*61c4878aSAndroid Build Coastguard Worker   depends on the experimental :bdg-ref-primary-line:`module-pw_bluetooth`
13*61c4878aSAndroid Build Coastguard Worker   module and may see significant breaking API changes.
14*61c4878aSAndroid Build Coastguard Worker
15*61c4878aSAndroid Build Coastguard WorkerThe ``pw_bluetooth_profiles`` module provides a collection of implementations
16*61c4878aSAndroid Build Coastguard Workerfor basic Bluetooth profiles built on top of the ``pw_bluetooth`` module API.
17*61c4878aSAndroid Build Coastguard WorkerThese profiles are independent from each other
18*61c4878aSAndroid Build Coastguard Worker
19*61c4878aSAndroid Build Coastguard Worker--------------------------
20*61c4878aSAndroid Build Coastguard WorkerDevice Information Service
21*61c4878aSAndroid Build Coastguard Worker--------------------------
22*61c4878aSAndroid Build Coastguard WorkerThe ``device_info_service`` target implements the Device Information Service
23*61c4878aSAndroid Build Coastguard Worker(DIS) as defined in the specification version 1.1. It exposes up to nine
24*61c4878aSAndroid Build Coastguard Workerdifferent basic properties of the device such as the model, manufacturer or
25*61c4878aSAndroid Build Coastguard Workerserial number, all of which are optional. This module implements the GATT
26*61c4878aSAndroid Build Coastguard Workerserver-side service (``bluetooth::gatt::LocalServiceDelegate``) with the
27*61c4878aSAndroid Build Coastguard Workerfollowing limitations:
28*61c4878aSAndroid Build Coastguard Worker
29*61c4878aSAndroid Build Coastguard Worker- The subset of properties exposed and their values are constant throughout the
30*61c4878aSAndroid Build Coastguard Worker  life of the service.
31*61c4878aSAndroid Build Coastguard Worker- The subset of properties is defined at compile time, but the values may be
32*61c4878aSAndroid Build Coastguard Worker  defined at runtime before service initialization. For example, the serial
33*61c4878aSAndroid Build Coastguard Worker  number property might be different for different devices running the same
34*61c4878aSAndroid Build Coastguard Worker  code.
35*61c4878aSAndroid Build Coastguard Worker- All property values must be available in memory while the service is
36*61c4878aSAndroid Build Coastguard Worker  published. Rather than using a callback mechanism to let the user produce the
37*61c4878aSAndroid Build Coastguard Worker  property value at run-time, this module expects those values to be readily
38*61c4878aSAndroid Build Coastguard Worker  available when initialized, but they can be stored in read-only memory.
39*61c4878aSAndroid Build Coastguard Worker
40*61c4878aSAndroid Build Coastguard WorkerUsage
41*61c4878aSAndroid Build Coastguard Worker-----
42*61c4878aSAndroid Build Coastguard WorkerThe main intended usage of the service consists on creating and publishing the
43*61c4878aSAndroid Build Coastguard Workerservice, leaving it published forever referencing the values passed on
44*61c4878aSAndroid Build Coastguard Workerinitialization.
45*61c4878aSAndroid Build Coastguard Worker
46*61c4878aSAndroid Build Coastguard WorkerThe subset of properties exposed is a template parameter bit field
47*61c4878aSAndroid Build Coastguard Worker(``DeviceInfo::Field``) and can't be changed at run-time. The ``pw::span``
48*61c4878aSAndroid Build Coastguard Workervalues referenced in the ``DeviceInfo`` struct must remain available after
49*61c4878aSAndroid Build Coastguard Workerinitialization to avoid copying them to RAM in the service, but the
50*61c4878aSAndroid Build Coastguard Worker``DeviceInfo`` struct itself can be destroyed after initialization.
51*61c4878aSAndroid Build Coastguard Worker
52*61c4878aSAndroid Build Coastguard WorkerExample code:
53*61c4878aSAndroid Build Coastguard Worker
54*61c4878aSAndroid Build Coastguard Worker.. code-block:: cpp
55*61c4878aSAndroid Build Coastguard Worker
56*61c4878aSAndroid Build Coastguard Worker   using pw::bluetooth_profiles::DeviceInfo;
57*61c4878aSAndroid Build Coastguard Worker   using pw::bluetooth_profiles::DeviceInfoService;
58*61c4878aSAndroid Build Coastguard Worker
59*61c4878aSAndroid Build Coastguard Worker   // Global serial number for the device, initialized elsewhere.
60*61c4878aSAndroid Build Coastguard Worker   pw::InlineString serial_number(...);
61*61c4878aSAndroid Build Coastguard Worker
62*61c4878aSAndroid Build Coastguard Worker   // Select which fields to expose at compile-time with a constexpr template
63*61c4878aSAndroid Build Coastguard Worker   // parameter.
64*61c4878aSAndroid Build Coastguard Worker   constexpr auto kUsedFields = DeviceInfo::Field::kModelNumber |
65*61c4878aSAndroid Build Coastguard Worker                                DeviceInfo::Field::kSerialNumber |
66*61c4878aSAndroid Build Coastguard Worker                                DeviceInfo::Field::kSoftwareRevision;
67*61c4878aSAndroid Build Coastguard Worker
68*61c4878aSAndroid Build Coastguard Worker   // Create a DeviceInfo with the values. Values are referenced from the
69*61c4878aSAndroid Build Coastguard Worker   // service, not copied, so they must remain available while the service is
70*61c4878aSAndroid Build Coastguard Worker   // published.
71*61c4878aSAndroid Build Coastguard Worker   DeviceInfo device_info = {};
72*61c4878aSAndroid Build Coastguard Worker   device_info.model_number = pw::as_bytes(pw::span{"My Model"sv});
73*61c4878aSAndroid Build Coastguard Worker   device_info.software_revision = pw::as_bytes(pw::span{REVISION_MACRO});
74*61c4878aSAndroid Build Coastguard Worker   device_info.serial_number = pw::as_bytes(
75*61c4878aSAndroid Build Coastguard Worker       pw::span(serial_number.data(), serial_number.size()));
76*61c4878aSAndroid Build Coastguard Worker
77*61c4878aSAndroid Build Coastguard Worker   DeviceInfoService<kUsedFields, pw::bluetooth::gatt::Handle{123}>
78*61c4878aSAndroid Build Coastguard Worker       device_info_service{device_info};
79*61c4878aSAndroid Build Coastguard Worker   device_info_service.PublishService(...);
80