Bluetooth: Audio: Split vol_ctlr and vol_rend callback structure

Split the `bt_vcp_cb` struct into separate structure for
the volume controller and the volume renderer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2022-10-10 12:59:00 +02:00 committed by Carles Cufí
commit c82af2885e
8 changed files with 177 additions and 89 deletions

View file

@ -64,7 +64,7 @@ struct bt_vcp_vol_rend_register_param {
struct bt_aics_register_param aics_param[BT_VCP_VOL_REND_AICS_CNT]; struct bt_aics_register_param aics_param[BT_VCP_VOL_REND_AICS_CNT];
/** Volume Control Service callback structure. */ /** 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, int bt_vcp_vol_rend_register(struct bt_vcp_vol_rend_register_param *param,
struct bt_vcp **vcp); struct bt_vcp **vcp);
/** struct bt_vcp_vol_rend_cb {
* @brief Callback function for bt_vcp_vol_ctlr_discover. /**
* * @brief Callback function for Volume Control Service volume state.
* This callback is only used for the client. *
* * Called when the value is locally read with
* @param vcp Volume Control Service instance pointer. * bt_vcp_vol_rend_get_state(), or if the state is changed by either
* @param err Error value. 0 on success, GATT error on positive value * the Volume Renderer or a remote Volume Controller.
* or errno on negative value. *
* @param vocs_count Number of Volume Offset Control Service instances * @param vcp Volume Control Service instance pointer.
* on peer device. * @param err Error value. 0 on success, GATT error on positive value
* @param aics_count Number of Audio Input Control Service instances on * or errno on negative value.
* peer device. * @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_vol_ctlr_discover_cb)(struct bt_vcp *vcp, int err, */
uint8_t vocs_count, uint8_t aics_count); void (*state)(struct bt_vcp *vcp, int err, uint8_t volume,
uint8_t mute);
/** /**
* @brief Callback function for Volume Control Service volume state. * @brief Callback function for Volume Control Service flags.
* *
* Called when the value is locally read as the server. * Called when the value is locally read as the server.
* Called when the value is remotely read as the client. * Called when the value is remotely read as the client.
* Called if the value is changed by either the server or client. * Called if the value is changed by either the server or client.
* *
* @param vcp Volume Control Service instance pointer. * @param vcp Volume Control Service instance pointer.
* @param err Error value. 0 on success, GATT error on positive value * @param err Error value. 0 on success, GATT error on positive value
* or errno on negative value. * or errno on negative value.
* @param volume The volume of the Volume Control Service server. * @param flags The flags of the Volume Control Service server.
* @param mute The mute setting of the Volume Control Service server. */
*/ void (*flags)(struct bt_vcp *vcp, int err, uint8_t flags);
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 */
}; };
/** /**
@ -291,6 +245,140 @@ int bt_vcp_vol_rend_unmute(struct bt_vcp *vcp);
*/ */
int bt_vcp_vol_rend_mute(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. * @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. * @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. * @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 will start a GATT discovery and setup handles and subscriptions.
* This shall be called once before any other actions can be * This shall be called once before any other actions can be
* executed for the peer device, and the * 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. * start remote operations.
* *
* This shall only be done as the client, * This shall only be done as the client,

View file

@ -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, .state = vcs_state_cb,
.flags = vcs_flags_cb, .flags = vcs_flags_cb,
}; };
@ -163,7 +163,7 @@ int vcp_vol_renderer_init(void)
vcp_register_param.step = 1; vcp_register_param.step = 1;
vcp_register_param.mute = BT_VCP_STATE_UNMUTED; vcp_register_param.mute = BT_VCP_STATE_UNMUTED;
vcp_register_param.volume = 100; 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); err = bt_vcp_vol_rend_register(&vcp_register_param, &vcp);
if (err) { if (err) {

View file

@ -71,7 +71,7 @@ struct bt_vcp_vol_ctlr {
struct bt_vcp_server { struct bt_vcp_server {
struct vcs_state state; struct vcs_state state;
uint8_t flags; uint8_t flags;
struct bt_vcp_cb *cb; struct bt_vcp_vol_rend_cb *cb;
uint8_t volume_step; uint8_t volume_step;
struct bt_gatt_service *service_p; struct bt_gatt_service *service_p;

View file

@ -29,7 +29,7 @@ LOG_MODULE_REGISTER(bt_vcp_vol_ctlr, CONFIG_BT_VCP_VOL_CTLR_LOG_LEVEL);
#include "common/bt_str.h" #include "common/bt_str.h"
/* Callback functions */ /* 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 struct bt_vcp vcp_insts[CONFIG_BT_MAX_CONN];
static int vcp_vol_ctlr_common_vcs_cp(struct bt_vcp *vcp, uint8_t opcode); 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; 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) #if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS)
struct bt_vocs_cb *vocs_cb = NULL; struct bt_vocs_cb *vocs_cb = NULL;

View file

@ -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 */ #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, .discover = vcs_discover_cb,
.vol_down = vcs_vol_down_cb, .vol_down = vcs_vol_down_cb,
.vol_up = vcs_vol_up_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; ctx_shell = sh;
} }
result = bt_vcp_vol_ctlr_cb_register(&vcs_cbs); result = bt_vcp_vol_ctlr_cb_register(&vcp_cbs);
if (result != 0) { if (result != 0) {
shell_print(sh, "CB register failed: %d", result); shell_print(sh, "CB register failed: %d", result);
return result; return result;

View file

@ -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, .state = vcp_vol_rend_state_cb,
.flags = vcp_vol_rend_flags_cb, .flags = vcp_vol_rend_flags_cb,
}; };

View file

@ -225,7 +225,7 @@ static void vcs_write_cb(struct bt_vcp *vcp, int err)
g_write_complete = true; g_write_complete = true;
} }
static struct bt_vcp_cb vcs_cbs = { static struct bt_vcp_vol_ctlr_cb vcp_cbs = {
.discover = vcs_discover_cb, .discover = vcs_discover_cb,
.vol_down = vcs_write_cb, .vol_down = vcs_write_cb,
.vol_up = vcs_write_cb, .vol_up = vcs_write_cb,
@ -544,7 +544,7 @@ static void test_main(void)
return; return;
} }
err = bt_vcp_vol_ctlr_cb_register(&vcs_cbs); err = bt_vcp_vol_ctlr_cb_register(&vcp_cbs);
if (err) { if (err) {
FAIL("CB register failed (err %d)\n", err); FAIL("CB register failed (err %d)\n", err);
return; return;

View file

@ -167,7 +167,7 @@ static void aics_description_cb(struct bt_aics *inst, int err,
g_cb = true; g_cb = true;
} }
static struct bt_vcp_cb vcs_cb = { static struct bt_vcp_vol_rend_cb vcs_cb = {
.state = vcs_state_cb, .state = vcs_state_cb,
.flags = vcs_flags_cb, .flags = vcs_flags_cb,
}; };