1 /** @file
2  *  @brief Bluetooth Volume Control Profile (VCP) Volume Renderer role.
3  *
4  *  Copyright (c) 2020 Bose Corporation
5  *  Copyright (c) 2020-2022 Nordic Semiconductor ASA
6  *  Copyright (c) 2022 Codecoup
7  *  Copyright 2023 NXP
8  *
9  *  SPDX-License-Identifier: Apache-2.0
10  */
11 
12 #include <zephyr/kernel.h>
13 #include <zephyr/sys/printk.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16 
17 #include <zephyr/bluetooth/conn.h>
18 #include <zephyr/bluetooth/audio/vcp.h>
19 
20 static struct bt_vcp_included vcp_included;
21 
vcs_state_cb(int err,uint8_t volume,uint8_t mute)22 static void vcs_state_cb(int err, uint8_t volume, uint8_t mute)
23 {
24 	if (err) {
25 		printk("VCS state get failed (%d)\n", err);
26 	} else {
27 		printk("VCS volume %u, mute %u\n", volume, mute);
28 	}
29 }
30 
vcs_flags_cb(int err,uint8_t flags)31 static void vcs_flags_cb(int err, uint8_t flags)
32 {
33 	if (err) {
34 		printk("VCS flags get failed (%d)\n", err);
35 	} else {
36 		printk("VCS flags 0x%02X\n", flags);
37 	}
38 }
39 
40 static struct bt_vcp_vol_rend_cb vcp_cbs = {
41 	.state = vcs_state_cb,
42 	.flags = vcs_flags_cb,
43 };
44 
vcp_vol_renderer_init(void)45 int vcp_vol_renderer_init(void)
46 {
47 	int err;
48 	struct bt_vcp_vol_rend_register_param vcp_register_param;
49 
50 	memset(&vcp_register_param, 0, sizeof(vcp_register_param));
51 
52 	vcp_register_param.step = 1;
53 	vcp_register_param.mute = BT_VCP_STATE_UNMUTED;
54 	vcp_register_param.volume = 100;
55 	vcp_register_param.cb = &vcp_cbs;
56 
57 	err = bt_vcp_vol_rend_register(&vcp_register_param);
58 	if (err) {
59 		return err;
60 	}
61 
62 	err = bt_vcp_vol_rend_included_get(&vcp_included);
63 	if (err != 0) {
64 		return err;
65 	}
66 
67 	return 0;
68 }
69