2017-03-07 08:15:54 -05:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "common/bt_target.h"
|
2017-03-07 08:15:54 -05:00
|
|
|
#include <string.h>
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "esp_a2dp_api.h"
|
|
|
|
#include "esp_bt_main.h"
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "btc/btc_manage.h"
|
2017-03-07 08:15:54 -05:00
|
|
|
#include "btc_av.h"
|
|
|
|
|
2017-03-17 03:08:47 -04:00
|
|
|
#if BTC_AV_INCLUDED
|
|
|
|
|
2017-12-25 06:39:37 -05:00
|
|
|
#if BTC_AV_SINK_INCLUDED
|
2017-03-07 08:15:54 -05:00
|
|
|
esp_err_t esp_a2d_sink_init(void)
|
|
|
|
{
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
btc_msg_t msg;
|
2017-12-25 06:39:37 -05:00
|
|
|
|
2017-03-07 08:15:54 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_A2DP;
|
|
|
|
msg.act = BTC_AV_SINK_API_INIT_EVT;
|
|
|
|
|
|
|
|
/* Switch to BTC context */
|
|
|
|
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL);
|
|
|
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_a2d_sink_deinit(void)
|
|
|
|
{
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
2017-12-25 06:39:37 -05:00
|
|
|
|
2017-03-07 08:15:54 -05:00
|
|
|
btc_msg_t msg;
|
2017-12-25 06:39:37 -05:00
|
|
|
|
2017-03-07 08:15:54 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_A2DP;
|
|
|
|
msg.act = BTC_AV_SINK_API_DEINIT_EVT;
|
|
|
|
|
|
|
|
/* Switch to BTC context */
|
|
|
|
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL);
|
|
|
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
2017-12-25 06:39:37 -05:00
|
|
|
esp_err_t esp_a2d_sink_register_data_callback(esp_a2d_sink_data_cb_t callback)
|
2017-03-13 02:54:02 -04:00
|
|
|
{
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
btc_msg_t msg;
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_A2DP;
|
|
|
|
msg.act = BTC_AV_SINK_API_REG_DATA_CB_EVT;
|
|
|
|
|
|
|
|
btc_av_args_t arg;
|
2017-12-25 06:39:37 -05:00
|
|
|
memset(&arg, 0, sizeof(btc_av_args_t));
|
2017-03-13 02:54:02 -04:00
|
|
|
arg.data_cb = callback;
|
2017-12-25 06:39:37 -05:00
|
|
|
|
2017-03-13 02:54:02 -04:00
|
|
|
/* Switch to BTC context */
|
2017-12-25 06:39:37 -05:00
|
|
|
bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_av_args_t), NULL);
|
2017-03-13 02:54:02 -04:00
|
|
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
2017-03-07 08:15:54 -05:00
|
|
|
esp_err_t esp_a2d_sink_connect(esp_bd_addr_t remote_bda)
|
|
|
|
{
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
2017-12-25 06:39:37 -05:00
|
|
|
|
2017-03-07 08:15:54 -05:00
|
|
|
bt_status_t stat;
|
|
|
|
btc_av_args_t arg;
|
|
|
|
btc_msg_t msg;
|
2017-12-25 06:39:37 -05:00
|
|
|
|
2017-03-07 08:15:54 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_A2DP;
|
|
|
|
msg.act = BTC_AV_SINK_API_CONNECT_EVT;
|
|
|
|
|
|
|
|
memset(&arg, 0, sizeof(btc_av_args_t));
|
2017-12-25 06:39:37 -05:00
|
|
|
|
2017-03-07 08:15:54 -05:00
|
|
|
/* Switch to BTC context */
|
|
|
|
memcpy(&(arg.connect), remote_bda, sizeof(bt_bdaddr_t));
|
|
|
|
stat = btc_transfer_context(&msg, &arg, sizeof(btc_av_args_t), NULL);
|
|
|
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_a2d_sink_disconnect(esp_bd_addr_t remote_bda)
|
|
|
|
{
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
2017-12-25 06:39:37 -05:00
|
|
|
|
2017-03-07 08:15:54 -05:00
|
|
|
bt_status_t stat;
|
|
|
|
btc_msg_t msg;
|
2017-12-25 06:39:37 -05:00
|
|
|
|
2017-03-07 08:15:54 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_A2DP;
|
2017-03-08 08:08:11 -05:00
|
|
|
msg.act = BTC_AV_SINK_API_DISCONNECT_EVT;
|
2017-03-07 08:15:54 -05:00
|
|
|
|
|
|
|
/* Switch to BTC context */
|
2017-03-08 08:08:11 -05:00
|
|
|
stat = btc_transfer_context(&msg, NULL, 0, NULL);
|
2017-03-07 08:15:54 -05:00
|
|
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
|
|
|
}
|
2017-03-17 03:08:47 -04:00
|
|
|
|
2017-12-25 06:39:37 -05:00
|
|
|
#endif /* BTC_AV_SINK_INCLUDED */
|
|
|
|
|
|
|
|
esp_err_t esp_a2d_register_callback(esp_a2d_cb_t callback)
|
|
|
|
{
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (callback == NULL) {
|
|
|
|
return ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
btc_profile_cb_set(BTC_PID_A2DP, callback);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_a2d_media_ctrl(esp_a2d_media_ctrl_t ctrl)
|
|
|
|
{
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_status_t stat;
|
|
|
|
btc_av_args_t arg;
|
|
|
|
btc_msg_t msg;
|
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_A2DP;
|
|
|
|
msg.act = BTC_AV_API_MEDIA_CTRL_EVT;
|
|
|
|
|
|
|
|
memset(&arg, 0, sizeof(btc_av_args_t));
|
|
|
|
|
|
|
|
/* Switch to BTC context */
|
|
|
|
arg.ctrl = ctrl;
|
|
|
|
stat = btc_transfer_context(&msg, &arg, sizeof(btc_av_args_t), NULL);
|
|
|
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BTC_AV_SRC_INCLUDED
|
|
|
|
esp_err_t esp_a2d_source_init(void)
|
|
|
|
{
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
btc_msg_t msg;
|
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_A2DP;
|
|
|
|
msg.act = BTC_AV_SRC_API_INIT_EVT;
|
|
|
|
|
|
|
|
/* Switch to BTC context */
|
|
|
|
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL);
|
|
|
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_a2d_source_deinit(void)
|
|
|
|
{
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
btc_msg_t msg;
|
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_A2DP;
|
|
|
|
msg.act = BTC_AV_SRC_API_DEINIT_EVT;
|
|
|
|
|
|
|
|
/* Switch to BTC context */
|
|
|
|
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL);
|
|
|
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_a2d_source_connect(esp_bd_addr_t remote_bda)
|
|
|
|
{
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_status_t stat;
|
|
|
|
btc_av_args_t arg;
|
|
|
|
btc_msg_t msg;
|
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_A2DP;
|
|
|
|
msg.act = BTC_AV_SRC_API_CONNECT_EVT;
|
|
|
|
|
|
|
|
memset(&arg, 0, sizeof(btc_av_args_t));
|
|
|
|
|
|
|
|
/* Switch to BTC context */
|
|
|
|
memcpy(&(arg.src_connect), remote_bda, sizeof(bt_bdaddr_t));
|
|
|
|
stat = btc_transfer_context(&msg, &arg, sizeof(btc_av_args_t), NULL);
|
|
|
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_a2d_source_disconnect(esp_bd_addr_t remote_bda)
|
|
|
|
{
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_status_t stat;
|
|
|
|
btc_msg_t msg;
|
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_A2DP;
|
|
|
|
msg.act = BTC_AV_SRC_API_DISCONNECT_EVT;
|
|
|
|
|
|
|
|
/* Switch to BTC context */
|
|
|
|
stat = btc_transfer_context(&msg, NULL, 0, NULL);
|
|
|
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_a2d_source_register_data_callback(esp_a2d_source_data_cb_t callback)
|
|
|
|
{
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
btc_msg_t msg;
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_A2DP;
|
|
|
|
msg.act = BTC_AV_SRC_API_REG_DATA_CB_EVT;
|
|
|
|
|
|
|
|
btc_av_args_t arg;
|
|
|
|
memset(&arg, 0, sizeof(btc_av_args_t));
|
|
|
|
arg.src_data_cb = callback;
|
|
|
|
|
|
|
|
/* Switch to BTC context */
|
|
|
|
bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_av_args_t), NULL);
|
|
|
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* BTC_AV_SRC_INCLUDED */
|
|
|
|
|
2017-03-17 03:08:47 -04:00
|
|
|
#endif /* #if BTC_AV_INCLUDED */
|