Bluetooth: Audio: Rename struct bt_micp and cleanup
Rename struct bt_micp to bt_mic_ctlr as it is only used ofr microphone controller now. This also allow cleanup of the bt_micp struct, thus removing the common internal micp_internal.h header file and reducing the size of the implementation by not using a union of the structs. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
c8a6a51566
commit
28f6e37ba8
6 changed files with 299 additions and 341 deletions
|
@ -41,10 +41,10 @@ extern "C" {
|
|||
#define BT_MICP_MUTE_MUTED 0x01
|
||||
#define BT_MICP_MUTE_DISABLED 0x02
|
||||
|
||||
/** @brief Opaque Microphone Input Control Profile instance. */
|
||||
struct bt_micp;
|
||||
/** @brief Opaque Microphone Controller instance. */
|
||||
struct bt_micp_mic_ctlr;
|
||||
|
||||
/** @brief Register parameters structure for Microphone Input Control Profile instance */
|
||||
/** @brief Register parameters structure for Microphone Input Control Service */
|
||||
struct bt_micp_mic_dev_register_param {
|
||||
#if defined(CONFIG_BT_MICP_MIC_DEV_AICS)
|
||||
/** Register parameter structure for Audio Input Control Services */
|
||||
|
@ -59,10 +59,11 @@ struct bt_micp_mic_dev_register_param {
|
|||
* @brief Microphone Input Control Profile included services
|
||||
*
|
||||
* Used for to represent the Microphone Input Control Profile included service
|
||||
* instances, for either a client or a server instance. The instance pointers
|
||||
* either represent local server instances, or remote service instances.
|
||||
* instances, for either a Microphone Controller or a Microphone Device.
|
||||
* The instance pointers either represent local service instances,
|
||||
* or remote service instances.
|
||||
*/
|
||||
struct bt_micp_included {
|
||||
struct bt_micp_included {
|
||||
/** Number of Audio Input Control Service instances */
|
||||
uint8_t aics_cnt;
|
||||
/** Array of pointers to Audio Input Control Service instances */
|
||||
|
@ -70,11 +71,10 @@ struct bt_micp_included {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief Initialize the Microphone Input Control Profile
|
||||
* @brief Initialize the Microphone Input Control Profile Microphone Device
|
||||
*
|
||||
* This will enable the Microphone Input Control Profile instance and make it
|
||||
* discoverable by clients.
|
||||
* This can only be done as the server.
|
||||
* This will enable the Microphone Input Control Service instance and make it
|
||||
* discoverable by Microphone Controllers.
|
||||
*
|
||||
* @param param Pointer to an initialization structure.
|
||||
*
|
||||
|
@ -83,13 +83,12 @@ struct bt_micp_included {
|
|||
int bt_micp_mic_dev_register(struct bt_micp_mic_dev_register_param *param);
|
||||
|
||||
/**
|
||||
* @brief Get Microphone Input Control Profile included services
|
||||
* @brief Get Microphone Device included services
|
||||
*
|
||||
* Returns a pointer to a struct that contains information about the
|
||||
* Microphone Input Control Profile included services instances, such as
|
||||
* pointers to the Audio Input Control Service instances.
|
||||
* Microphone Device included Audio Input Control Service instances.
|
||||
*
|
||||
* Requires that @kconfig{CONFIG_BT_MICP_MIC_DEV_AICS}
|
||||
* Requires that @kconfig{CONFIG_BT_MICP_MIC_DEV_AICS} is enabled.
|
||||
*
|
||||
* @param included Pointer to store the result in.
|
||||
*
|
||||
|
@ -99,51 +98,42 @@ int bt_micp_mic_dev_included_get(struct bt_micp_included *included);
|
|||
|
||||
struct bt_micp_mic_dev_cb {
|
||||
/**
|
||||
* @brief Callback function for Microphone Input Control Profile mute.
|
||||
* @brief Callback function for Microphone Device mute.
|
||||
*
|
||||
* Called when the value is read with bt_micp_mic_dev_mute_get(),
|
||||
* or if the value is changed by either the server or client.
|
||||
* or if the value is changed by either the Microphone Device or a
|
||||
* Microphone Controller.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
* @param mute The mute setting of the Microphone Input Control Profile instance.
|
||||
* @param mute The mute setting of the Microphone Input Control Service.
|
||||
*/
|
||||
void (*mute)(uint8_t mute);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Unmute the server.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
* @brief Unmute the Microphone Device.
|
||||
*
|
||||
* @return 0 on success, GATT error value on fail.
|
||||
*/
|
||||
int bt_micp_mic_dev_unmute(void);
|
||||
|
||||
/**
|
||||
* @brief Mute the server.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
* @brief Mute the Microphone Device.
|
||||
*
|
||||
* @return 0 on success, GATT error value on fail.
|
||||
*/
|
||||
int bt_micp_mic_dev_mute(void);
|
||||
|
||||
/**
|
||||
* @brief Disable the mute functionality.
|
||||
* @brief Disable the mute functionality on the Microphone Device.
|
||||
*
|
||||
* Can be reenabled by called @ref bt_micp_mic_dev_mute or @ref bt_micp_mic_dev_unmute.
|
||||
* This can only be done as the server.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
*
|
||||
* @return 0 on success, GATT error value on fail.
|
||||
*/
|
||||
int bt_micp_mic_dev_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Read the mute state of a Microphone Input Control Profile instance.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
* @brief Read the mute state on the Microphone Device.
|
||||
*
|
||||
* @return 0 on success, GATT error value on fail.
|
||||
*/
|
||||
|
@ -154,42 +144,42 @@ struct bt_micp_mic_ctlr_cb {
|
|||
* @brief Callback function for Microphone Input Control Profile mute.
|
||||
*
|
||||
* Called when the value is read,
|
||||
* or if the value is changed by either the server or client.
|
||||
* or if the value is changed by either the Microphone Device or a
|
||||
* Microphone Controller.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
* @param mic_ctlr Microphone Controller instance pointer.
|
||||
* @param err Error value. 0 on success, GATT error or errno on fail.
|
||||
* For notifications, this will always be 0.
|
||||
* @param mute The mute setting of the Microphone Input Control Profile instance.
|
||||
* @param mute The mute setting of the Microphone Input Control Service.
|
||||
*/
|
||||
void (*mute)(struct bt_micp *micp, int err, uint8_t mute);
|
||||
void (*mute)(struct bt_micp_mic_ctlr *mic_ctlr, int err, uint8_t mute);
|
||||
|
||||
/**
|
||||
* @brief Callback function for bt_micp_mic_ctlr_discover().
|
||||
*
|
||||
* This callback is only used for the client.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
* @param mic_ctlr Microphone Controller instance pointer.
|
||||
* @param err Error value. 0 on success, GATT error or errno on fail.
|
||||
* @param aics_count Number of Audio Input Control Service instances on
|
||||
* peer device.
|
||||
*/
|
||||
void (*discover)(struct bt_micp *micp, int err, uint8_t aics_count);
|
||||
void (*discover)(struct bt_micp_mic_ctlr *mic_ctlr, int err,
|
||||
uint8_t aics_count);
|
||||
|
||||
/**
|
||||
* @brief Callback function for Microphone Input Control Profile mute/unmute.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
* @param mic_ctlr Microphone Controller instance pointer.
|
||||
* @param err Error value. 0 on success, GATT error or errno on fail.
|
||||
*/
|
||||
void (*mute_written)(struct bt_micp *micp, int err);
|
||||
void (*mute_written)(struct bt_micp_mic_ctlr *mic_ctlr, int err);
|
||||
|
||||
/**
|
||||
* @brief Callback function for Microphone Input Control Profile mute/unmute.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
* @param mic_ctlr Microphone Controller instance pointer.
|
||||
* @param err Error value. 0 on success, GATT error or errno on fail.
|
||||
*/
|
||||
void (*unmute_written)(struct bt_micp *micp, int err);
|
||||
void (*unmute_written)(struct bt_micp_mic_ctlr *mic_ctlr, int err);
|
||||
|
||||
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
|
||||
/** Audio Input Control Service client callback */
|
||||
|
@ -206,74 +196,72 @@ struct bt_micp_mic_ctlr_cb {
|
|||
*
|
||||
* Requires that @kconfig{CONFIG_BT_MICP_MIC_CTLR_AICS} is enabled.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
* @param mic_ctlr Microphone Controller instance pointer.
|
||||
* @param[out] included Pointer to store the result in.
|
||||
*
|
||||
* @return 0 if success, errno on failure.
|
||||
*/
|
||||
int bt_micp_mic_ctlr_included_get(struct bt_micp *micp,
|
||||
int bt_micp_mic_ctlr_included_get(struct bt_micp_mic_ctlr *mic_ctlr,
|
||||
struct bt_micp_included *included);
|
||||
|
||||
/**
|
||||
* @brief Get the connection pointer of a client instance
|
||||
* @brief Get the connection pointer of a Microphone Controller instance
|
||||
*
|
||||
* Get the Bluetooth connection pointer of a Microphone Input Control Profile
|
||||
* client instance.
|
||||
* Get the Bluetooth connection pointer of a Microphone Controller instance.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile client instance pointer.
|
||||
* @param conn Connection pointer.
|
||||
* @param mic_ctlr Microphone Controller instance pointer.
|
||||
* @param conn Connection pointer.
|
||||
*
|
||||
* @return 0 if success, errno on failure.
|
||||
*/
|
||||
int bt_micp_mic_ctlr_conn_get(const struct bt_micp *micp,
|
||||
int bt_micp_mic_ctlr_conn_get(const struct bt_micp_mic_ctlr *mic_ctlr,
|
||||
struct bt_conn **conn);
|
||||
|
||||
/**
|
||||
* @brief Discover Microphone Input Control Profile instance
|
||||
* @brief Discover Microphone Input Control Service
|
||||
*
|
||||
* This will start a GATT discovery and setup handles and subscriptions.
|
||||
* This shall be called once before any other actions can be executed for the
|
||||
* peer device, and the @ref bt_micp_mic_ctlr_cb.discover callback will notify
|
||||
* when it is possible to start remote operations.
|
||||
*
|
||||
* This shall only be done as the client.
|
||||
*
|
||||
* *
|
||||
* @param conn The connection to initialize the profile for.
|
||||
* @param[out] micp Valid remote instance object on success.
|
||||
* @param[out] mic_ctlr Valid remote instance object on success.
|
||||
*
|
||||
* @return 0 on success, GATT error value on fail.
|
||||
*/
|
||||
int bt_micp_mic_ctlr_discover(struct bt_conn *conn, struct bt_micp **micp);
|
||||
int bt_micp_mic_ctlr_discover(struct bt_conn *conn,
|
||||
struct bt_micp_mic_ctlr **mic_ctlr);
|
||||
|
||||
/**
|
||||
* @brief Unmute the server.
|
||||
* @brief Unmute a remote Microphone Device.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
* @param mic_ctlr Microphone Controller instance pointer.
|
||||
*
|
||||
* @return 0 on success, GATT error value on fail.
|
||||
*/
|
||||
int bt_micp_mic_ctlr_unmute(struct bt_micp *micp);
|
||||
int bt_micp_mic_ctlr_unmute(struct bt_micp_mic_ctlr *mic_ctlr);
|
||||
|
||||
/**
|
||||
* @brief Mute the server.
|
||||
* @brief Mute a remote Microphone Device.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
* @param mic_ctlr Microphone Controller instance pointer.
|
||||
*
|
||||
* @return 0 on success, GATT error value on fail.
|
||||
*/
|
||||
int bt_micp_mic_ctlr_mute(struct bt_micp *micp);
|
||||
int bt_micp_mic_ctlr_mute(struct bt_micp_mic_ctlr *mic_ctlr);
|
||||
|
||||
/**
|
||||
* @brief Read the mute state of a Microphone Input Control Profile instance.
|
||||
* @brief Read the mute state of a remote Microphone Device.
|
||||
*
|
||||
* @param micp Microphone Input Control Profile instance pointer.
|
||||
* @param mic_ctlr Microphone Controller instance pointer.
|
||||
*
|
||||
* @return 0 on success, GATT error value on fail.
|
||||
*/
|
||||
int bt_micp_mic_ctlr_mute_get(struct bt_micp *micp);
|
||||
int bt_micp_mic_ctlr_mute_get(struct bt_micp_mic_ctlr *mic_ctlr);
|
||||
|
||||
/**
|
||||
* @brief Registers the callbacks used by Microphone Input Control Profile client.
|
||||
* @brief Registers the callbacks used by Microphone Controller.
|
||||
*
|
||||
* This can only be done as the client.
|
||||
*
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2022 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MICP_INTERNAL_
|
||||
#define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MICP_INTERNAL_
|
||||
#include <zephyr/types.h>
|
||||
#include <zephyr/bluetooth/gatt.h>
|
||||
|
||||
#if defined(CONFIG_BT_MICP_MIC_DEV)
|
||||
struct bt_micp_server {
|
||||
uint8_t mute;
|
||||
struct bt_micp_mic_dev_cb *cb;
|
||||
struct bt_gatt_service *service_p;
|
||||
struct bt_aics *aics_insts[CONFIG_BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT];
|
||||
};
|
||||
#endif /* CONFIG_BT_MICP_MIC_DEV */
|
||||
|
||||
#if defined(CONFIG_BT_MICP_MIC_CTLR)
|
||||
struct bt_micp_mic_ctlr {
|
||||
uint16_t start_handle;
|
||||
uint16_t end_handle;
|
||||
uint16_t mute_handle;
|
||||
struct bt_gatt_subscribe_params mute_sub_params;
|
||||
struct bt_gatt_discover_params mute_sub_disc_params;
|
||||
|
||||
bool busy;
|
||||
uint8_t mute_val_buf[1]; /* Mute value is a single octet */
|
||||
struct bt_gatt_write_params write_params;
|
||||
struct bt_gatt_read_params read_params;
|
||||
struct bt_gatt_discover_params discover_params;
|
||||
struct bt_conn *conn;
|
||||
|
||||
uint8_t aics_inst_cnt;
|
||||
struct bt_aics *aics[CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST];
|
||||
};
|
||||
#endif /* CONFIG_BT_MICP_MIC_CTLR */
|
||||
|
||||
/* Struct used as a common type for the api */
|
||||
struct bt_micp {
|
||||
bool client_instance;
|
||||
union {
|
||||
#if defined(CONFIG_BT_MICP_MIC_DEV)
|
||||
struct bt_micp_server srv;
|
||||
#endif /* CONFIG_BT_MICP_MIC_DEV */
|
||||
#if defined(CONFIG_BT_MICP_MIC_CTLR)
|
||||
struct bt_micp_mic_ctlr cli;
|
||||
#endif /* CONFIG_BT_MICP_MIC_CTLR */
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MICS_INTERNAL_ */
|
|
@ -20,8 +20,6 @@
|
|||
#include <zephyr/bluetooth/gatt.h>
|
||||
#include <zephyr/bluetooth/audio/micp.h>
|
||||
|
||||
#include "micp_internal.h"
|
||||
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_MICP_MIC_CTLR)
|
||||
#define LOG_MODULE_NAME bt_micp_mic_ctlr
|
||||
#include "common/log.h"
|
||||
|
@ -29,7 +27,25 @@
|
|||
/* Callback functions */
|
||||
static struct bt_micp_mic_ctlr_cb *micp_mic_ctlr_cb;
|
||||
|
||||
static struct bt_micp micp_insts[CONFIG_BT_MAX_CONN];
|
||||
struct bt_micp_mic_ctlr {
|
||||
uint16_t start_handle;
|
||||
uint16_t end_handle;
|
||||
uint16_t mute_handle;
|
||||
struct bt_gatt_subscribe_params mute_sub_params;
|
||||
struct bt_gatt_discover_params mute_sub_disc_params;
|
||||
|
||||
bool busy;
|
||||
uint8_t mute_val_buf[1]; /* Mute value is a single octet */
|
||||
struct bt_gatt_write_params write_params;
|
||||
struct bt_gatt_read_params read_params;
|
||||
struct bt_gatt_discover_params discover_params;
|
||||
struct bt_conn *conn;
|
||||
|
||||
uint8_t aics_inst_cnt;
|
||||
struct bt_aics *aics[CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST];
|
||||
};
|
||||
|
||||
static struct bt_micp_mic_ctlr mic_ctlrs[CONFIG_BT_MAX_CONN];
|
||||
static struct bt_uuid *mics_uuid = BT_UUID_MICS;
|
||||
|
||||
static uint8_t mute_notify_handler(struct bt_conn *conn,
|
||||
|
@ -37,13 +53,13 @@ static uint8_t mute_notify_handler(struct bt_conn *conn,
|
|||
const void *data, uint16_t length)
|
||||
{
|
||||
uint8_t *mute_val;
|
||||
struct bt_micp *micp_inst;
|
||||
struct bt_micp_mic_ctlr *mic_ctlr;
|
||||
|
||||
if (conn == NULL) {
|
||||
return BT_GATT_ITER_CONTINUE;
|
||||
}
|
||||
|
||||
micp_inst = &micp_insts[bt_conn_index(conn)];
|
||||
mic_ctlr = &mic_ctlrs[bt_conn_index(conn)];
|
||||
|
||||
if (data != NULL) {
|
||||
if (length == sizeof(*mute_val)) {
|
||||
|
@ -51,7 +67,7 @@ static uint8_t mute_notify_handler(struct bt_conn *conn,
|
|||
BT_DBG("Mute %u", *mute_val);
|
||||
if (micp_mic_ctlr_cb != NULL &&
|
||||
micp_mic_ctlr_cb->mute != NULL) {
|
||||
micp_mic_ctlr_cb->mute(micp_inst, 0, *mute_val);
|
||||
micp_mic_ctlr_cb->mute(mic_ctlr, 0, *mute_val);
|
||||
}
|
||||
} else {
|
||||
BT_DBG("Invalid length %u (expected %zu)",
|
||||
|
@ -69,9 +85,9 @@ static uint8_t micp_mic_ctlr_read_mute_cb(struct bt_conn *conn, uint8_t err,
|
|||
{
|
||||
uint8_t cb_err = err;
|
||||
uint8_t mute_val = 0;
|
||||
struct bt_micp *micp_inst = &micp_insts[bt_conn_index(conn)];
|
||||
struct bt_micp_mic_ctlr *mic_ctlr = &mic_ctlrs[bt_conn_index(conn)];
|
||||
|
||||
micp_inst->cli.busy = false;
|
||||
mic_ctlr->busy = false;
|
||||
|
||||
if (err > 0) {
|
||||
BT_DBG("err: 0x%02X", err);
|
||||
|
@ -87,7 +103,7 @@ static uint8_t micp_mic_ctlr_read_mute_cb(struct bt_conn *conn, uint8_t err,
|
|||
}
|
||||
|
||||
if (micp_mic_ctlr_cb != NULL && micp_mic_ctlr_cb->mute != NULL) {
|
||||
micp_mic_ctlr_cb->mute(micp_inst, cb_err, mute_val);
|
||||
micp_mic_ctlr_cb->mute(mic_ctlr, cb_err, mute_val);
|
||||
}
|
||||
|
||||
return BT_GATT_ITER_STOP;
|
||||
|
@ -96,36 +112,36 @@ static uint8_t micp_mic_ctlr_read_mute_cb(struct bt_conn *conn, uint8_t err,
|
|||
static void micp_mic_ctlr_write_mics_mute_cb(struct bt_conn *conn, uint8_t err,
|
||||
struct bt_gatt_write_params *params)
|
||||
{
|
||||
struct bt_micp *micp_inst = &micp_insts[bt_conn_index(conn)];
|
||||
uint8_t mute_val = micp_inst->cli.mute_val_buf[0];
|
||||
struct bt_micp_mic_ctlr *mic_ctlr = &mic_ctlrs[bt_conn_index(conn)];
|
||||
uint8_t mute_val = mic_ctlr->mute_val_buf[0];
|
||||
|
||||
BT_DBG("Write %s (0x%02X)", err ? "failed" : "successful", err);
|
||||
|
||||
micp_inst->cli.busy = false;
|
||||
mic_ctlr->busy = false;
|
||||
|
||||
if (mute_val == BT_MICP_MUTE_UNMUTED) {
|
||||
if (micp_mic_ctlr_cb != NULL &&
|
||||
micp_mic_ctlr_cb->unmute_written != NULL) {
|
||||
micp_mic_ctlr_cb->unmute_written(micp_inst, err);
|
||||
micp_mic_ctlr_cb->unmute_written(mic_ctlr, err);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (micp_mic_ctlr_cb != NULL &&
|
||||
micp_mic_ctlr_cb->mute_written != NULL) {
|
||||
micp_mic_ctlr_cb->mute_written(micp_inst, err);
|
||||
micp_mic_ctlr_cb->mute_written(mic_ctlr, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
|
||||
static struct bt_micp *lookup_micp_by_aics(const struct bt_aics *aics)
|
||||
static struct bt_micp_mic_ctlr *lookup_micp_by_aics(const struct bt_aics *aics)
|
||||
{
|
||||
__ASSERT(aics != NULL, "AICS pointer cannot be NULL");
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(micp_insts); i++) {
|
||||
for (int j = 0; j < ARRAY_SIZE(micp_insts[i].cli.aics); j++) {
|
||||
if (micp_insts[i].cli.aics[j] == aics) {
|
||||
return &micp_insts[i];
|
||||
for (int i = 0; i < ARRAY_SIZE(mic_ctlrs); i++) {
|
||||
for (int j = 0; j < ARRAY_SIZE(mic_ctlrs[i].aics); j++) {
|
||||
if (mic_ctlrs[i].aics[j] == aics) {
|
||||
return &mic_ctlrs[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,19 +151,19 @@ static struct bt_micp *lookup_micp_by_aics(const struct bt_aics *aics)
|
|||
|
||||
static void aics_discover_cb(struct bt_aics *inst, int err)
|
||||
{
|
||||
struct bt_micp *micp_inst = lookup_micp_by_aics(inst);
|
||||
struct bt_micp_mic_ctlr *mic_ctlr = lookup_micp_by_aics(inst);
|
||||
|
||||
if (err == 0) {
|
||||
/* Continue discovery of included services */
|
||||
err = bt_gatt_discover(micp_inst->cli.conn,
|
||||
&micp_inst->cli.discover_params);
|
||||
err = bt_gatt_discover(mic_ctlr->conn,
|
||||
&mic_ctlr->discover_params);
|
||||
}
|
||||
|
||||
if (err != 0) {
|
||||
BT_DBG("Discover failed (err %d)", err);
|
||||
if (micp_mic_ctlr_cb != NULL &&
|
||||
micp_mic_ctlr_cb->discover != NULL) {
|
||||
micp_mic_ctlr_cb->discover(micp_inst, err, 0);
|
||||
micp_mic_ctlr_cb->discover(mic_ctlr, err, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,17 +173,17 @@ static uint8_t micp_discover_include_func(
|
|||
struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||
struct bt_gatt_discover_params *params)
|
||||
{
|
||||
struct bt_micp *micp_inst = &micp_insts[bt_conn_index(conn)];
|
||||
struct bt_micp_mic_ctlr *mic_ctlr = &mic_ctlrs[bt_conn_index(conn)];
|
||||
|
||||
if (attr == NULL) {
|
||||
BT_DBG("Discover include complete for MICP: %u AICS",
|
||||
micp_inst->cli.aics_inst_cnt);
|
||||
BT_DBG("Discover include complete for MICS: %u AICS",
|
||||
mic_ctlr->aics_inst_cnt);
|
||||
(void)memset(params, 0, sizeof(*params));
|
||||
|
||||
if (micp_mic_ctlr_cb != NULL &&
|
||||
micp_mic_ctlr_cb->discover != NULL) {
|
||||
micp_mic_ctlr_cb->discover(micp_inst, 0,
|
||||
micp_inst->cli.aics_inst_cnt);
|
||||
micp_mic_ctlr_cb->discover(mic_ctlr, 0,
|
||||
mic_ctlr->aics_inst_cnt);
|
||||
}
|
||||
|
||||
return BT_GATT_ITER_STOP;
|
||||
|
@ -181,7 +197,7 @@ static uint8_t micp_discover_include_func(
|
|||
BT_DBG("Include UUID %s", bt_uuid_str(include->uuid));
|
||||
|
||||
if (bt_uuid_cmp(include->uuid, BT_UUID_AICS) == 0 &&
|
||||
micp_inst->cli.aics_inst_cnt < CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST) {
|
||||
mic_ctlr->aics_inst_cnt < CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST) {
|
||||
uint8_t inst_idx;
|
||||
int err;
|
||||
struct bt_aics_discover_param param = {
|
||||
|
@ -192,16 +208,16 @@ static uint8_t micp_discover_include_func(
|
|||
/* Update discover params so we can continue where we
|
||||
* left off after bt_aics_discover
|
||||
*/
|
||||
micp_inst->cli.discover_params.start_handle = attr->handle + 1;
|
||||
mic_ctlr->discover_params.start_handle = attr->handle + 1;
|
||||
|
||||
inst_idx = micp_inst->cli.aics_inst_cnt++;
|
||||
err = bt_aics_discover(conn, micp_inst->cli.aics[inst_idx],
|
||||
inst_idx = mic_ctlr->aics_inst_cnt++;
|
||||
err = bt_aics_discover(conn, mic_ctlr->aics[inst_idx],
|
||||
¶m);
|
||||
if (err != 0) {
|
||||
BT_DBG("AICS Discover failed (err %d)", err);
|
||||
if (micp_mic_ctlr_cb != NULL &&
|
||||
micp_mic_ctlr_cb->discover != NULL) {
|
||||
micp_mic_ctlr_cb->discover(micp_inst, err,
|
||||
micp_mic_ctlr_cb->discover(mic_ctlr, err,
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
@ -221,33 +237,33 @@ static uint8_t micp_discover_func(struct bt_conn *conn,
|
|||
const struct bt_gatt_attr *attr,
|
||||
struct bt_gatt_discover_params *params)
|
||||
{
|
||||
struct bt_micp *micp_inst = &micp_insts[bt_conn_index(conn)];
|
||||
struct bt_micp_mic_ctlr *mic_ctlr = &mic_ctlrs[bt_conn_index(conn)];
|
||||
|
||||
if (attr == NULL) {
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("Setup complete for MICP");
|
||||
BT_DBG("Discovery complete");
|
||||
(void)memset(params, 0, sizeof(*params));
|
||||
if (CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST > 0) {
|
||||
/* Discover included services */
|
||||
micp_inst->cli.discover_params.start_handle = micp_inst->cli.start_handle;
|
||||
micp_inst->cli.discover_params.end_handle = micp_inst->cli.end_handle;
|
||||
micp_inst->cli.discover_params.type = BT_GATT_DISCOVER_INCLUDE;
|
||||
micp_inst->cli.discover_params.func = micp_discover_include_func;
|
||||
mic_ctlr->discover_params.start_handle = mic_ctlr->start_handle;
|
||||
mic_ctlr->discover_params.end_handle = mic_ctlr->end_handle;
|
||||
mic_ctlr->discover_params.type = BT_GATT_DISCOVER_INCLUDE;
|
||||
mic_ctlr->discover_params.func = micp_discover_include_func;
|
||||
|
||||
err = bt_gatt_discover(conn,
|
||||
&micp_inst->cli.discover_params);
|
||||
&mic_ctlr->discover_params);
|
||||
if (err != 0) {
|
||||
BT_DBG("Discover failed (err %d)", err);
|
||||
BT_DBG("Discover AICS failed (err %d)", err);
|
||||
if (micp_mic_ctlr_cb != NULL &&
|
||||
micp_mic_ctlr_cb->discover != NULL) {
|
||||
micp_mic_ctlr_cb->discover(micp_inst, err, 0);
|
||||
micp_mic_ctlr_cb->discover(mic_ctlr, err, 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (micp_mic_ctlr_cb != NULL &&
|
||||
micp_mic_ctlr_cb->discover != NULL) {
|
||||
micp_mic_ctlr_cb->discover(micp_inst, err, 0);
|
||||
micp_mic_ctlr_cb->discover(mic_ctlr, err, 0);
|
||||
}
|
||||
}
|
||||
return BT_GATT_ITER_STOP;
|
||||
|
@ -261,9 +277,9 @@ static uint8_t micp_discover_func(struct bt_conn *conn,
|
|||
|
||||
if (bt_uuid_cmp(chrc->uuid, BT_UUID_MICS_MUTE) == 0) {
|
||||
BT_DBG("Mute");
|
||||
micp_inst->cli.mute_handle = chrc->value_handle;
|
||||
sub_params = &micp_inst->cli.mute_sub_params;
|
||||
sub_params->disc_params = &micp_inst->cli.mute_sub_disc_params;
|
||||
mic_ctlr->mute_handle = chrc->value_handle;
|
||||
sub_params = &mic_ctlr->mute_sub_params;
|
||||
sub_params->disc_params = &mic_ctlr->mute_sub_disc_params;
|
||||
}
|
||||
|
||||
if (sub_params != NULL) {
|
||||
|
@ -271,7 +287,7 @@ static uint8_t micp_discover_func(struct bt_conn *conn,
|
|||
|
||||
/* With ccc_handle == 0 it will use auto discovery */
|
||||
sub_params->ccc_handle = 0;
|
||||
sub_params->end_handle = micp_inst->cli.end_handle;
|
||||
sub_params->end_handle = mic_ctlr->end_handle;
|
||||
sub_params->value = BT_GATT_CCC_NOTIFY;
|
||||
sub_params->value_handle = chrc->value_handle;
|
||||
sub_params->notify = mute_notify_handler;
|
||||
|
@ -294,13 +310,13 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
|
|||
const struct bt_gatt_attr *attr,
|
||||
struct bt_gatt_discover_params *params)
|
||||
{
|
||||
struct bt_micp *micp_inst = &micp_insts[bt_conn_index(conn)];
|
||||
struct bt_micp_mic_ctlr *mic_ctlr = &mic_ctlrs[bt_conn_index(conn)];
|
||||
|
||||
if (attr == NULL) {
|
||||
BT_DBG("Could not find a MICS instance on the server");
|
||||
if (micp_mic_ctlr_cb != NULL &&
|
||||
micp_mic_ctlr_cb->discover != NULL) {
|
||||
micp_mic_ctlr_cb->discover(micp_inst, -ENODATA, 0);
|
||||
micp_mic_ctlr_cb->discover(mic_ctlr, -ENODATA, 0);
|
||||
}
|
||||
return BT_GATT_ITER_STOP;
|
||||
}
|
||||
|
@ -313,22 +329,22 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
|
|||
int err;
|
||||
|
||||
BT_DBG("Primary discover complete");
|
||||
micp_inst->cli.start_handle = attr->handle + 1;
|
||||
micp_inst->cli.end_handle = prim_service->end_handle;
|
||||
mic_ctlr->start_handle = attr->handle + 1;
|
||||
mic_ctlr->end_handle = prim_service->end_handle;
|
||||
|
||||
/* Discover characteristics */
|
||||
micp_inst->cli.discover_params.uuid = NULL;
|
||||
micp_inst->cli.discover_params.start_handle = micp_inst->cli.start_handle;
|
||||
micp_inst->cli.discover_params.end_handle = micp_inst->cli.end_handle;
|
||||
micp_inst->cli.discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC;
|
||||
micp_inst->cli.discover_params.func = micp_discover_func;
|
||||
mic_ctlr->discover_params.uuid = NULL;
|
||||
mic_ctlr->discover_params.start_handle = mic_ctlr->start_handle;
|
||||
mic_ctlr->discover_params.end_handle = mic_ctlr->end_handle;
|
||||
mic_ctlr->discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC;
|
||||
mic_ctlr->discover_params.func = micp_discover_func;
|
||||
|
||||
err = bt_gatt_discover(conn, &micp_inst->cli.discover_params);
|
||||
err = bt_gatt_discover(conn, &mic_ctlr->discover_params);
|
||||
if (err != 0) {
|
||||
BT_DBG("Discover failed (err %d)", err);
|
||||
if (micp_mic_ctlr_cb != NULL &&
|
||||
micp_mic_ctlr_cb->discover != NULL) {
|
||||
micp_mic_ctlr_cb->discover(micp_inst, err, 0);
|
||||
micp_mic_ctlr_cb->discover(mic_ctlr, err, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,15 +354,15 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
|
|||
return BT_GATT_ITER_CONTINUE;
|
||||
}
|
||||
|
||||
static void micp_mic_ctlr_reset(struct bt_micp *micp)
|
||||
static void micp_mic_ctlr_reset(struct bt_micp_mic_ctlr *mic_ctlr)
|
||||
{
|
||||
micp->cli.start_handle = 0;
|
||||
micp->cli.end_handle = 0;
|
||||
micp->cli.mute_handle = 0;
|
||||
micp->cli.aics_inst_cnt = 0;
|
||||
mic_ctlr->start_handle = 0;
|
||||
mic_ctlr->end_handle = 0;
|
||||
mic_ctlr->mute_handle = 0;
|
||||
mic_ctlr->aics_inst_cnt = 0;
|
||||
|
||||
if (micp->cli.conn != NULL) {
|
||||
struct bt_conn *conn = micp->cli.conn;
|
||||
if (mic_ctlr->conn != NULL) {
|
||||
struct bt_conn *conn = mic_ctlr->conn;
|
||||
|
||||
/* It's okay if this fails. In case of disconnect, we can't
|
||||
* unsubscribe and it will just fail.
|
||||
|
@ -354,19 +370,19 @@ static void micp_mic_ctlr_reset(struct bt_micp *micp)
|
|||
* function, we will unsubscribe (regardless of bonding state)
|
||||
* to accommodate the new discovery values.
|
||||
*/
|
||||
(void)bt_gatt_unsubscribe(conn, &micp->cli.mute_sub_params);
|
||||
(void)bt_gatt_unsubscribe(conn, &mic_ctlr->mute_sub_params);
|
||||
|
||||
bt_conn_unref(conn);
|
||||
micp->cli.conn = NULL;
|
||||
mic_ctlr->conn = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void disconnected(struct bt_conn *conn, uint8_t reason)
|
||||
{
|
||||
struct bt_micp *micp = &micp_insts[bt_conn_index(conn)];
|
||||
struct bt_micp_mic_ctlr *mic_ctlr = &mic_ctlrs[bt_conn_index(conn)];
|
||||
|
||||
if (micp->cli.conn == conn) {
|
||||
micp_mic_ctlr_reset(micp);
|
||||
if (mic_ctlr->conn == conn) {
|
||||
micp_mic_ctlr_reset(mic_ctlr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -374,9 +390,9 @@ BT_CONN_CB_DEFINE(conn_callbacks) = {
|
|||
.disconnected = disconnected,
|
||||
};
|
||||
|
||||
int bt_micp_mic_ctlr_discover(struct bt_conn *conn, struct bt_micp **micp)
|
||||
int bt_micp_mic_ctlr_discover(struct bt_conn *conn, struct bt_micp_mic_ctlr **mic_ctlr_out)
|
||||
{
|
||||
struct bt_micp *micp_inst;
|
||||
struct bt_micp_mic_ctlr *mic_ctlr;
|
||||
int err;
|
||||
|
||||
/*
|
||||
|
@ -394,24 +410,24 @@ int bt_micp_mic_ctlr_discover(struct bt_conn *conn, struct bt_micp **micp)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
micp_inst = &micp_insts[bt_conn_index(conn)];
|
||||
mic_ctlr = &mic_ctlrs[bt_conn_index(conn)];
|
||||
|
||||
(void)memset(&micp_inst->cli.discover_params, 0,
|
||||
sizeof(micp_inst->cli.discover_params));
|
||||
micp_mic_ctlr_reset(micp_inst);
|
||||
(void)memset(&mic_ctlr->discover_params, 0,
|
||||
sizeof(mic_ctlr->discover_params));
|
||||
micp_mic_ctlr_reset(mic_ctlr);
|
||||
|
||||
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
|
||||
static bool initialized;
|
||||
|
||||
if (!initialized) {
|
||||
for (int i = 0; i < ARRAY_SIZE(micp_inst->cli.aics); i++) {
|
||||
micp_inst->cli.aics[i] = bt_aics_client_free_instance_get();
|
||||
for (int i = 0; i < ARRAY_SIZE(mic_ctlr->aics); i++) {
|
||||
mic_ctlr->aics[i] = bt_aics_client_free_instance_get();
|
||||
|
||||
if (micp_inst->cli.aics[i] == NULL) {
|
||||
if (mic_ctlr->aics[i] == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
bt_aics_client_cb_register(micp_inst->cli.aics[i],
|
||||
bt_aics_client_cb_register(mic_ctlr->aics[i],
|
||||
&micp_mic_ctlr_cb->aics_cb);
|
||||
}
|
||||
}
|
||||
|
@ -419,17 +435,16 @@ int bt_micp_mic_ctlr_discover(struct bt_conn *conn, struct bt_micp **micp)
|
|||
initialized = true;
|
||||
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
|
||||
|
||||
micp_inst->cli.conn = bt_conn_ref(conn);
|
||||
micp_inst->client_instance = true;
|
||||
micp_inst->cli.discover_params.func = primary_discover_func;
|
||||
micp_inst->cli.discover_params.uuid = mics_uuid;
|
||||
micp_inst->cli.discover_params.type = BT_GATT_DISCOVER_PRIMARY;
|
||||
micp_inst->cli.discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE;
|
||||
micp_inst->cli.discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
|
||||
mic_ctlr->conn = bt_conn_ref(conn);
|
||||
mic_ctlr->discover_params.func = primary_discover_func;
|
||||
mic_ctlr->discover_params.uuid = mics_uuid;
|
||||
mic_ctlr->discover_params.type = BT_GATT_DISCOVER_PRIMARY;
|
||||
mic_ctlr->discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE;
|
||||
mic_ctlr->discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
|
||||
|
||||
err = bt_gatt_discover(conn, &micp_inst->cli.discover_params);
|
||||
err = bt_gatt_discover(conn, &mic_ctlr->discover_params);
|
||||
if (err == 0) {
|
||||
*micp = micp_inst;
|
||||
*mic_ctlr_out = mic_ctlr;
|
||||
}
|
||||
|
||||
return err;
|
||||
|
@ -450,9 +465,9 @@ int bt_micp_mic_ctlr_cb_register(struct bt_micp_mic_ctlr_cb *cb)
|
|||
aics_cb = &cb->aics_cb;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(micp_insts); i++) {
|
||||
for (int j = 0; j < ARRAY_SIZE(micp_insts[i].cli.aics); j++) {
|
||||
struct bt_aics *aics = micp_insts[i].cli.aics[j];
|
||||
for (int i = 0; i < ARRAY_SIZE(mic_ctlrs); i++) {
|
||||
for (int j = 0; j < ARRAY_SIZE(mic_ctlrs[i].aics); j++) {
|
||||
struct bt_aics *aics = mic_ctlrs[i].aics[j];
|
||||
|
||||
if (aics != NULL) {
|
||||
bt_aics_client_cb_register(aics, aics_cb);
|
||||
|
@ -466,11 +481,11 @@ int bt_micp_mic_ctlr_cb_register(struct bt_micp_mic_ctlr_cb *cb)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int bt_micp_mic_ctlr_included_get(struct bt_micp *micp,
|
||||
int bt_micp_mic_ctlr_included_get(struct bt_micp_mic_ctlr *mic_ctlr,
|
||||
struct bt_micp_included *included)
|
||||
{
|
||||
CHECKIF(micp == NULL) {
|
||||
BT_DBG("NULL micp");
|
||||
CHECKIF(mic_ctlr == NULL) {
|
||||
BT_DBG("NULL mic_ctlr");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -478,100 +493,95 @@ int bt_micp_mic_ctlr_included_get(struct bt_micp *micp,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
included->aics_cnt = micp->cli.aics_inst_cnt;
|
||||
included->aics = micp->cli.aics;
|
||||
included->aics_cnt = mic_ctlr->aics_inst_cnt;
|
||||
included->aics = mic_ctlr->aics;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_micp_mic_ctlr_conn_get(const struct bt_micp *micp, struct bt_conn **conn)
|
||||
int bt_micp_mic_ctlr_conn_get(const struct bt_micp_mic_ctlr *mic_ctlr, struct bt_conn **conn)
|
||||
{
|
||||
CHECKIF(micp == NULL) {
|
||||
BT_DBG("NULL micp pointer");
|
||||
CHECKIF(mic_ctlr == NULL) {
|
||||
BT_DBG("NULL mic_ctlr pointer");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!micp->client_instance) {
|
||||
BT_DBG("micp pointer shall be client instance");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (micp->cli.conn == NULL) {
|
||||
BT_DBG("micp pointer not associated with a connection. "
|
||||
if (mic_ctlr->conn == NULL) {
|
||||
BT_DBG("mic_ctlr pointer not associated with a connection. "
|
||||
"Do discovery first");
|
||||
return -ENOTCONN;
|
||||
}
|
||||
|
||||
*conn = micp->cli.conn;
|
||||
*conn = mic_ctlr->conn;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_micp_mic_ctlr_mute_get(struct bt_micp *micp)
|
||||
int bt_micp_mic_ctlr_mute_get(struct bt_micp_mic_ctlr *mic_ctlr)
|
||||
{
|
||||
int err;
|
||||
|
||||
CHECKIF(micp == NULL) {
|
||||
BT_DBG("NULL micp");
|
||||
CHECKIF(mic_ctlr == NULL) {
|
||||
BT_DBG("NULL mic_ctlr");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (micp->cli.mute_handle == 0) {
|
||||
if (mic_ctlr->mute_handle == 0) {
|
||||
BT_DBG("Handle not set");
|
||||
return -EINVAL;
|
||||
} else if (micp->cli.busy) {
|
||||
} else if (mic_ctlr->busy) {
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
micp->cli.read_params.func = micp_mic_ctlr_read_mute_cb;
|
||||
micp->cli.read_params.handle_count = 1;
|
||||
micp->cli.read_params.single.handle = micp->cli.mute_handle;
|
||||
micp->cli.read_params.single.offset = 0U;
|
||||
mic_ctlr->read_params.func = micp_mic_ctlr_read_mute_cb;
|
||||
mic_ctlr->read_params.handle_count = 1;
|
||||
mic_ctlr->read_params.single.handle = mic_ctlr->mute_handle;
|
||||
mic_ctlr->read_params.single.offset = 0U;
|
||||
|
||||
err = bt_gatt_read(micp->cli.conn, &micp->cli.read_params);
|
||||
err = bt_gatt_read(mic_ctlr->conn, &mic_ctlr->read_params);
|
||||
if (err == 0) {
|
||||
micp->cli.busy = true;
|
||||
mic_ctlr->busy = true;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int bt_micp_mic_ctlr_write_mute(struct bt_micp *micp, bool mute)
|
||||
int bt_micp_mic_ctlr_write_mute(struct bt_micp_mic_ctlr *mic_ctlr, bool mute)
|
||||
{
|
||||
int err;
|
||||
|
||||
CHECKIF(micp == NULL) {
|
||||
BT_DBG("NULL micp");
|
||||
CHECKIF(mic_ctlr == NULL) {
|
||||
BT_DBG("NULL mic_ctlr");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (micp->cli.mute_handle == 0) {
|
||||
if (mic_ctlr->mute_handle == 0) {
|
||||
BT_DBG("Handle not set");
|
||||
return -EINVAL;
|
||||
} else if (micp->cli.busy) {
|
||||
} else if (mic_ctlr->busy) {
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
micp->cli.mute_val_buf[0] = mute;
|
||||
micp->cli.write_params.offset = 0;
|
||||
micp->cli.write_params.data = micp->cli.mute_val_buf;
|
||||
micp->cli.write_params.length = sizeof(mute);
|
||||
micp->cli.write_params.handle = micp->cli.mute_handle;
|
||||
micp->cli.write_params.func = micp_mic_ctlr_write_mics_mute_cb;
|
||||
mic_ctlr->mute_val_buf[0] = mute;
|
||||
mic_ctlr->write_params.offset = 0;
|
||||
mic_ctlr->write_params.data = mic_ctlr->mute_val_buf;
|
||||
mic_ctlr->write_params.length = sizeof(mute);
|
||||
mic_ctlr->write_params.handle = mic_ctlr->mute_handle;
|
||||
mic_ctlr->write_params.func = micp_mic_ctlr_write_mics_mute_cb;
|
||||
|
||||
err = bt_gatt_write(micp->cli.conn, &micp->cli.write_params);
|
||||
err = bt_gatt_write(mic_ctlr->conn, &mic_ctlr->write_params);
|
||||
if (err == 0) {
|
||||
micp->cli.busy = true;
|
||||
mic_ctlr->busy = true;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int bt_micp_mic_ctlr_mute(struct bt_micp *micp)
|
||||
int bt_micp_mic_ctlr_mute(struct bt_micp_mic_ctlr *mic_ctlr)
|
||||
{
|
||||
return bt_micp_mic_ctlr_write_mute(micp, true);
|
||||
return bt_micp_mic_ctlr_write_mute(mic_ctlr, true);
|
||||
}
|
||||
|
||||
int bt_micp_mic_ctlr_unmute(struct bt_micp *micp)
|
||||
int bt_micp_mic_ctlr_unmute(struct bt_micp_mic_ctlr *mic_ctlr)
|
||||
{
|
||||
return bt_micp_mic_ctlr_write_mute(micp, false);
|
||||
return bt_micp_mic_ctlr_write_mute(mic_ctlr, false);
|
||||
}
|
||||
|
|
|
@ -19,13 +19,18 @@
|
|||
#include <zephyr/bluetooth/audio/micp.h>
|
||||
#include <zephyr/bluetooth/audio/aics.h>
|
||||
|
||||
#include "micp_internal.h"
|
||||
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_MICP_MIC_DEV)
|
||||
#define LOG_MODULE_NAME bt_micp
|
||||
#include "common/log.h"
|
||||
|
||||
static struct bt_micp micp_inst;
|
||||
struct bt_micp_server {
|
||||
uint8_t mute;
|
||||
struct bt_micp_mic_dev_cb *cb;
|
||||
struct bt_gatt_service *service_p;
|
||||
struct bt_aics *aics_insts[CONFIG_BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT];
|
||||
};
|
||||
|
||||
static struct bt_micp_server micp_inst;
|
||||
|
||||
static void mute_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
|
||||
{
|
||||
|
@ -36,10 +41,10 @@ static ssize_t read_mute(struct bt_conn *conn,
|
|||
const struct bt_gatt_attr *attr, void *buf,
|
||||
uint16_t len, uint16_t offset)
|
||||
{
|
||||
BT_DBG("Mute %u", micp_inst.srv.mute);
|
||||
BT_DBG("Mute %u", micp_inst.mute);
|
||||
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset,
|
||||
&micp_inst.srv.mute, sizeof(micp_inst.srv.mute));
|
||||
&micp_inst.mute, sizeof(micp_inst.mute));
|
||||
}
|
||||
|
||||
static ssize_t write_mute(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||
|
@ -52,7 +57,7 @@ static ssize_t write_mute(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
|||
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
|
||||
}
|
||||
|
||||
if (len != sizeof(micp_inst.srv.mute)) {
|
||||
if (len != sizeof(micp_inst.mute)) {
|
||||
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
|
||||
}
|
||||
|
||||
|
@ -61,21 +66,21 @@ static ssize_t write_mute(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
|||
return BT_GATT_ERR(BT_MICP_ERR_VAL_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
if (conn != NULL && micp_inst.srv.mute == BT_MICP_MUTE_DISABLED) {
|
||||
if (conn != NULL && micp_inst.mute == BT_MICP_MUTE_DISABLED) {
|
||||
return BT_GATT_ERR(BT_MICP_ERR_MUTE_DISABLED);
|
||||
}
|
||||
|
||||
BT_DBG("%u", *val);
|
||||
|
||||
if (*val != micp_inst.srv.mute) {
|
||||
micp_inst.srv.mute = *val;
|
||||
if (*val != micp_inst.mute) {
|
||||
micp_inst.mute = *val;
|
||||
|
||||
bt_gatt_notify_uuid(NULL, BT_UUID_MICS_MUTE,
|
||||
micp_inst.srv.service_p->attrs,
|
||||
&micp_inst.srv.mute, sizeof(micp_inst.srv.mute));
|
||||
micp_inst.service_p->attrs,
|
||||
&micp_inst.mute, sizeof(micp_inst.mute));
|
||||
|
||||
if (micp_inst.srv.cb != NULL && micp_inst.srv.cb->mute != NULL) {
|
||||
micp_inst.srv.cb->mute(micp_inst.srv.mute);
|
||||
if (micp_inst.cb != NULL && micp_inst.cb->mute != NULL) {
|
||||
micp_inst.cb->mute(micp_inst.mute);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,20 +117,20 @@ static int prepare_aics_inst(struct bt_micp_mic_dev_register_param *param)
|
|||
|
||||
for (j = 0, i = 0; i < ARRAY_SIZE(mics_attrs); i++) {
|
||||
if (bt_uuid_cmp(mics_attrs[i].uuid, BT_UUID_GATT_INCLUDE) == 0) {
|
||||
micp_inst.srv.aics_insts[j] = bt_aics_free_instance_get();
|
||||
if (micp_inst.srv.aics_insts[j] == NULL) {
|
||||
micp_inst.aics_insts[j] = bt_aics_free_instance_get();
|
||||
if (micp_inst.aics_insts[j] == NULL) {
|
||||
BT_DBG("Could not get free AICS instances[%u]", j);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
err = bt_aics_register(micp_inst.srv.aics_insts[j],
|
||||
err = bt_aics_register(micp_inst.aics_insts[j],
|
||||
¶m->aics_param[j]);
|
||||
if (err != 0) {
|
||||
BT_DBG("Could not register AICS instance[%u]: %d", j, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
mics_attrs[i].user_data = bt_aics_svc_decl_get(micp_inst.srv.aics_insts[j]);
|
||||
mics_attrs[i].user_data = bt_aics_svc_decl_get(micp_inst.aics_insts[j]);
|
||||
j++;
|
||||
|
||||
if (j == CONFIG_BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT) {
|
||||
|
@ -163,14 +168,14 @@ int bt_micp_mic_dev_register(struct bt_micp_mic_dev_register_param *param)
|
|||
#endif /* CONFIG_BT_MICP_MIC_DEV_AICS */
|
||||
|
||||
mics_svc = (struct bt_gatt_service)BT_GATT_SERVICE(mics_attrs);
|
||||
micp_inst.srv.service_p = &mics_svc;
|
||||
micp_inst.service_p = &mics_svc;
|
||||
err = bt_gatt_service_register(&mics_svc);
|
||||
|
||||
if (err != 0) {
|
||||
BT_ERR("MICS service register failed: %d", err);
|
||||
}
|
||||
|
||||
micp_inst.srv.cb = param->cb;
|
||||
micp_inst.cb = param->cb;
|
||||
|
||||
registered = true;
|
||||
|
||||
|
@ -195,8 +200,8 @@ int bt_micp_mic_dev_included_get(struct bt_micp_included *included)
|
|||
}
|
||||
|
||||
#if defined(CONFIG_BT_MICP_MIC_DEV_AICS)
|
||||
included->aics_cnt = ARRAY_SIZE(micp_inst.srv.aics_insts);
|
||||
included->aics = micp_inst.srv.aics_insts;
|
||||
included->aics_cnt = ARRAY_SIZE(micp_inst.aics_insts);
|
||||
included->aics = micp_inst.aics_insts;
|
||||
#endif /* CONFIG_BT_MICP_MIC_DEV_AICS */
|
||||
|
||||
return 0;
|
||||
|
@ -220,8 +225,8 @@ int bt_micp_mic_dev_mute(void)
|
|||
|
||||
int bt_micp_mic_dev_mute_get(void)
|
||||
{
|
||||
if (micp_inst.srv.cb && micp_inst.srv.cb->mute) {
|
||||
micp_inst.srv.cb->mute(micp_inst.srv.mute);
|
||||
if (micp_inst.cb && micp_inst.cb->mute) {
|
||||
micp_inst.cb->mute(micp_inst.mute);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/** @file
|
||||
* @brief Bluetooth MICP client shell.
|
||||
* @brief Bluetooth MICP Microphone Controller shell.
|
||||
*
|
||||
* Copyright (c) 2020 Bose Corporation
|
||||
* Copyright (c) 2020-2022 Nordic Semiconductor ASA
|
||||
|
@ -16,28 +16,31 @@
|
|||
|
||||
#include "bt.h"
|
||||
|
||||
static struct bt_micp *micp;
|
||||
static struct bt_micp_mic_ctlr *mic_ctlr;
|
||||
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
|
||||
static struct bt_micp_included micp_included;
|
||||
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
|
||||
|
||||
static void micp_mic_ctlr_discover_cb(struct bt_micp *micp, int err, uint8_t aics_count)
|
||||
static void micp_mic_ctlr_discover_cb(struct bt_micp_mic_ctlr *mic_ctlr,
|
||||
int err, uint8_t aics_count)
|
||||
{
|
||||
if (err != 0) {
|
||||
shell_error(ctx_shell, "MICP discover failed (%d)", err);
|
||||
shell_error(ctx_shell, "Discovery failed (%d)", err);
|
||||
} else {
|
||||
shell_print(ctx_shell, "MICP discover done with %u AICS",
|
||||
shell_print(ctx_shell, "Discovery done with %u AICS",
|
||||
aics_count);
|
||||
|
||||
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
|
||||
if (bt_micp_mic_ctlr_included_get(micp, &micp_included) != 0) {
|
||||
shell_error(ctx_shell, "Could not get MICP context");
|
||||
if (bt_micp_mic_ctlr_included_get(mic_ctlr,
|
||||
&micp_included) != 0) {
|
||||
shell_error(ctx_shell, "Could not get included services");
|
||||
}
|
||||
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
|
||||
}
|
||||
}
|
||||
|
||||
static void micp_mic_ctlr_mute_written_cb(struct bt_micp *micp, int err)
|
||||
static void micp_mic_ctlr_mute_written_cb(struct bt_micp_mic_ctlr *mic_ctlr,
|
||||
int err)
|
||||
{
|
||||
if (err != 0) {
|
||||
shell_error(ctx_shell, "Mute write failed (%d)", err);
|
||||
|
@ -46,7 +49,8 @@ static void micp_mic_ctlr_mute_written_cb(struct bt_micp *micp, int err)
|
|||
}
|
||||
}
|
||||
|
||||
static void micp_mic_ctlr_unmute_written_cb(struct bt_micp *micp, int err)
|
||||
static void micp_mic_ctlr_unmute_written_cb(struct bt_micp_mic_ctlr *mic_ctlr,
|
||||
int err)
|
||||
{
|
||||
if (err != 0) {
|
||||
shell_error(ctx_shell, "Unmute write failed (%d)", err);
|
||||
|
@ -55,7 +59,8 @@ static void micp_mic_ctlr_unmute_written_cb(struct bt_micp *micp, int err)
|
|||
}
|
||||
}
|
||||
|
||||
static void micp_mic_ctlr_mute_cb(struct bt_micp *micp, int err, uint8_t mute)
|
||||
static void micp_mic_ctlr_mute_cb(struct bt_micp_mic_ctlr *mic_ctlr, int err,
|
||||
uint8_t mute)
|
||||
{
|
||||
if (err != 0) {
|
||||
shell_error(ctx_shell, "Mute get failed (%d)", err);
|
||||
|
@ -228,7 +233,7 @@ static int cmd_micp_mic_ctlr_discover(const struct shell *sh, size_t argc,
|
|||
return -ENOTCONN;
|
||||
}
|
||||
|
||||
result = bt_micp_mic_ctlr_discover(default_conn, &micp);
|
||||
result = bt_micp_mic_ctlr_discover(default_conn, &mic_ctlr);
|
||||
if (result != 0) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
}
|
||||
|
@ -241,11 +246,11 @@ static int cmd_micp_mic_ctlr_mute_get(const struct shell *sh, size_t argc,
|
|||
{
|
||||
int result;
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
result = bt_micp_mic_ctlr_mute_get(micp);
|
||||
result = bt_micp_mic_ctlr_mute_get(mic_ctlr);
|
||||
|
||||
if (result != 0) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
|
@ -259,11 +264,11 @@ static int cmd_micp_mic_ctlr_mute(const struct shell *sh, size_t argc,
|
|||
{
|
||||
int result;
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
result = bt_micp_mic_ctlr_mute(micp);
|
||||
result = bt_micp_mic_ctlr_mute(mic_ctlr);
|
||||
|
||||
if (result != 0) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
|
@ -277,11 +282,11 @@ static int cmd_micp_mic_ctlr_unmute(const struct shell *sh, size_t argc,
|
|||
{
|
||||
int result;
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
result = bt_micp_mic_ctlr_unmute(micp);
|
||||
result = bt_micp_mic_ctlr_unmute(mic_ctlr);
|
||||
|
||||
if (result != 0) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
|
@ -303,7 +308,7 @@ static int cmd_micp_mic_ctlr_aics_input_state_get(const struct shell *sh,
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
@ -327,7 +332,7 @@ static int cmd_micp_mic_ctlr_aics_gain_setting_get(const struct shell *sh,
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
@ -351,7 +356,7 @@ static int cmd_micp_mic_ctlr_aics_input_type_get(const struct shell *sh,
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
@ -375,7 +380,7 @@ static int cmd_micp_mic_ctlr_aics_input_status_get(const struct shell *sh,
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
@ -399,7 +404,7 @@ static int cmd_micp_mic_ctlr_aics_input_unmute(const struct shell *sh,
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
@ -423,7 +428,7 @@ static int cmd_micp_mic_ctlr_aics_input_mute(const struct shell *sh,
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
@ -447,7 +452,7 @@ static int cmd_micp_mic_ctlr_aics_manual_input_gain_set(const struct shell *sh,
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
@ -472,7 +477,7 @@ static int cmd_micp_mic_ctlr_aics_automatic_input_gain_set(const struct shell *s
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
@ -503,7 +508,7 @@ static int cmd_micp_mic_ctlr_aics_gain_set(const struct shell *sh, size_t argc,
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
@ -527,7 +532,7 @@ static int cmd_micp_mic_ctlr_aics_input_description_get(const struct shell *sh,
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
@ -552,7 +557,7 @@ static int cmd_micp_mic_ctlr_aics_input_description_set(const struct shell *sh,
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (micp == NULL) {
|
||||
if (mic_ctlr == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
@ -583,13 +588,13 @@ SHELL_STATIC_SUBCMD_SET_CREATE(micp_mic_ctlr_cmds,
|
|||
"Discover MICS on remote device",
|
||||
cmd_micp_mic_ctlr_discover, 1, 0),
|
||||
SHELL_CMD_ARG(mute_get, NULL,
|
||||
"Read the mute state of the MICP server.",
|
||||
"Read the mute state of the Microphone Device server.",
|
||||
cmd_micp_mic_ctlr_mute_get, 1, 0),
|
||||
SHELL_CMD_ARG(mute, NULL,
|
||||
"Mute the MICP server",
|
||||
"Mute the Microphone Device server",
|
||||
cmd_micp_mic_ctlr_mute, 1, 0),
|
||||
SHELL_CMD_ARG(unmute, NULL,
|
||||
"Unmute the MICP server",
|
||||
"Unmute the Microphone Device server",
|
||||
cmd_micp_mic_ctlr_unmute, 1, 0),
|
||||
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
|
||||
SHELL_CMD_ARG(aics_input_state_get, NULL,
|
||||
|
@ -634,5 +639,5 @@ SHELL_STATIC_SUBCMD_SET_CREATE(micp_mic_ctlr_cmds,
|
|||
);
|
||||
|
||||
SHELL_CMD_ARG_REGISTER(micp_mic_ctlr, &micp_mic_ctlr_cmds,
|
||||
"Bluetooth MICP client shell commands",
|
||||
"Bluetooth Microphone Controller shell commands",
|
||||
cmd_micp_mic_ctlr, 1, 1);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
extern enum bst_result_t bst_result;
|
||||
|
||||
static struct bt_micp *micp;
|
||||
static struct bt_micp_mic_ctlr *mic_ctlr;
|
||||
static struct bt_micp_included micp_included;
|
||||
static volatile bool g_bt_init;
|
||||
static volatile bool g_is_connected;
|
||||
|
@ -119,11 +119,12 @@ static void aics_write_cb(struct bt_aics *inst, int err)
|
|||
g_write_complete = true;
|
||||
}
|
||||
|
||||
static void micp_mic_ctlr_discover_cb(struct bt_micp *micp, int err,
|
||||
static void micp_mic_ctlr_discover_cb(struct bt_micp_mic_ctlr *mic_ctlr,
|
||||
int err,
|
||||
uint8_t aics_count)
|
||||
{
|
||||
if (err != 0) {
|
||||
FAIL("MICP could not be discovered (%d)\n", err);
|
||||
FAIL("MICS could not be discovered (%d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -131,30 +132,33 @@ static void micp_mic_ctlr_discover_cb(struct bt_micp *micp, int err,
|
|||
g_discovery_complete = true;
|
||||
}
|
||||
|
||||
static void micp_mic_ctlr_mute_written_cb(struct bt_micp *micp, int err)
|
||||
static void micp_mic_ctlr_mute_written_cb(struct bt_micp_mic_ctlr *mic_ctlr,
|
||||
int err)
|
||||
{
|
||||
if (err != 0) {
|
||||
FAIL("MICP mute write failed (%d)\n", err);
|
||||
FAIL("mic_ctlr mute write failed (%d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
g_write_complete = true;
|
||||
}
|
||||
|
||||
static void micp_mic_ctlr_unmute_written_cb(struct bt_micp *micp, int err)
|
||||
static void micp_mic_ctlr_unmute_written_cb(struct bt_micp_mic_ctlr *mic_ctlr,
|
||||
int err)
|
||||
{
|
||||
if (err != 0) {
|
||||
FAIL("MICP unmute write failed (%d)\n", err);
|
||||
FAIL("mic_ctlr unmute write failed (%d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
g_write_complete = true;
|
||||
}
|
||||
|
||||
static void micp_mic_ctlr_mute_cb(struct bt_micp *micp, int err, uint8_t mute)
|
||||
static void micp_mic_ctlr_mute_cb(struct bt_micp_mic_ctlr *mic_ctlr, int err,
|
||||
uint8_t mute)
|
||||
{
|
||||
if (err != 0) {
|
||||
FAIL("MICP mute read failed (%d)\n", err);
|
||||
FAIL("mic_ctlr mute read failed (%d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -388,22 +392,22 @@ static void test_main(void)
|
|||
printk("Scanning successfully started\n");
|
||||
WAIT_FOR_COND(g_is_connected);
|
||||
|
||||
err = bt_micp_mic_ctlr_discover(default_conn, &micp);
|
||||
err = bt_micp_mic_ctlr_discover(default_conn, &mic_ctlr);
|
||||
if (err != 0) {
|
||||
FAIL("Failed to discover MICP %d", err);
|
||||
FAIL("Failed to discover MICS %d", err);
|
||||
}
|
||||
WAIT_FOR_COND(g_discovery_complete);
|
||||
|
||||
err = bt_micp_mic_ctlr_included_get(micp, &micp_included);
|
||||
err = bt_micp_mic_ctlr_included_get(mic_ctlr, &micp_included);
|
||||
if (err != 0) {
|
||||
FAIL("Failed to get MICP context (err %d)\n", err);
|
||||
FAIL("Failed to get mic_ctlr context (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Getting MICP client conn\n");
|
||||
err = bt_micp_mic_ctlr_conn_get(micp, &cached_conn);
|
||||
printk("Getting mic_ctlr conn\n");
|
||||
err = bt_micp_mic_ctlr_conn_get(mic_ctlr, &cached_conn);
|
||||
if (err != 0) {
|
||||
FAIL("Failed to get MICP client conn (err %d)\n", err);
|
||||
FAIL("Failed to get mic_ctlr conn (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
if (cached_conn != default_conn) {
|
||||
|
@ -411,37 +415,37 @@ static void test_main(void)
|
|||
return;
|
||||
}
|
||||
|
||||
printk("Getting MICP mute state\n");
|
||||
printk("Getting mic_ctlr mute state\n");
|
||||
g_cb = false;
|
||||
err = bt_micp_mic_ctlr_mute_get(micp);
|
||||
err = bt_micp_mic_ctlr_mute_get(mic_ctlr);
|
||||
if (err != 0) {
|
||||
FAIL("Could not get MICP mute state (err %d)\n", err);
|
||||
FAIL("Could not get mic_ctlr mute state (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
WAIT_FOR_COND(g_cb);
|
||||
printk("MICP mute state received\n");
|
||||
printk("mic_ctlr mute state received\n");
|
||||
|
||||
printk("Muting MICP\n");
|
||||
printk("Muting mic_ctlr\n");
|
||||
expected_mute = 1;
|
||||
g_write_complete = g_cb = false;
|
||||
err = bt_micp_mic_ctlr_mute(micp);
|
||||
err = bt_micp_mic_ctlr_mute(mic_ctlr);
|
||||
if (err != 0) {
|
||||
FAIL("Could not mute MICP (err %d)\n", err);
|
||||
FAIL("Could not mute mic_ctlr (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
WAIT_FOR_COND(g_mute == expected_mute && g_cb && g_write_complete);
|
||||
printk("MICP muted\n");
|
||||
printk("mic_ctlr muted\n");
|
||||
|
||||
printk("Unmuting MICP\n");
|
||||
printk("Unmuting mic_ctlr\n");
|
||||
expected_mute = 0;
|
||||
g_write_complete = g_cb = false;
|
||||
err = bt_micp_mic_ctlr_unmute(micp);
|
||||
err = bt_micp_mic_ctlr_unmute(mic_ctlr);
|
||||
if (err != 0) {
|
||||
FAIL("Could not unmute MICP (err %d)\n", err);
|
||||
FAIL("Could not unmute mic_ctlr (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
WAIT_FOR_COND(g_mute == expected_mute && g_cb && g_write_complete);
|
||||
printk("MICP unmuted\n");
|
||||
printk("mic_ctlr unmuted\n");
|
||||
|
||||
if (CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST > 0 && g_aics_count > 0) {
|
||||
if (test_aics()) {
|
||||
|
@ -449,7 +453,7 @@ static void test_main(void)
|
|||
}
|
||||
}
|
||||
|
||||
PASS("MICP client Passed\n");
|
||||
PASS("mic_ctlr Passed\n");
|
||||
}
|
||||
|
||||
static const struct bst_test_instance test_micp[] = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue