1 /** 2 * @file 3 * @brief Internal Header for Bluetooth Volume Control Service (VCS). 4 * 5 * Copyright (c) 2020 Bose Corporation 6 * Copyright (c) 2020-2022 Nordic Semiconductor ASA 7 * 8 * SPDX-License-Identifier: Apache-2.0 9 */ 10 11 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_VCP_INTERNAL_ 12 #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_VCP_INTERNAL_ 13 14 #include <stdbool.h> 15 #include <stdint.h> 16 17 #include <zephyr/autoconf.h> 18 #include <zephyr/bluetooth/conn.h> 19 #include <zephyr/bluetooth/gatt.h> 20 #include <zephyr/bluetooth/uuid.h> 21 #include <zephyr/sys/atomic.h> 22 23 /* VCS opcodes */ 24 #define BT_VCP_OPCODE_REL_VOL_DOWN 0x00 25 #define BT_VCP_OPCODE_REL_VOL_UP 0x01 26 #define BT_VCP_OPCODE_UNMUTE_REL_VOL_DOWN 0x02 27 #define BT_VCP_OPCODE_UNMUTE_REL_VOL_UP 0x03 28 #define BT_VCP_OPCODE_SET_ABS_VOL 0x04 29 #define BT_VCP_OPCODE_UNMUTE 0x05 30 #define BT_VCP_OPCODE_MUTE 0x06 31 32 struct vcs_state { 33 uint8_t volume; 34 uint8_t mute; 35 uint8_t change_counter; 36 } __packed; 37 38 struct vcs_control { 39 uint8_t opcode; 40 uint8_t counter; 41 } __packed; 42 43 struct vcs_control_vol { 44 struct vcs_control cp; 45 uint8_t volume; 46 } __packed; 47 48 enum bt_vcp_vol_ctlr_flag { 49 BT_VCP_VOL_CTLR_FLAG_BUSY, 50 BT_VCP_VOL_CTLR_FLAG_CP_RETRIED, 51 52 BT_VCP_VOL_CTLR_FLAG_NUM_FLAGS, /* keep as last */ 53 }; 54 55 struct bt_vcp_vol_ctlr { 56 struct vcs_state state; 57 uint8_t vol_flags; 58 59 uint16_t start_handle; 60 uint16_t end_handle; 61 uint16_t state_handle; 62 uint16_t control_handle; 63 uint16_t vol_flag_handle; 64 struct bt_gatt_subscribe_params state_sub_params; 65 struct bt_gatt_discover_params state_sub_disc_params; 66 struct bt_gatt_subscribe_params vol_flag_sub_params; 67 struct bt_gatt_discover_params vol_flag_sub_disc_params; 68 69 struct vcs_control_vol cp_val; 70 struct bt_gatt_write_params write_params; 71 struct bt_gatt_read_params read_params; 72 struct bt_gatt_discover_params discover_params; 73 struct bt_uuid_16 uuid; 74 struct bt_conn *conn; 75 76 #if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS) 77 uint8_t vocs_inst_cnt; 78 struct bt_vocs *vocs[CONFIG_BT_VCP_VOL_CTLR_MAX_VOCS_INST]; 79 #endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */ 80 #if defined(CONFIG_BT_VCP_VOL_CTLR_AICS) 81 uint8_t aics_inst_cnt; 82 struct bt_aics *aics[CONFIG_BT_VCP_VOL_CTLR_MAX_AICS_INST]; 83 #endif /* CONFIG_BT_VCP_VOL_CTLR_AICS */ 84 85 ATOMIC_DEFINE(flags, BT_VCP_VOL_CTLR_FLAG_NUM_FLAGS); 86 }; 87 88 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_VCP_INTERNAL_*/ 89