diff --git a/include/zephyr/bluetooth/audio/vcp.h b/include/zephyr/bluetooth/audio/vcp.h index 60d8ae7b181..9b39c68b632 100644 --- a/include/zephyr/bluetooth/audio/vcp.h +++ b/include/zephyr/bluetooth/audio/vcp.h @@ -64,7 +64,7 @@ struct bt_vcp_vol_rend_register_param { struct bt_aics_register_param aics_param[BT_VCP_VOL_REND_AICS_CNT]; /** Volume Control Service callback structure. */ - struct bt_vcp_cb *cb; + struct bt_vcp_vol_rend_cb *cb; }; /** @@ -117,82 +117,36 @@ int bt_vcp_vol_rend_included_get(struct bt_vcp *vcp, int bt_vcp_vol_rend_register(struct bt_vcp_vol_rend_register_param *param, struct bt_vcp **vcp); -/** - * @brief Callback function for bt_vcp_vol_ctlr_discover. - * - * This callback is only used for the client. - * - * @param vcp Volume Control Service instance pointer. - * @param err Error value. 0 on success, GATT error on positive value - * or errno on negative value. - * @param vocs_count Number of Volume Offset Control Service instances - * on peer device. - * @param aics_count Number of Audio Input Control Service instances on - * peer device. - */ -typedef void (*bt_vcp_vol_ctlr_discover_cb)(struct bt_vcp *vcp, int err, - uint8_t vocs_count, uint8_t aics_count); +struct bt_vcp_vol_rend_cb { + /** + * @brief Callback function for Volume Control Service volume state. + * + * Called when the value is locally read with + * bt_vcp_vol_rend_get_state(), or if the state is changed by either + * the Volume Renderer or a remote Volume Controller. + * + * @param vcp Volume Control Service instance pointer. + * @param err Error value. 0 on success, GATT error on positive value + * or errno on negative value. + * @param volume The volume of the Volume Control Service server. + * @param mute The mute setting of the Volume Control Service server. + */ + void (*state)(struct bt_vcp *vcp, int err, uint8_t volume, + uint8_t mute); -/** - * @brief Callback function for Volume Control Service volume state. - * - * Called when the value is locally read as the server. - * Called when the value is remotely read as the client. - * Called if the value is changed by either the server or client. - * - * @param vcp Volume Control Service instance pointer. - * @param err Error value. 0 on success, GATT error on positive value - * or errno on negative value. - * @param volume The volume of the Volume Control Service server. - * @param mute The mute setting of the Volume Control Service server. - */ -typedef void (*bt_vcp_state_cb)(struct bt_vcp *vcp, int err, uint8_t volume, - uint8_t mute); - -/** - * @brief Callback function for Volume Control Service flags. - * - * Called when the value is locally read as the server. - * Called when the value is remotely read as the client. - * Called if the value is changed by either the server or client. - * - * @param vcp Volume Control Service instance pointer. - * @param err Error value. 0 on success, GATT error on positive value - * or errno on negative value. - * @param flags The flags of the Volume Control Service server. - */ -typedef void (*bt_vcp_flags_cb)(struct bt_vcp *vcp, int err, uint8_t flags); - -/** - * @brief Callback function for writes. - * - * This callback is only used for the client. - * - * @param vcp Volume Control Service instance pointer. - * @param err Error value. 0 on success, GATT error on fail. - */ -typedef void (*bt_vcp_write_cb)(struct bt_vcp *vcp, int err); - -struct bt_vcp_cb { - /* Volume Control Service */ - bt_vcp_state_cb state; - bt_vcp_flags_cb flags; -#if defined(CONFIG_BT_VCP_VOL_CTLR) - bt_vcp_vol_ctlr_discover_cb discover; - bt_vcp_write_cb vol_down; - bt_vcp_write_cb vol_up; - bt_vcp_write_cb mute; - bt_vcp_write_cb unmute; - bt_vcp_write_cb vol_down_unmute; - bt_vcp_write_cb vol_up_unmute; - bt_vcp_write_cb vol_set; - - /* Volume Offset Control Service */ - struct bt_vocs_cb vocs_cb; - - /* Audio Input Control Service */ - struct bt_aics_cb aics_cb; -#endif /* CONFIG_BT_VCP_VOL_CTLR */ + /** + * @brief Callback function for Volume Control Service flags. + * + * Called when the value is locally read as the server. + * Called when the value is remotely read as the client. + * Called if the value is changed by either the server or client. + * + * @param vcp Volume Control Service instance pointer. + * @param err Error value. 0 on success, GATT error on positive value + * or errno on negative value. + * @param flags The flags of the Volume Control Service server. + */ + void (*flags)(struct bt_vcp *vcp, int err, uint8_t flags); }; /** @@ -291,6 +245,140 @@ int bt_vcp_vol_rend_unmute(struct bt_vcp *vcp); */ int bt_vcp_vol_rend_mute(struct bt_vcp *vcp); +struct bt_vcp_vol_ctlr_cb { + /** + * @brief Callback function for Volume Control Profile volume state. + * + * Called when the value is remotely read as the Volume Controller. + * Called if the value is changed by either the Volume Renderer or + * Volume Controller, and notified to the to Volume Controller. + * + * @param vcp Volume Control Profile instance pointer. + * @param err Error value. 0 on success, GATT error on positive + * value or errno on negative value. + * @param volume The volume of the Volume Renderer. + * @param mute The mute setting of the Volume Renderer. + */ + void (*state)(struct bt_vcp *vcp, int err, uint8_t volume, + uint8_t mute); + + /** + * @brief Callback function for Volume Control Profile volume flags. + * + * Called when the value is remotely read as the Volume Controller. + * Called if the value is changed by the Volume Renderer. + * + * A non-zero value indicates the the volume has been changed on the + * Volume Renderer since it was booted. + * + * @param vcp Volume Control Profile instance pointer. + * @param err Error value. 0 on success, GATT error on positive + * value or errno on negative value. + * @param flags The flags of the Volume Renderer. + */ + + void (*flags)(struct bt_vcp *vcp, int err, uint8_t flags); + + /** + * @brief Callback function for bt_vcp_vol_ctlr_discover(). + * + * This callback is called once the discovery procedure is completed. + * + * @param vcp Volume Control Profile instance pointer. + * @param err Error value. 0 on success, GATT error on positive + * value or errno on negative value. + * @param vocs_count Number of Volume Offset Control Service instances + * on the remote Volume Renderer. + * @param aics_count Number of Audio Input Control Service instances + * the remote Volume Renderer. + */ + void (*discover)(struct bt_vcp *vcp, int err, uint8_t vocs_count, + uint8_t aics_count); + + /** + * @brief Callback function for bt_vcp_vol_ctlr_vol_down(). + * + * Called when the volume down procedure is completed. + * + * @param vcp Volume Control Profile instance pointer. + * @param err Error value. 0 on success, GATT error on positive + * value or errno on negative value. + */ + void (*vol_down)(struct bt_vcp *vcp, int err); + + /** + * @brief Callback function for bt_vcp_vol_ctlr_vol_up(). + * + * Called when the volume up procedure is completed. + * + * @param vcp Volume Control Profile instance pointer. + * @param err Error value. 0 on success, GATT error on positive + * value or errno on negative value. + */ + void (*vol_up)(struct bt_vcp *vcp, int err); + + /** + * @brief Callback function for bt_vcp_vol_ctlr_mute(). + * + * Called when the mute procedure is completed. + * + * @param vcp Volume Control Profile instance pointer. + * @param err Error value. 0 on success, GATT error on positive + * value or errno on negative value. + */ + void (*mute)(struct bt_vcp *vcp, int err); + + /** + * @brief Callback function for bt_vcp_vol_ctlr_unmute(). + * + * Called when the unmute procedure is completed. + * + * @param vcp Volume Control Profile instance pointer. + * @param err Error value. 0 on success, GATT error on positive + * value or errno on negative value. + */ + void (*unmute)(struct bt_vcp *vcp, int err); + + /** + * @brief Callback function for bt_vcp_vol_ctlr_vol_down_unmute(). + * + * Called when the volume down and unmute procedure is completed. + * + * @param vcp Volume Control Profile instance pointer. + * @param err Error value. 0 on success, GATT error on positive + * value or errno on negative value. + */ + void (*vol_down_unmute)(struct bt_vcp *vcp, int err); + + /** + * @brief Callback function for bt_vcp_vol_ctlr_vol_up_unmute(). + * + * Called when the volume up and unmute procedure is completed. + * + * @param vcp Volume Control Profile instance pointer. + * @param err Error value. 0 on success, GATT error on positive + * value or errno on negative value. + */ + void (*vol_up_unmute)(struct bt_vcp *vcp, int err); + + /** + * @brief Callback function for bt_vcp_vol_ctlr_vol_set(). + * + * Called when the set absolute volume procedure is completed. + * + * @param vcp Volume Control Profile instance pointer. + * @param err Error value. 0 on success, GATT error on positive + * value or errno on negative value. + */ + void (*vol_set)(struct bt_vcp *vcp, int err); + + /* Volume Offset Control Service callbacks */ + struct bt_vocs_cb vocs_cb; + + /* Audio Input Control Service callbacks */ + struct bt_aics_cb aics_cb; +}; + /** * @brief Registers the callbacks used by the Volume Controller. * @@ -298,7 +386,7 @@ int bt_vcp_vol_rend_mute(struct bt_vcp *vcp); * * @return 0 if success, errno on failure. */ -int bt_vcp_vol_ctlr_cb_register(struct bt_vcp_cb *cb); +int bt_vcp_vol_ctlr_cb_register(struct bt_vcp_vol_ctlr_cb *cb); /** * @brief Discover Volume Control Service and included services. @@ -306,7 +394,7 @@ int bt_vcp_vol_ctlr_cb_register(struct bt_vcp_cb *cb); * This will start a GATT discovery and setup handles and subscriptions. * This shall be called once before any other actions can be * executed for the peer device, and the - * @ref bt_vcp_vol_ctlr_discover_cb callback will notify when it is possible to + * @ref bt_vcp_vol_ctlr_cb.discover callback will notify when it is possible to * start remote operations. * * This shall only be done as the client, diff --git a/samples/bluetooth/hap_ha/src/vcp_vol_renderer.c b/samples/bluetooth/hap_ha/src/vcp_vol_renderer.c index dea9369ef78..5fec2dda235 100644 --- a/samples/bluetooth/hap_ha/src/vcp_vol_renderer.c +++ b/samples/bluetooth/hap_ha/src/vcp_vol_renderer.c @@ -111,7 +111,7 @@ static void vocs_description_cb(struct bt_vocs *inst, int err, char *description } } -static struct bt_vcp_cb vcs_cbs = { +static struct bt_vcp_vol_rend_cb vcp_cbs = { .state = vcs_state_cb, .flags = vcs_flags_cb, }; @@ -163,7 +163,7 @@ int vcp_vol_renderer_init(void) vcp_register_param.step = 1; vcp_register_param.mute = BT_VCP_STATE_UNMUTED; vcp_register_param.volume = 100; - vcp_register_param.cb = &vcs_cbs; + vcp_register_param.cb = &vcp_cbs; err = bt_vcp_vol_rend_register(&vcp_register_param, &vcp); if (err) { diff --git a/subsys/bluetooth/audio/vcp_internal.h b/subsys/bluetooth/audio/vcp_internal.h index abbda3c30be..070190d0a60 100644 --- a/subsys/bluetooth/audio/vcp_internal.h +++ b/subsys/bluetooth/audio/vcp_internal.h @@ -71,7 +71,7 @@ struct bt_vcp_vol_ctlr { struct bt_vcp_server { struct vcs_state state; uint8_t flags; - struct bt_vcp_cb *cb; + struct bt_vcp_vol_rend_cb *cb; uint8_t volume_step; struct bt_gatt_service *service_p; diff --git a/subsys/bluetooth/audio/vcp_vol_ctlr.c b/subsys/bluetooth/audio/vcp_vol_ctlr.c index ac570deaccf..1f28d652816 100644 --- a/subsys/bluetooth/audio/vcp_vol_ctlr.c +++ b/subsys/bluetooth/audio/vcp_vol_ctlr.c @@ -29,7 +29,7 @@ LOG_MODULE_REGISTER(bt_vcp_vol_ctlr, CONFIG_BT_VCP_VOL_CTLR_LOG_LEVEL); #include "common/bt_str.h" /* Callback functions */ -static struct bt_vcp_cb *vcp_vol_ctlr_cb; +static struct bt_vcp_vol_ctlr_cb *vcp_vol_ctlr_cb; static struct bt_vcp vcp_insts[CONFIG_BT_MAX_CONN]; static int vcp_vol_ctlr_common_vcs_cp(struct bt_vcp *vcp, uint8_t opcode); @@ -756,7 +756,7 @@ int bt_vcp_vol_ctlr_discover(struct bt_conn *conn, struct bt_vcp **vcp) return err; } -int bt_vcp_vol_ctlr_cb_register(struct bt_vcp_cb *cb) +int bt_vcp_vol_ctlr_cb_register(struct bt_vcp_vol_ctlr_cb *cb) { #if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS) struct bt_vocs_cb *vocs_cb = NULL; diff --git a/subsys/bluetooth/shell/vcp_vol_ctlr.c b/subsys/bluetooth/shell/vcp_vol_ctlr.c index 6a20d49efed..140a5fed118 100644 --- a/subsys/bluetooth/shell/vcp_vol_ctlr.c +++ b/subsys/bluetooth/shell/vcp_vol_ctlr.c @@ -284,7 +284,7 @@ static void vcs_vocs_description_cb(struct bt_vocs *inst, int err, } #endif /* CONFIG_BT_VCP_VOL_CTLR_MAX_VOCS_INST > 0 */ -static struct bt_vcp_cb vcs_cbs = { +static struct bt_vcp_vol_ctlr_cb vcp_cbs = { .discover = vcs_discover_cb, .vol_down = vcs_vol_down_cb, .vol_up = vcs_vol_up_cb, @@ -331,7 +331,7 @@ static int cmd_vcp_vol_ctlr_discover(const struct shell *sh, size_t argc, ctx_shell = sh; } - result = bt_vcp_vol_ctlr_cb_register(&vcs_cbs); + result = bt_vcp_vol_ctlr_cb_register(&vcp_cbs); if (result != 0) { shell_print(sh, "CB register failed: %d", result); return result; diff --git a/subsys/bluetooth/shell/vcp_vol_rend.c b/subsys/bluetooth/shell/vcp_vol_rend.c index 376064bc656..0df466f6683 100644 --- a/subsys/bluetooth/shell/vcp_vol_rend.c +++ b/subsys/bluetooth/shell/vcp_vol_rend.c @@ -139,7 +139,7 @@ static void vocs_description_cb(struct bt_vocs *inst, int err, } } -static struct bt_vcp_cb vcp_vol_rend_cbs = { +static struct bt_vcp_vol_rend_cb vcp_vol_rend_cbs = { .state = vcp_vol_rend_state_cb, .flags = vcp_vol_rend_flags_cb, }; diff --git a/tests/bluetooth/bsim_bt/bsim_test_audio/src/vcp_vol_ctlr_test.c b/tests/bluetooth/bsim_bt/bsim_test_audio/src/vcp_vol_ctlr_test.c index 0b2c5547353..e08471ccd8c 100644 --- a/tests/bluetooth/bsim_bt/bsim_test_audio/src/vcp_vol_ctlr_test.c +++ b/tests/bluetooth/bsim_bt/bsim_test_audio/src/vcp_vol_ctlr_test.c @@ -225,7 +225,7 @@ static void vcs_write_cb(struct bt_vcp *vcp, int err) g_write_complete = true; } -static struct bt_vcp_cb vcs_cbs = { +static struct bt_vcp_vol_ctlr_cb vcp_cbs = { .discover = vcs_discover_cb, .vol_down = vcs_write_cb, .vol_up = vcs_write_cb, @@ -544,7 +544,7 @@ static void test_main(void) return; } - err = bt_vcp_vol_ctlr_cb_register(&vcs_cbs); + err = bt_vcp_vol_ctlr_cb_register(&vcp_cbs); if (err) { FAIL("CB register failed (err %d)\n", err); return; diff --git a/tests/bluetooth/bsim_bt/bsim_test_audio/src/vcp_vol_rend_test.c b/tests/bluetooth/bsim_bt/bsim_test_audio/src/vcp_vol_rend_test.c index 5c0270fb8ba..b45f2af13d5 100644 --- a/tests/bluetooth/bsim_bt/bsim_test_audio/src/vcp_vol_rend_test.c +++ b/tests/bluetooth/bsim_bt/bsim_test_audio/src/vcp_vol_rend_test.c @@ -167,7 +167,7 @@ static void aics_description_cb(struct bt_aics *inst, int err, g_cb = true; } -static struct bt_vcp_cb vcs_cb = { +static struct bt_vcp_vol_rend_cb vcs_cb = { .state = vcs_state_cb, .flags = vcs_flags_cb, };