Skip to content

Commit 51f2022

Browse files
Thalleynashif
authored andcommitted
Bluetooth: Audio: Add initial server values in bt_vcs_register_param
Add support for setting initial values in bt_vcs_register_param when registering a VCS service Signed-off-by: Emil Gydesen <[email protected]>
1 parent 6a8abcb commit 51f2022

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

include/bluetooth/audio/vcs.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,24 @@ extern "C" {
3939
#define BT_VCS_ERR_INVALID_COUNTER 0x80
4040
#define BT_VCS_ERR_OP_NOT_SUPPORTED 0x81
4141

42+
/** Volume Control Service Mute Values */
43+
#define BT_VCS_STATE_UNMUTED 0x00
44+
#define BT_VCS_STATE_MUTED 0x01
45+
4246
/** @brief Opaque Volume Control Service instance. */
4347
struct bt_vcs;
4448

4549
/** Register structure for Volume Control Service */
4650
struct bt_vcs_register_param {
51+
/** Initial step size (1-255) */
52+
uint8_t step;
53+
54+
/** Initial mute state (0-1) */
55+
uint8_t mute;
56+
57+
/** Initial volume level (0-255) */
58+
uint8_t volume;
59+
4760
/** Register parameters for Volume Offset Control Services */
4861
struct bt_vocs_register_param vocs_param[BT_VCS_VOCS_CNT];
4962

subsys/bluetooth/audio/vcs.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
152152
notify = true;
153153
}
154154
if (vcs_inst.srv.state.mute) {
155-
vcs_inst.srv.state.mute = 0;
155+
vcs_inst.srv.state.mute = BT_VCS_STATE_UNMUTED;
156156
notify = true;
157157
}
158158
volume_change = true;
@@ -164,7 +164,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
164164
notify = true;
165165
}
166166
if (vcs_inst.srv.state.mute) {
167-
vcs_inst.srv.state.mute = 0;
167+
vcs_inst.srv.state.mute = BT_VCS_STATE_UNMUTED;
168168
notify = true;
169169
}
170170
volume_change = true;
@@ -181,14 +181,14 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
181181
case BT_VCS_OPCODE_UNMUTE:
182182
BT_DBG("Unmute (0x%x)", opcode);
183183
if (vcs_inst.srv.state.mute) {
184-
vcs_inst.srv.state.mute = 0;
184+
vcs_inst.srv.state.mute = BT_VCS_STATE_UNMUTED;
185185
notify = true;
186186
}
187187
break;
188188
case BT_VCS_OPCODE_MUTE:
189189
BT_DBG("Mute (0x%x)", opcode);
190-
if (vcs_inst.srv.state.mute == 0) {
191-
vcs_inst.srv.state.mute = 1;
190+
if (vcs_inst.srv.state.mute == BT_VCS_STATE_UNMUTED) {
191+
vcs_inst.srv.state.mute = BT_VCS_STATE_MUTED;
192192
notify = true;
193193
}
194194
break;
@@ -362,6 +362,21 @@ int bt_vcs_register(struct bt_vcs_register_param *param, struct bt_vcs **vcs)
362362
static bool registered;
363363
int err;
364364

365+
CHECKIF(param == NULL) {
366+
BT_DBG("param is NULL");
367+
return -EINVAL;
368+
}
369+
370+
CHECKIF(param->mute > BT_VCS_STATE_MUTED) {
371+
BT_DBG("Invalid mute value: %u", param->mute);
372+
return -EINVAL;
373+
}
374+
375+
CHECKIF(param->step == 0) {
376+
BT_DBG("Invalid step value: %u", param->step);
377+
return -EINVAL;
378+
}
379+
365380
if (registered) {
366381
*vcs = &vcs_inst;
367382
return -EALREADY;
@@ -386,8 +401,9 @@ int bt_vcs_register(struct bt_vcs_register_param *param, struct bt_vcs **vcs)
386401
}
387402

388403

389-
vcs_inst.srv.state.volume = 100; /* Default value */
390-
vcs_inst.srv.volume_step = 1; /* Default value */
404+
vcs_inst.srv.state.volume = param->volume;
405+
vcs_inst.srv.state.mute = param->mute;
406+
vcs_inst.srv.volume_step = param->step;
391407
vcs_inst.srv.service_p = &vcs_svc;
392408

393409
err = bt_gatt_service_register(&vcs_svc);

subsys/bluetooth/shell/vcs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ static int cmd_vcs_init(const struct shell *sh, size_t argc, char **argv)
193193
vcs_param.aics_param[i].cb = &aics_cbs;
194194
}
195195

196+
vcs_param.step = 1;
197+
vcs_param.mute = BT_VCS_STATE_UNMUTED;
198+
vcs_param.volume = 100;
199+
196200
vcs_param.cb = &vcs_cbs;
197201

198202
result = bt_vcs_register(&vcs_param, &vcs);

tests/bluetooth/bsim_bt/bsim_test_audio/src/vcs_test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,9 @@ static void test_standalone(void)
474474
vcs_param.aics_param[i].cb = &aics_cb;
475475
}
476476

477+
vcs_param.step = 1;
478+
vcs_param.mute = BT_VCS_STATE_UNMUTED;
479+
vcs_param.volume = 100;
477480
vcs_param.cb = &vcs_cb;
478481

479482
err = bt_vcs_register(&vcs_param, &vcs);
@@ -667,6 +670,9 @@ static void test_main(void)
667670
vcs_param.aics_param[i].cb = &aics_cb;
668671
}
669672

673+
vcs_param.step = 1;
674+
vcs_param.mute = BT_VCS_STATE_UNMUTED;
675+
vcs_param.volume = 100;
670676
vcs_param.cb = &vcs_cb;
671677

672678
err = bt_vcs_register(&vcs_param, &vcs);

0 commit comments

Comments
 (0)