Skip to content
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

Fast Pair callback API improvements #19737

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/bluetooth/services/fast_pair/fast_pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ int bt_fast_pair_battery_set(enum bt_fast_pair_battery_comp battery_comp,
* This function can only be called before enabling Fast Pair with the @ref bt_fast_pair_enable
* API.
*
* This function must be called in the cooperative thread context.
* This function must be called in the cooperative thread context or in the system initialization
* context (@ref SYS_INIT macro).
*
* @param cb Callback struct.
*
Expand Down
20 changes: 17 additions & 3 deletions include/bluetooth/services/fast_pair/fmdn.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention at the top of the file (line 17) that some functions can be called from sys_init. We have there a comment that It is required to use the Fast Pair FMDN API in the cooperative thread context (for example, system workqueue thread)., which is no longer true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could e.g. state that * It is required to use most of the the Fast Pair FMDN APIs in the cooperative thread context? (to avoid going into details)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improved this inconsistency

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
* @defgroup bt_fast_pair_fmdn Fast Pair FMDN API
* @brief Fast Pair FMDN API
*
* It is required to use the Fast Pair FMDN API in the cooperative thread context
* (for example, system workqueue thread). Following this requirement guarantees
* a proper synchronization between the user operations and the module operations.
* It is required to use the Fast Pair FMDN API in the cooperative thread context.
* API function exceptions that do not follow this rule mention alternative requirements
* explicitly in their API documentation. Following the cooperative thread context
* requirement guarantees proper synchronization between the user operations and the
* module operations.
*
* @{
*/
Expand Down Expand Up @@ -234,6 +236,9 @@ struct bt_fast_pair_fmdn_ring_cb {
* You can call this function only in the disabled state of the FMDN module
* (see @ref bt_fast_pair_is_ready function).
*
* This function must be called in the cooperative thread context or in the system initialization
* context (@ref SYS_INIT macro).
*
* @param cb Ringing callback structure.
*
* @return 0 if the operation was successful. Otherwise, a (negative) error code is returned.
Expand Down Expand Up @@ -355,6 +360,9 @@ struct bt_fast_pair_fmdn_motion_detector_cb {
* You can call this function only in the disabled state of the FMDN module
* (see @ref bt_fast_pair_is_ready function).
*
* This function must be called in the cooperative thread context or in the system initialization
* context (@ref SYS_INIT macro).
*
* @param cb Motion detector callback structure.
*
* @return 0 if the operation was successful. Otherwise, a (negative) error code is returned.
Expand Down Expand Up @@ -529,6 +537,9 @@ struct bt_fast_pair_fmdn_info_cb {
* This API for callback registration is optional and does not have to be used. You can
* register multiple instances of information callbacks.
*
* This function must be called in the cooperative thread context or in the system initialization
* context (@ref SYS_INIT macro).
*
* @param cb Information callback structure.
*
* @return 0 if the operation was successful. Otherwise, a (negative) error code is returned.
Expand Down Expand Up @@ -565,6 +576,9 @@ struct bt_fast_pair_fmdn_read_mode_cb {
* You can call this function only in the disabled state of the FMDN module
* (see @ref bt_fast_pair_is_ready function).
*
* This function must be called in the cooperative thread context or in the system initialization
* context (@ref SYS_INIT macro).
*
* @param cb Read mode callback structure.
*
* @return 0 if the operation was successful. Otherwise, a (negative) error code is returned.
Expand Down
5 changes: 3 additions & 2 deletions subsys/bluetooth/services/fast_pair/fp_gatt_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,9 @@ static void fp_info_cb_account_key_written_notify(struct bt_conn *conn)

int bt_fast_pair_info_cb_register(struct bt_fast_pair_info_cb *cb)
{
/* It is assumed that this function executes in the cooperative thread context. */
__ASSERT_NO_MSG(!k_is_preempt_thread());
/* It is assumed that this function executes in the cooperative thread context
* or in the system initialization context (SYS_INIT macro).
*/
__ASSERT_NO_MSG(!k_is_in_isr());

if (bt_fast_pair_is_ready()) {
Expand Down
Loading