Lines Matching +full:mute +full:- +full:control

1 /*  Bluetooth MICP - Microphone Control Profile - Microphone Controller */
5 * Copyright (c) 2020-2023 Nordic Semiconductor ASA
7 * SPDX-License-Identifier: Apache-2.0
56 if (listener->mute) { in micp_mic_ctlr_mute_changed()
57 listener->mute(mic_ctlr, err, mute_val); in micp_mic_ctlr_mute_changed()
68 if (listener->unmute_written) { in micp_mic_ctlr_mute_written()
69 listener->unmute_written(mic_ctlr, err); in micp_mic_ctlr_mute_written()
72 if (listener->mute_written) { in micp_mic_ctlr_mute_written()
73 listener->mute_written(mic_ctlr, err); in micp_mic_ctlr_mute_written()
83 atomic_clear_bit(mic_ctlr->flags, BT_MICP_MIC_CTLR_FLAG_BUSY); in micp_mic_ctlr_discover_complete()
86 if (listener->discover) { in micp_mic_ctlr_discover_complete()
91 aics_cnt = mic_ctlr->aics_inst_cnt; in micp_mic_ctlr_discover_complete()
95 listener->discover(mic_ctlr, err, aics_cnt); in micp_mic_ctlr_discover_complete()
115 LOG_DBG("Mute %u", *mute_val); in mute_notify_handler()
133 atomic_clear_bit(mic_ctlr->flags, BT_MICP_MIC_CTLR_FLAG_BUSY); in micp_mic_ctlr_read_mute_cb()
140 LOG_DBG("Mute %u", mute_val); in micp_mic_ctlr_read_mute_cb()
156 uint8_t mute_val = mic_ctlr->mute_val_buf[0]; in micp_mic_ctlr_write_mics_mute_cb()
160 atomic_clear_bit(mic_ctlr->flags, BT_MICP_MIC_CTLR_FLAG_BUSY); in micp_mic_ctlr_write_mics_mute_cb()
181 static void micp_mic_ctlr_aics_state_cb(struct bt_aics *inst, int err, int8_t gain, uint8_t mute, in micp_mic_ctlr_aics_state_cb() argument
187 if (listener->aics_cb.state) { in micp_mic_ctlr_aics_state_cb()
188 listener->aics_cb.state(inst, err, gain, mute, mode); in micp_mic_ctlr_aics_state_cb()
199 if (listener->aics_cb.gain_setting) { in micp_mic_ctlr_aics_gain_setting_cb()
200 listener->aics_cb.gain_setting(inst, err, units, minimum, maximum); in micp_mic_ctlr_aics_gain_setting_cb()
210 if (listener->aics_cb.type) { in micp_mic_ctlr_aics_type_cb()
211 listener->aics_cb.type(inst, err, type); in micp_mic_ctlr_aics_type_cb()
221 if (listener->aics_cb.status) { in micp_mic_ctlr_aics_status_cb()
222 listener->aics_cb.status(inst, err, active); in micp_mic_ctlr_aics_status_cb()
232 if (listener->aics_cb.description) { in micp_mic_ctlr_aics_description_cb()
233 listener->aics_cb.description(inst, err, description); in micp_mic_ctlr_aics_description_cb()
252 err = bt_gatt_discover(mic_ctlr->conn, &mic_ctlr->discover_params); in micp_mic_ctlr_aics_discover_cb()
261 if (listener->aics_cb.discover) { in micp_mic_ctlr_aics_discover_cb()
262 listener->aics_cb.discover(inst, err); in micp_mic_ctlr_aics_discover_cb()
272 if (listener->aics_cb.set_gain) { in micp_mic_ctlr_aics_set_gain_cb()
273 listener->aics_cb.set_gain(inst, err); in micp_mic_ctlr_aics_set_gain_cb()
283 if (listener->aics_cb.unmute) { in micp_mic_ctlr_aics_unmute_cb()
284 listener->aics_cb.unmute(inst, err); in micp_mic_ctlr_aics_unmute_cb()
294 if (listener->aics_cb.mute) { in micp_mic_ctlr_aics_mute_cb()
295 listener->aics_cb.mute(inst, err); in micp_mic_ctlr_aics_mute_cb()
305 if (listener->aics_cb.set_manual_mode) { in micp_mic_ctlr_aics_set_manual_mode_cb()
306 listener->aics_cb.set_manual_mode(inst, err); in micp_mic_ctlr_aics_set_manual_mode_cb()
316 if (listener->aics_cb.set_auto_mode) { in micp_mic_ctlr_aics_set_auto_mode_cb()
317 listener->aics_cb.set_auto_mode(inst, err); in micp_mic_ctlr_aics_set_auto_mode_cb()
329 LOG_DBG("Discover include complete for MICS: %u AICS", mic_ctlr->aics_inst_cnt); in micp_discover_include_func()
337 LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); in micp_discover_include_func()
339 if (params->type == BT_GATT_DISCOVER_INCLUDE) { in micp_discover_include_func()
340 struct bt_gatt_include *include = (struct bt_gatt_include *)attr->user_data; in micp_discover_include_func()
342 LOG_DBG("Include UUID %s", bt_uuid_str(include->uuid)); in micp_discover_include_func()
344 if (bt_uuid_cmp(include->uuid, BT_UUID_AICS) == 0 && in micp_discover_include_func()
345 mic_ctlr->aics_inst_cnt < CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST) { in micp_discover_include_func()
349 .start_handle = include->start_handle, in micp_discover_include_func()
350 .end_handle = include->end_handle, in micp_discover_include_func()
356 mic_ctlr->discover_params.start_handle = attr->handle + 1; in micp_discover_include_func()
358 inst_idx = mic_ctlr->aics_inst_cnt++; in micp_discover_include_func()
359 err = bt_aics_discover(conn, mic_ctlr->aics[inst_idx], in micp_discover_include_func()
393 mic_ctlr->discover_params.start_handle = mic_ctlr->start_handle; in micp_discover_func()
394 mic_ctlr->discover_params.end_handle = mic_ctlr->end_handle; in micp_discover_func()
395 mic_ctlr->discover_params.type = BT_GATT_DISCOVER_INCLUDE; in micp_discover_func()
396 mic_ctlr->discover_params.func = micp_discover_include_func; in micp_discover_func()
398 err = bt_gatt_discover(conn, &mic_ctlr->discover_params); in micp_discover_func()
410 LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); in micp_discover_func()
412 if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { in micp_discover_func()
413 struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data; in micp_discover_func()
416 if (bt_uuid_cmp(chrc->uuid, BT_UUID_MICS_MUTE) == 0) { in micp_discover_func()
417 LOG_DBG("Mute"); in micp_discover_func()
418 mic_ctlr->mute_handle = chrc->value_handle; in micp_discover_func()
419 sub_params = &mic_ctlr->mute_sub_params; in micp_discover_func()
420 sub_params->disc_params = &mic_ctlr->mute_sub_disc_params; in micp_discover_func()
426 sub_params->ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE; in micp_discover_func()
427 sub_params->end_handle = mic_ctlr->end_handle; in micp_discover_func()
428 sub_params->value = BT_GATT_CCC_NOTIFY; in micp_discover_func()
429 sub_params->value_handle = chrc->value_handle; in micp_discover_func()
430 sub_params->notify = mute_notify_handler; in micp_discover_func()
431 atomic_set_bit(sub_params->flags, BT_GATT_SUBSCRIBE_FLAG_VOLATILE); in micp_discover_func()
434 if (err == 0 || err == -EALREADY) { in micp_discover_func()
435 LOG_DBG("Subscribed to handle 0x%04X", attr->handle); in micp_discover_func()
437 LOG_DBG("Could not subscribe to handle 0x%04X: %d", attr->handle, in micp_discover_func()
458 micp_mic_ctlr_discover_complete(mic_ctlr, -ENODATA); in primary_discover_func()
463 LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); in primary_discover_func()
465 if (params->type == BT_GATT_DISCOVER_PRIMARY) { in primary_discover_func()
467 (struct bt_gatt_service_val *)attr->user_data; in primary_discover_func()
471 mic_ctlr->start_handle = attr->handle + 1; in primary_discover_func()
472 mic_ctlr->end_handle = prim_service->end_handle; in primary_discover_func()
475 mic_ctlr->discover_params.uuid = NULL; in primary_discover_func()
476 mic_ctlr->discover_params.start_handle = mic_ctlr->start_handle; in primary_discover_func()
477 mic_ctlr->discover_params.end_handle = mic_ctlr->end_handle; in primary_discover_func()
478 mic_ctlr->discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; in primary_discover_func()
479 mic_ctlr->discover_params.func = micp_discover_func; in primary_discover_func()
481 err = bt_gatt_discover(conn, &mic_ctlr->discover_params); in primary_discover_func()
495 mic_ctlr->start_handle = 0; in micp_mic_ctlr_reset()
496 mic_ctlr->end_handle = 0; in micp_mic_ctlr_reset()
497 mic_ctlr->mute_handle = 0; in micp_mic_ctlr_reset()
499 mic_ctlr->aics_inst_cnt = 0; in micp_mic_ctlr_reset()
502 if (mic_ctlr->conn != NULL) { in micp_mic_ctlr_reset()
503 struct bt_conn *conn = mic_ctlr->conn; in micp_mic_ctlr_reset()
506 mic_ctlr->conn = NULL; in micp_mic_ctlr_reset()
514 if (mic_ctlr->conn == conn) { in disconnected()
540 return -EINVAL; in bt_micp_mic_ctlr_discover()
544 if (atomic_test_and_set_bit(mic_ctlr->flags, BT_MICP_MIC_CTLR_FLAG_BUSY)) { in bt_micp_mic_ctlr_discover()
547 return -EBUSY; in bt_micp_mic_ctlr_discover()
550 (void)memset(&mic_ctlr->discover_params, 0, in bt_micp_mic_ctlr_discover()
551 sizeof(mic_ctlr->discover_params)); in bt_micp_mic_ctlr_discover()
559 for (size_t j = 0U; j < ARRAY_SIZE(mic_ctlr->aics); j++) { in bt_micp_mic_ctlr_discover()
569 .mute = micp_mic_ctlr_aics_mute_cb, in bt_micp_mic_ctlr_discover()
577 return -ENOMEM; in bt_micp_mic_ctlr_discover()
588 mic_ctlr->conn = bt_conn_ref(conn); in bt_micp_mic_ctlr_discover()
589 mic_ctlr->discover_params.func = primary_discover_func; in bt_micp_mic_ctlr_discover()
590 mic_ctlr->discover_params.uuid = mics_uuid; in bt_micp_mic_ctlr_discover()
591 mic_ctlr->discover_params.type = BT_GATT_DISCOVER_PRIMARY; in bt_micp_mic_ctlr_discover()
592 mic_ctlr->discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; in bt_micp_mic_ctlr_discover()
593 mic_ctlr->discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; in bt_micp_mic_ctlr_discover()
595 err = bt_gatt_discover(conn, &mic_ctlr->discover_params); in bt_micp_mic_ctlr_discover()
599 atomic_clear_bit(mic_ctlr->flags, BT_MICP_MIC_CTLR_FLAG_BUSY); in bt_micp_mic_ctlr_discover()
610 return -EINVAL; in bt_micp_mic_ctlr_cb_register()
616 return -EALREADY; in bt_micp_mic_ctlr_cb_register()
620 sys_slist_append(&micp_mic_ctlr_cbs, &cb->_node); in bt_micp_mic_ctlr_cb_register()
631 return -EINVAL; in bt_micp_mic_ctlr_included_get()
635 return -EINVAL; in bt_micp_mic_ctlr_included_get()
638 included->aics_cnt = mic_ctlr->aics_inst_cnt; in bt_micp_mic_ctlr_included_get()
639 included->aics = mic_ctlr->aics; in bt_micp_mic_ctlr_included_get()
655 if (mic_ctlr->conn == NULL) { in bt_micp_mic_ctlr_get_by_conn()
668 return -EINVAL; in bt_micp_mic_ctlr_conn_get()
671 if (mic_ctlr->conn == NULL) { in bt_micp_mic_ctlr_conn_get()
674 return -ENOTCONN; in bt_micp_mic_ctlr_conn_get()
677 *conn = mic_ctlr->conn; in bt_micp_mic_ctlr_conn_get()
687 return -EINVAL; in bt_micp_mic_ctlr_mute_get()
690 if (mic_ctlr->mute_handle == 0) { in bt_micp_mic_ctlr_mute_get()
692 return -EINVAL; in bt_micp_mic_ctlr_mute_get()
693 } else if (atomic_test_and_set_bit(mic_ctlr->flags, BT_MICP_MIC_CTLR_FLAG_BUSY)) { in bt_micp_mic_ctlr_mute_get()
696 return -EBUSY; in bt_micp_mic_ctlr_mute_get()
699 mic_ctlr->read_params.func = micp_mic_ctlr_read_mute_cb; in bt_micp_mic_ctlr_mute_get()
700 mic_ctlr->read_params.handle_count = 1; in bt_micp_mic_ctlr_mute_get()
701 mic_ctlr->read_params.single.handle = mic_ctlr->mute_handle; in bt_micp_mic_ctlr_mute_get()
702 mic_ctlr->read_params.single.offset = 0U; in bt_micp_mic_ctlr_mute_get()
704 err = bt_gatt_read(mic_ctlr->conn, &mic_ctlr->read_params); in bt_micp_mic_ctlr_mute_get()
706 atomic_clear_bit(mic_ctlr->flags, BT_MICP_MIC_CTLR_FLAG_BUSY); in bt_micp_mic_ctlr_mute_get()
712 static int bt_micp_mic_ctlr_write_mute(struct bt_micp_mic_ctlr *mic_ctlr, bool mute) in bt_micp_mic_ctlr_write_mute() argument
718 return -EINVAL; in bt_micp_mic_ctlr_write_mute()
721 if (mic_ctlr->mute_handle == 0) { in bt_micp_mic_ctlr_write_mute()
723 return -EINVAL; in bt_micp_mic_ctlr_write_mute()
724 } else if (atomic_test_and_set_bit(mic_ctlr->flags, BT_MICP_MIC_CTLR_FLAG_BUSY)) { in bt_micp_mic_ctlr_write_mute()
727 return -EBUSY; in bt_micp_mic_ctlr_write_mute()
730 mic_ctlr->mute_val_buf[0] = mute; in bt_micp_mic_ctlr_write_mute()
731 mic_ctlr->write_params.offset = 0; in bt_micp_mic_ctlr_write_mute()
732 mic_ctlr->write_params.data = mic_ctlr->mute_val_buf; in bt_micp_mic_ctlr_write_mute()
733 mic_ctlr->write_params.length = sizeof(mute); in bt_micp_mic_ctlr_write_mute()
734 mic_ctlr->write_params.handle = mic_ctlr->mute_handle; in bt_micp_mic_ctlr_write_mute()
735 mic_ctlr->write_params.func = micp_mic_ctlr_write_mics_mute_cb; in bt_micp_mic_ctlr_write_mute()
737 err = bt_gatt_write(mic_ctlr->conn, &mic_ctlr->write_params); in bt_micp_mic_ctlr_write_mute()
739 atomic_clear_bit(mic_ctlr->flags, BT_MICP_MIC_CTLR_FLAG_BUSY); in bt_micp_mic_ctlr_write_mute()