Bluetooth: Audio: MICS introduce opaque bt_mics struct
Add a bt_mics struct that represents a MICS instance, either a local (server) or remote (client) instance. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
f5b0f92bb7
commit
d6fd79f65d
6 changed files with 63 additions and 42 deletions
|
@ -41,6 +41,9 @@ extern "C" {
|
|||
#define BT_MICS_MUTE_MUTED 0x01
|
||||
#define BT_MICS_MUTE_DISABLED 0x02
|
||||
|
||||
/** @brief Opaque Microphone Input Control Service instance. */
|
||||
struct bt_mics;
|
||||
|
||||
/** @brief Register parameters structure for Microphone Input Control Service */
|
||||
struct bt_mics_register_param {
|
||||
/** Register parameter structure for Audio Input Control Services */
|
||||
|
@ -71,10 +74,12 @@ struct bt_mics_included {
|
|||
* This can only be done as the server.
|
||||
*
|
||||
* @param param Pointer to an initialization structure.
|
||||
* @param[out] mics Pointer to the registered Microphone Input Control Service.
|
||||
*
|
||||
* @return 0 if success, errno on failure.
|
||||
*/
|
||||
int bt_mics_register(struct bt_mics_register_param *param);
|
||||
int bt_mics_register(struct bt_mics_register_param *param,
|
||||
struct bt_mics **mics);
|
||||
|
||||
/**
|
||||
* @brief Get Microphone Input Control Service included services
|
||||
|
|
|
@ -26,14 +26,8 @@
|
|||
#include "common/log.h"
|
||||
|
||||
#if defined(CONFIG_BT_MICS)
|
||||
struct mics_instance {
|
||||
uint8_t mute;
|
||||
struct bt_mics_cb *cb;
|
||||
struct bt_gatt_service *service_p;
|
||||
struct bt_aics *aics_insts[CONFIG_BT_MICS_AICS_INSTANCE_COUNT];
|
||||
};
|
||||
|
||||
static struct mics_instance mics_inst;
|
||||
static struct bt_mics_server mics_inst;
|
||||
|
||||
static void mute_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
|
||||
{
|
||||
|
@ -148,7 +142,8 @@ static int prepare_aics_inst(struct bt_mics_register_param *param)
|
|||
}
|
||||
|
||||
/****************************** PUBLIC API ******************************/
|
||||
int bt_mics_register(struct bt_mics_register_param *param)
|
||||
int bt_mics_register(struct bt_mics_register_param *param,
|
||||
struct bt_mics **mics)
|
||||
{
|
||||
int err;
|
||||
|
||||
|
@ -168,6 +163,8 @@ int bt_mics_register(struct bt_mics_register_param *param)
|
|||
|
||||
mics_inst.cb = param->cb;
|
||||
|
||||
*mics = (struct bt_mics *)&mics_inst;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,31 +20,16 @@
|
|||
#include <bluetooth/gatt.h>
|
||||
#include <bluetooth/audio/mics.h>
|
||||
|
||||
#include "mics_internal.h"
|
||||
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_MICS_CLIENT)
|
||||
#define LOG_MODULE_NAME bt_mics_client
|
||||
#include "common/log.h"
|
||||
|
||||
struct mics_instance {
|
||||
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;
|
||||
|
||||
uint8_t aics_inst_cnt;
|
||||
struct bt_aics *aics[CONFIG_BT_MICS_CLIENT_MAX_AICS_INST];
|
||||
};
|
||||
|
||||
/* Callback functions */
|
||||
static struct bt_mics_cb *mics_client_cb;
|
||||
|
||||
static struct mics_instance mics_insts[CONFIG_BT_MAX_CONN];
|
||||
static struct bt_mics_client mics_insts[CONFIG_BT_MAX_CONN];
|
||||
static struct bt_uuid *mics_uuid = BT_UUID_MICS;
|
||||
|
||||
bool bt_mics_client_valid_aics_inst(struct bt_conn *conn, struct bt_aics *aics)
|
||||
|
@ -100,7 +85,7 @@ static uint8_t mics_client_read_mute_cb(struct bt_conn *conn, uint8_t err,
|
|||
{
|
||||
uint8_t cb_err = err;
|
||||
uint8_t *mute_val = NULL;
|
||||
struct mics_instance *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
struct bt_mics_client *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
|
||||
mics_inst->busy = false;
|
||||
|
||||
|
@ -127,7 +112,7 @@ static uint8_t mics_client_read_mute_cb(struct bt_conn *conn, uint8_t err,
|
|||
static void mics_client_write_mics_mute_cb(struct bt_conn *conn, uint8_t err,
|
||||
struct bt_gatt_write_params *params)
|
||||
{
|
||||
struct mics_instance *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
struct bt_mics_client *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
uint8_t mute_val = mics_inst->mute_val_buf[0];
|
||||
|
||||
BT_DBG("Write %s (0x%02X)", err ? "failed" : "successful", err);
|
||||
|
@ -151,7 +136,7 @@ static void mics_client_write_mics_mute_cb(struct bt_conn *conn, uint8_t err,
|
|||
static void aics_discover_cb(struct bt_conn *conn, struct bt_aics *inst,
|
||||
int err)
|
||||
{
|
||||
struct mics_instance *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
struct bt_mics_client *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
|
||||
if (err == 0) {
|
||||
/* Continue discovery of included services */
|
||||
|
@ -171,7 +156,7 @@ static uint8_t mics_discover_include_func(
|
|||
struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||
struct bt_gatt_discover_params *params)
|
||||
{
|
||||
struct mics_instance *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
struct bt_mics_client *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
|
||||
if (attr == NULL) {
|
||||
BT_DBG("Discover include complete for MICS: %u AICS",
|
||||
|
@ -233,7 +218,7 @@ static uint8_t mics_discover_func(struct bt_conn *conn,
|
|||
const struct bt_gatt_attr *attr,
|
||||
struct bt_gatt_discover_params *params)
|
||||
{
|
||||
struct mics_instance *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
struct bt_mics_client *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
|
||||
if (attr == NULL) {
|
||||
int err = 0;
|
||||
|
@ -306,7 +291,7 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
|
|||
const struct bt_gatt_attr *attr,
|
||||
struct bt_gatt_discover_params *params)
|
||||
{
|
||||
struct mics_instance *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
struct bt_mics_client *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
|
||||
if (attr == NULL) {
|
||||
BT_DBG("Could not find a MICS instance on the server");
|
||||
|
@ -352,7 +337,7 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
|
|||
|
||||
static void mics_client_reset(struct bt_conn *conn)
|
||||
{
|
||||
struct mics_instance *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
struct bt_mics_client *mics_inst = &mics_insts[bt_conn_index(conn)];
|
||||
|
||||
mics_inst->start_handle = 0;
|
||||
mics_inst->end_handle = 0;
|
||||
|
@ -366,7 +351,7 @@ static void mics_client_reset(struct bt_conn *conn)
|
|||
int bt_mics_discover(struct bt_conn *conn)
|
||||
{
|
||||
static bool initialized;
|
||||
struct mics_instance *mics_inst;
|
||||
struct bt_mics_client *mics_inst;
|
||||
/*
|
||||
* This will initiate a discover procedure. The procedure will do the
|
||||
* following sequence:
|
||||
|
@ -450,7 +435,7 @@ int bt_mics_client_cb_register(struct bt_mics_cb *cb)
|
|||
int bt_mics_client_included_get(struct bt_conn *conn,
|
||||
struct bt_mics_included *included)
|
||||
{
|
||||
struct mics_instance *mics_inst;
|
||||
struct bt_mics_client *mics_inst;
|
||||
|
||||
CHECKIF(conn == NULL) {
|
||||
return -EINVAL;
|
||||
|
@ -471,7 +456,7 @@ int bt_mics_client_included_get(struct bt_conn *conn,
|
|||
int bt_mics_client_mute_get(struct bt_conn *conn)
|
||||
{
|
||||
int err;
|
||||
struct mics_instance *mics_inst;
|
||||
struct bt_mics_client *mics_inst;
|
||||
|
||||
CHECKIF(conn == NULL) {
|
||||
BT_DBG("NULL conn");
|
||||
|
@ -503,7 +488,7 @@ int bt_mics_client_mute_get(struct bt_conn *conn)
|
|||
int bt_mics_client_write_mute(struct bt_conn *conn, bool mute)
|
||||
{
|
||||
int err;
|
||||
struct mics_instance *mics_inst;
|
||||
struct bt_mics_client *mics_inst;
|
||||
|
||||
CHECKIF(conn == NULL) {
|
||||
BT_DBG("NULL conn");
|
||||
|
|
|
@ -9,6 +9,38 @@
|
|||
#include <zephyr/types.h>
|
||||
#include <bluetooth/gatt.h>
|
||||
|
||||
struct bt_mics_server {
|
||||
uint8_t mute;
|
||||
struct bt_mics_cb *cb;
|
||||
struct bt_gatt_service *service_p;
|
||||
struct bt_aics *aics_insts[CONFIG_BT_MICS_AICS_INSTANCE_COUNT];
|
||||
};
|
||||
|
||||
struct bt_mics_client {
|
||||
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;
|
||||
|
||||
uint8_t aics_inst_cnt;
|
||||
struct bt_aics *aics[CONFIG_BT_MICS_CLIENT_MAX_AICS_INST];
|
||||
};
|
||||
|
||||
/* Struct used as a common type for the api */
|
||||
struct bt_mics {
|
||||
union {
|
||||
struct bt_mics_server srv;
|
||||
struct bt_mics_client cli;
|
||||
};
|
||||
};
|
||||
|
||||
int bt_mics_client_included_get(struct bt_conn *conn,
|
||||
struct bt_mics_included *included);
|
||||
int bt_mics_client_mute_get(struct bt_conn *conn);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "bt.h"
|
||||
|
||||
static struct bt_mics *mics;
|
||||
static struct bt_mics_included mics_included;
|
||||
|
||||
static void mics_mute_cb(struct bt_conn *conn, int err, uint8_t mute)
|
||||
|
@ -132,7 +133,7 @@ static int cmd_mics_param(const struct shell *sh, size_t argc, char **argv)
|
|||
|
||||
mics_param.cb = &mics_cbs;
|
||||
|
||||
result = bt_mics_register(&mics_param);
|
||||
result = bt_mics_register(&mics_param, &mics);
|
||||
if (result != 0) {
|
||||
shell_error(sh, "MICS register failed: %d", result);
|
||||
return result;
|
||||
|
|
|
@ -16,6 +16,7 @@ extern enum bst_result_t bst_result;
|
|||
#define AICS_DESC_SIZE 0
|
||||
#endif /* CONFIG_BT_AICS */
|
||||
|
||||
static struct bt_mics *mics;
|
||||
static struct bt_mics_included mics_included;
|
||||
|
||||
static volatile uint8_t g_mute;
|
||||
|
@ -346,7 +347,7 @@ static void test_server_only(void)
|
|||
}
|
||||
mics_param.cb = &mics_cb;
|
||||
|
||||
err = bt_mics_register(&mics_param);
|
||||
err = bt_mics_register(&mics_param, &mics);
|
||||
if (err != 0) {
|
||||
FAIL("MICS init failed (err %d)\n", err);
|
||||
return;
|
||||
|
@ -440,7 +441,7 @@ static void test_main(void)
|
|||
}
|
||||
mics_param.cb = &mics_cb;
|
||||
|
||||
err = bt_mics_register(&mics_param);
|
||||
err = bt_mics_register(&mics_param, &mics);
|
||||
if (err != 0) {
|
||||
FAIL("MICS init failed (err %d)\n", err);
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue