2016-11-24 17:58:26 +00: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.
|
|
|
|
|
2016-11-16 08:26:02 +00:00
|
|
|
#include "btc_task.h"
|
2016-11-15 12:56:15 +00:00
|
|
|
#include "btc_main.h"
|
2016-11-16 08:26:02 +00:00
|
|
|
#include "future.h"
|
2016-11-15 12:56:15 +00:00
|
|
|
#include "esp_err.h"
|
|
|
|
|
2016-11-16 08:26:02 +00:00
|
|
|
static future_t *main_future[BTC_MAIN_FUTURE_NUM];
|
|
|
|
|
2016-11-15 12:56:15 +00:00
|
|
|
extern int bte_main_boot_entry(void *cb);
|
|
|
|
extern int bte_main_shutdown(void);
|
|
|
|
|
2016-11-16 08:26:02 +00:00
|
|
|
future_t **btc_main_get_future_p(btc_main_future_type_t type)
|
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
return &main_future[type];
|
2016-11-16 08:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void btc_sec_callback(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
|
2016-11-15 12:56:15 +00:00
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
switch (event) {
|
|
|
|
case BTA_DM_ENABLE_EVT:
|
|
|
|
future_ready(*btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE), FUTURE_SUCCESS);
|
|
|
|
break;
|
|
|
|
case BTA_DM_DISABLE_EVT:
|
|
|
|
future_ready(*btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE), FUTURE_SUCCESS);
|
|
|
|
break;
|
|
|
|
}
|
2016-11-15 12:56:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 06:11:40 +00:00
|
|
|
static void btc_enable_bluetooth(void)
|
2016-11-15 12:56:15 +00:00
|
|
|
{
|
2016-12-07 06:11:40 +00:00
|
|
|
if (BTA_EnableBluetooth(btc_sec_callback) != BTA_SUCCESS) {
|
|
|
|
future_ready(*btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE), FUTURE_SUCCESS);
|
|
|
|
}
|
2016-11-15 12:56:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 06:11:40 +00:00
|
|
|
static void btc_disable_bluetooth(void)
|
2016-11-15 12:56:15 +00:00
|
|
|
{
|
2016-12-07 06:11:40 +00:00
|
|
|
if (BTA_DisableBluetooth() != BTA_SUCCESS) {
|
|
|
|
future_ready(*btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE), FUTURE_SUCCESS);
|
|
|
|
}
|
2016-11-15 12:56:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 08:26:02 +00:00
|
|
|
void btc_init_callback(void)
|
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
future_ready(*btc_main_get_future_p(BTC_MAIN_INIT_FUTURE), FUTURE_SUCCESS);
|
2016-11-16 08:26:02 +00:00
|
|
|
}
|
2016-11-15 12:56:15 +00:00
|
|
|
|
2016-12-07 06:11:40 +00:00
|
|
|
static void btc_init_bluetooth(void)
|
2016-11-16 08:26:02 +00:00
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
bte_main_boot_entry(btc_init_callback);
|
2016-11-16 08:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void btc_deinit_bluetooth(void)
|
2016-11-15 12:56:15 +00:00
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
bte_main_shutdown();
|
|
|
|
future_ready(*btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE), FUTURE_SUCCESS);
|
2016-11-15 12:56:15 +00:00
|
|
|
}
|
2016-11-16 08:26:02 +00:00
|
|
|
|
|
|
|
void btc_main_call_handler(btc_msg_t *msg)
|
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
LOG_DEBUG("%s act %d\n", __func__, msg->act);
|
2016-11-16 08:26:02 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
switch (msg->act) {
|
|
|
|
case BTC_MAIN_ACT_INIT:
|
|
|
|
btc_init_bluetooth();
|
|
|
|
break;
|
|
|
|
case BTC_MAIN_ACT_DEINIT:
|
|
|
|
btc_deinit_bluetooth();
|
|
|
|
break;
|
|
|
|
case BTC_MAIN_ACT_ENABLE:
|
|
|
|
btc_enable_bluetooth();
|
|
|
|
break;
|
|
|
|
case BTC_MAIN_ACT_DISABLE:
|
|
|
|
btc_disable_bluetooth();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_ERROR("%s UNKNOWN ACT %d\n", __func__, msg->act);
|
|
|
|
break;
|
|
|
|
}
|
2016-11-16 08:26:02 +00:00
|
|
|
}
|
|
|
|
|