tests: bsim: Bluetooth: CAP Commander Change Microphone Gain

Adds bsim test of the CAP Commander Change Microphone Gain
procedure.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2023-12-21 13:23:54 +01:00 committed by Fabio Baltieri
parent fa6a7c1b77
commit 8956642265
2 changed files with 139 additions and 3 deletions

View file

@ -10,6 +10,7 @@
#include <zephyr/bluetooth/audio/bap_lc3_preset.h>
#include <zephyr/bluetooth/audio/cap.h>
#include <zephyr/bluetooth/audio/pacs.h>
#include <zephyr/bluetooth/audio/micp.h>
#include <zephyr/bluetooth/audio/vcp.h>
#include <zephyr/sys/byteorder.h>
#include "common.h"
@ -672,7 +673,7 @@ static void init(void)
for (size_t i = 0U; i < ARRAY_SIZE(vcp_param.aics_param); i++) {
vcp_param.aics_param[i].desc_writable = true;
snprintf(input_desc[i], sizeof(input_desc[i]), "Input %d", i + 1);
snprintf(input_desc[i], sizeof(input_desc[i]), "VCP Input %d", i + 1);
vcp_param.aics_param[i].description = input_desc[i];
vcp_param.aics_param[i].type = BT_AICS_INPUT_TYPE_DIGITAL;
vcp_param.aics_param[i].status = true;
@ -694,6 +695,33 @@ static void init(void)
return;
}
}
if (IS_ENABLED(CONFIG_BT_MICP_MIC_DEV)) {
struct bt_micp_mic_dev_register_param micp_param = {0};
#if defined(CONFIG_BT_MICP_MIC_DEV_AICS)
char input_desc[CONFIG_BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT][16];
for (int i = 0; i < ARRAY_SIZE(micp_param.aics_param); i++) {
micp_param.aics_param[i].desc_writable = true;
snprintf(input_desc[i], sizeof(input_desc[i]), "MICP Input %d", i + 1);
micp_param.aics_param[i].description = input_desc[i];
micp_param.aics_param[i].type = BT_AICS_INPUT_TYPE_DIGITAL;
micp_param.aics_param[i].status = true;
micp_param.aics_param[i].gain_mode = BT_AICS_MODE_MANUAL;
micp_param.aics_param[i].units = 1;
micp_param.aics_param[i].min_gain = 0;
micp_param.aics_param[i].max_gain = 100;
micp_param.aics_param[i].cb = NULL;
}
#endif /* CONFIG_BT_MICP_MIC_DEV_AICS */
err = bt_micp_mic_dev_register(&micp_param);
if (err != 0) {
FAIL("Failed to register MICS (err %d)\n", err);
return;
}
}
}
static void test_cap_acceptor_unicast(void)

View file

@ -10,6 +10,7 @@
#include <zephyr/bluetooth/byteorder.h>
#include <zephyr/bluetooth/audio/bap_lc3_preset.h>
#include <zephyr/bluetooth/audio/cap.h>
#include <zephyr/bluetooth/audio/micp.h>
#include <zephyr/bluetooth/audio/vcp.h>
#include <zephyr/sys/byteorder.h>
#include "common.h"
@ -22,10 +23,12 @@ static volatile size_t connected_conn_cnt;
CREATE_FLAG(flag_cas_discovered);
CREATE_FLAG(flag_vcs_discovered);
CREATE_FLAG(flag_mics_discovered);
CREATE_FLAG(flag_mtu_exchanged);
CREATE_FLAG(flag_volume_changed);
CREATE_FLAG(flag_volume_mute_changed);
CREATE_FLAG(flag_volume_offset_changed);
CREATE_FLAG(flag_microphone_gain_changed);
static void cap_discovery_complete_cb(struct bt_conn *conn, int err,
const struct bt_csip_set_coordinator_csis_inst *csis_inst)
@ -51,6 +54,7 @@ static void cap_discovery_complete_cb(struct bt_conn *conn, int err,
SET_FLAG(flag_cas_discovered);
}
#if defined(CONFIG_BT_VCP_VOL_CTLR)
static void cap_volume_changed_cb(struct bt_conn *conn, int err)
{
if (err != 0) {
@ -71,6 +75,7 @@ static void cap_volume_mute_changed_cb(struct bt_conn *conn, int err)
SET_FLAG(flag_volume_mute_changed);
}
#if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS)
static void cap_volume_offset_changed_cb(struct bt_conn *conn, int err)
{
if (err != 0) {
@ -80,12 +85,37 @@ static void cap_volume_offset_changed_cb(struct bt_conn *conn, int err)
SET_FLAG(flag_volume_offset_changed);
}
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
#endif /* CONFIG_BT_VCP_VOL_CTLR */
#if defined(CONFIG_BT_MICP_MIC_CTLR)
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
static void cap_microphone_gain_changed_cb(struct bt_conn *conn, int err)
{
if (err != 0) {
FAIL("Failed to change volume for conn %p: %d\n", conn, err);
return;
}
SET_FLAG(flag_microphone_gain_changed);
}
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
#endif /* CONFIG_BT_MICP_MIC_CTLR */
static struct bt_cap_commander_cb cap_cb = {
.discovery_complete = cap_discovery_complete_cb,
#if defined(CONFIG_BT_VCP_VOL_CTLR)
.volume_changed = cap_volume_changed_cb,
.volume_mute_changed = cap_volume_mute_changed_cb,
#if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS)
.volume_offset_changed = cap_volume_offset_changed_cb,
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
#endif /* CONFIG_BT_VCP_VOL_CTLR */
#if defined(CONFIG_BT_MICP_MIC_CTLR)
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
.microphone_gain_changed = cap_microphone_gain_changed_cb,
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
#endif /* CONFIG_BT_MICP_MIC_CTLR */
};
static void cap_vcp_discover_cb(struct bt_vcp_vol_ctlr *vol_ctlr, int err, uint8_t vocs_count,
@ -117,6 +147,22 @@ static struct bt_vcp_vol_ctlr_cb vcp_cb = {
.state = cap_vcp_state_cb,
};
static void cap_micp_discover_cb(struct bt_micp_mic_ctlr *mic_ctlr, int err, uint8_t aics_count)
{
if (err != 0) {
FAIL("Failed to discover MICS: %d\n", err);
return;
}
printk("MICS for %p found with %u AICS\n", mic_ctlr, aics_count);
SET_FLAG(flag_mics_discovered);
}
static struct bt_micp_mic_ctlr_cb micp_cb = {
.discover = cap_micp_discover_cb,
};
static void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx)
{
printk("MTU exchanged\n");
@ -150,6 +196,12 @@ static void init(void)
FAIL("Failed to register VCP callbacks (err %d)\n", err);
return;
}
err = bt_micp_mic_ctlr_cb_register(&micp_cb);
if (err != 0) {
FAIL("Failed to register MICP callbacks (err %d)\n", err);
return;
}
}
static void cap_device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
@ -247,13 +299,29 @@ static void discover_vcs(struct bt_conn *conn)
err = bt_vcp_vol_ctlr_discover(conn, &vol_ctlr);
if (err != 0) {
printk("Failed to discover VCS: %d\n", err);
FAIL("Failed to discover VCS: %d\n", err);
return;
}
WAIT_FOR_FLAG(flag_vcs_discovered);
}
static void discover_mics(struct bt_conn *conn)
{
struct bt_micp_mic_ctlr *mic_ctlr;
int err;
UNSET_FLAG(flag_mics_discovered);
err = bt_micp_mic_ctlr_discover(conn, &mic_ctlr);
if (err != 0) {
FAIL("Failed to discover MICS: %d\n", err);
return;
}
WAIT_FOR_FLAG(flag_mics_discovered);
}
static void test_change_volume(void)
{
union bt_cap_set_member members[CONFIG_BT_MAX_CONN];
@ -338,6 +406,35 @@ static void test_change_volume_offset(void)
printk("Volume offset changed\n");
}
static void test_change_microphone_gain(void)
{
struct bt_cap_commander_change_microphone_gain_setting_member_param
member_params[CONFIG_BT_MAX_CONN];
const struct bt_cap_commander_change_microphone_gain_setting_param param = {
.type = BT_CAP_SET_TYPE_AD_HOC,
.param = member_params,
.count = connected_conn_cnt,
};
int err;
printk("Changing microphone gain\n");
UNSET_FLAG(flag_microphone_gain_changed);
for (size_t i = 0U; i < param.count; i++) {
member_params[i].member.member = connected_conns[i];
member_params[i].gain = 10 + i;
}
err = bt_cap_commander_change_microphone_gain_setting(&param);
if (err != 0) {
FAIL("Failed to change microphone gain: %d\n", err);
return;
}
WAIT_FOR_FLAG(flag_microphone_gain_changed);
printk("Microphone gain changed\n");
}
static void test_main_cap_commander_capture_and_render(void)
{
init();
@ -355,6 +452,10 @@ static void test_main_cap_commander_capture_and_render(void)
if (IS_ENABLED(CONFIG_BT_VCP_VOL_CTLR)) {
discover_vcs(connected_conns[i]);
}
if (IS_ENABLED(CONFIG_BT_MICP_MIC_CTLR)) {
discover_mics(connected_conns[i]);
}
}
if (IS_ENABLED(CONFIG_BT_CSIP_SET_COORDINATOR)) {
@ -368,7 +469,14 @@ static void test_main_cap_commander_capture_and_render(void)
test_change_volume_offset();
}
}
/* TODO: Add test of offset (VOCS), Mic (MICP) and gain (AICS) */
if (IS_ENABLED(CONFIG_BT_MICP_MIC_CTLR)) {
/* TODO: Add test of mic mute */
if (IS_ENABLED(CONFIG_BT_MICP_MIC_CTLR_AICS)) {
test_change_microphone_gain();
}
}
}
/* Disconnect all CAP acceptors */