Bluetooth Module for C++ #55433
Labels
area: Bluetooth Host
Bluetooth Host (excluding BR/EDR)
area: Bluetooth
RFC
Request For Comments: want input from the community
Introduction
Greetings Zephyr Team. This RFC proposes a BLE module for easier integration of Bluetooth GATT services and characteristics. I would like to hear your feedback and see if you would accept a proposal for C++ development.
Problem description
Currently adding GATT services and characteristics can be defined at compile time by using zephyr macros. This is however not type safe and straight forward. There are too many hidden details that make it cumbersome. Some examples:
Proposed change
A CPP zephyr module that initializes correctly the bt_gatt_attr struct for defining services and characteristics. The module would contain compile time declaration through templates (C++20) and dynamic declaration through normal C++ classes.
Detailed RFC
There is a need to either document how to initialize correctly the bt_gatt_attr struct. Unless you read the source code end users can not know how to define GATT attributes correctly. See for example this user which did not know how to use the API service define:
#20707
This proposal allows end users to use a CPP module which can be used at compile time or run time to define GATT attributes. It abstracts the complexity that is required to know how to declare GATT attributes. Currently the complexity is abstracted through Zephyr C Macros which are not type safe and are not thoroughly documented.
Proposed change (Detailed)
Templated class for C++ compile time definition of gatt attributes. The generated gatt attributes can then be used with the API bt_gatt_service_register. I attempted to declare the attributes directly in the linker section bt_gatt_service_static but my gcc compiler keeps mangling the c++ templated class instantiated attributes so I opted out of this option.
For run time, i propose a class that holds the attributes for services and characteristics. The end user can then can add characteristics to a service over a specified API for this module.
Dependencies
C++20 - I think that the latest standardization efforts for C++ allow better type safe code and optimizations at compile time.
Final notes
I am already developing this module and when I am back at the office I can link the current implementation and how this would look like.
Its either necessary to document how attributes are initialized or a module that end users can utilize to develop GATT attributes for the zephyr API.
I opt for a module that is typesafe and straightforward to use without the obfuscation that the zephyr macros have.
Alternatives
Document thoroughly how to define and initialize GATT services and characteristics without the Zephyr C Macros.
The text was updated successfully, but these errors were encountered: