Merge remote-tracking branch 'origin/feature/btdm_arch' into feature/btdm_arch_debug1

This commit is contained in:
Yulong 2016-11-17 08:08:19 -05:00
commit 645717b147
21 changed files with 693 additions and 343 deletions

View file

@ -0,0 +1,66 @@
// 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.
#include "esp_blufi_api.h"
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "btc_task.h"
#include "btc_blufi_prf.h"
#include "btc_manage.h"
#include "btc_main.h"
#include "future.h"
esp_err_t esp_blufi_register_callback(esp_profile_cb_t callback)
{
return (btc_profile_cb_set(BTC_PID_BLUFI, callback) == 0 ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_blufi_send_config_state(esp_blufi_config_state_t state)
{
btc_msg_t msg;
btc_blufi_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_BLUFI;
msg.act = BTC_BLUFI_ACT_SEND_CFG_STATE;
arg.cfg_state.state = state;
return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_blufi_profile_init(void)
{
btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_BLUFI;
msg.act = BTC_BLUFI_ACT_INIT;
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_blufi_profile_deinit(void)
{
btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_BLUFI;
msg.act = BTC_BLUFI_ACT_DEINIT;
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

View file

@ -1,26 +1,157 @@
// 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.
#include "esp_bt_main.h"
#include "btc_task.h"
#include "btc_main.h"
#include "future.h"
static bool esp_already_enable = false;
static bool esp_already_init = false;
esp_err_t esp_enable_bluetooth(esp_bt_sec_cb_t *p_cback)
esp_err_t esp_enable_bluetooth(void)
{
return btc_enable_bluetooth(p_cback) == BT_STATUS_SUCCESS ? ESP_OK: ESP_FAIL;
btc_msg_t msg;
future_t **future_p;
if (esp_already_enable) {
LOG_ERROR("%s already enable\n");
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
LOG_ERROR("%s failed\n");
return ESP_ERR_NO_MEM;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_MAIN_INIT;
msg.act = BTC_MAIN_ACT_ENABLE;
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n");
return ESP_FAIL;
}
esp_already_enable = true;
return ESP_OK;
}
esp_err_t esp_disable_bluetooth(void)
{
return btc_disable_bluetooth() == BT_STATUS_SUCCESS ? ESP_OK: ESP_FAIL;
btc_msg_t msg;
future_t **future_p;
if (!esp_already_enable) {
LOG_ERROR("%s already disable\n");
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
LOG_ERROR("%s failed\n");
return ESP_ERR_NO_MEM;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_MAIN_INIT;
msg.act = BTC_MAIN_ACT_DISABLE;
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n");
return ESP_FAIL;
}
esp_already_enable = false;
return ESP_OK;
}
esp_err_t esp_init_bluetooth(bluetooth_init_cb_t cb)
esp_err_t esp_init_bluetooth(void)
{
return btc_init_bluetooth(cb) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL;
btc_msg_t msg;
future_t **future_p;
if (esp_already_init) {
LOG_ERROR("%s already init\n");
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_INIT_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
LOG_ERROR("%s failed\n");
return ESP_ERR_NO_MEM;
}
btc_init();
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_MAIN_INIT;
msg.act = BTC_MAIN_ACT_INIT;
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n");
return ESP_FAIL;
}
esp_already_init = true;;
return ESP_OK;
}
void esp_deinit_bluetooth(void)
esp_err_t esp_deinit_bluetooth(void)
{
btc_deinit_bluetooth();
btc_msg_t msg;
future_t **future_p;
if (!esp_already_init) {
LOG_ERROR("%s already deinit\n");
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
LOG_ERROR("%s failed\n");
return ESP_ERR_NO_MEM;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_MAIN_INIT;
msg.act = BTC_MAIN_ACT_DEINIT;
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n");
return ESP_FAIL;
}
btc_deinit();
esp_already_init = false;
return ESP_OK;
}

View file

@ -0,0 +1,97 @@
#ifndef __ESP_BLUFI_API_H__
#define __ESP_BLUFI_API_H__
#include "bt_types.h"
#include "esp_bt_defs.h"
#include "esp_gatt_defs.h"
#include "bta_gatt_api.h"
#include "esp_err.h"
#define ESP_BLUFI_RECV_DATA_LEN_MAX 128
#define ESP_BLUFI_EVENT_INIT_FINISH 0
#define ESP_BLUFI_EVENT_DEINIT_FINISH 1
#define ESP_BLUFI_EVENT_RECV_DATA 2
typedef enum {
ESP_BLUFI_CONFIG_OK = 0,
ESP_BLUFI_CONFIG_FAILED,
} esp_blufi_config_state_t;
typedef enum {
ESP_BLUFI_INIT_OK = 0,
ESP_BLUFI_INIT_FAILED = 0,
} esp_blufi_init_state_t;
typedef enum {
ESP_BLUFI_DEINIT_OK = 0,
ESP_BLUFI_DEINIT_FAILED = 0,
} esp_blufi_deinit_state_t;
typedef union {
//ESP_BLUFI_EVENT_INIT_FINISH
struct blufi_init_finish_evt_param {
esp_blufi_init_state_t state;
} init_finish;
//ESP_BLUFI_EVENT_DEINIT_FINISH
struct blufi_deinit_finish_evt_param {
esp_blufi_deinit_state_t state;
} deinit_finish;
//ESP_BLUFI_EVENT_RECV_DATA
struct blufi_recv_evt_param {
uint8_t data[ESP_BLUFI_RECV_DATA_LEN_MAX];
uint8_t data_len;
} recv_data;
} esp_blufi_cb_param_t;
/*******************************************************************************
**
** @function esp_blufi_register_callback
**
** @brief This function is called to receive blufi callback event
**
** @param[in] callback: callback function
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_blufi_register_callback(esp_profile_cb_t callback);
/*******************************************************************************
**
** @function esp_blufi_send_config_state
**
** @brief This function is called to send config state to phone
**
** @param[in] state: blufi config ok or not
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_blufi_send_config_state(esp_blufi_config_state_t state);
/*******************************************************************************
**
** @function esp_blufi_profile_init
**
** @brief This function is called to init blufi_profile
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_blufi_profile_init(void);
/*******************************************************************************
**
** @function esp_blufi_profile_deinit
**
** @brief This function is called to init blufi_profile
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_blufi_profile_deinit(void);
#endif /* _ESP_BLUFI_API_ */

View file

@ -4,13 +4,13 @@
#include "btc_main.h"
#include "esp_err.h"
esp_err_t esp_enable_bluetooth(esp_bt_sec_cb_t *p_cback);
esp_err_t esp_enable_bluetooth(void);
esp_err_t esp_disable_bluetooth(void);
esp_err_t esp_init_bluetooth(bluetooth_init_cb_t cb);
esp_err_t esp_init_bluetooth(void);
void esp_deinit_bluetooth(void);
esp_err_t esp_deinit_bluetooth(void);
#endif /* __ESP_BT_MAIN_H__ */

View file

@ -222,7 +222,7 @@ void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
// btla-specific --
if (first_unuse != 0xff)
{
APPL_TRACE_ERROR("register application first_unuse rcb_idx = %d", first_unuse);
APPL_TRACE_VERBOSE("register application first_unuse rcb_idx = %d", first_unuse);
p_cb->rcb[first_unuse].in_use = TRUE;
p_cb->rcb[first_unuse].p_cback = p_msg->api_reg.p_cback;
@ -353,7 +353,7 @@ void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
rcb_idx = bta_gatts_find_app_rcb_idx_by_app_if(p_cb, p_msg->api_create_svc.server_if);
APPL_TRACE_ERROR("create service rcb_idx = %d", rcb_idx);
APPL_TRACE_DEBUG("create service rcb_idx = %d", rcb_idx);
if (rcb_idx != BTA_GATTS_INVALID_APP)
{

View file

@ -72,7 +72,6 @@ BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg)
break;
case BTA_GATTS_API_REG_EVT:
LOG_ERROR("bta_gatts_register\n");
bta_gatts_register(p_cb, (tBTA_GATTS_DATA *) p_msg);
break;

View file

@ -1,26 +1,77 @@
#include "btc_task.h"
#include "btc_main.h"
#include "future.h"
#include "esp_err.h"
static future_t *main_future[BTC_MAIN_FUTURE_NUM];
extern int bte_main_boot_entry(void *cb);
extern int bte_main_shutdown(void);
bt_status_t btc_enable_bluetooth(esp_bt_sec_cb_t *p_cback)
future_t **btc_main_get_future_p(btc_main_future_type_t type)
{
return BTA_EnableBluetooth(p_cback) == BTA_SUCCESS ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
return &main_future[type];
}
bt_status_t btc_disable_bluetooth(void)
static void btc_sec_callback(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
{
return BTA_DisableBluetooth() == BTA_SUCCESS ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
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;
}
}
bt_status_t btc_init_bluetooth(bluetooth_init_cb_t cb)
static bt_status_t btc_enable_bluetooth(void)
{
return bte_main_boot_entry(cb) == 0 ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
BTA_EnableBluetooth(btc_sec_callback);
}
static bt_status_t btc_disable_bluetooth(void)
{
BTA_DisableBluetooth();
}
void btc_init_callback(void)
{
future_ready(*btc_main_get_future_p(BTC_MAIN_INIT_FUTURE), FUTURE_SUCCESS);
}
static bt_status_t btc_init_bluetooth(void)
{
bte_main_boot_entry(btc_init_callback);
}
void btc_deinit_bluetooth(void)
static void btc_deinit_bluetooth(void)
{
bte_main_shutdown();
future_ready(*btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE), FUTURE_SUCCESS);
}
void btc_main_call_handler(btc_msg_t *msg)
{
LOG_DEBUG("%s act %d\n", __func__, msg->act);
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;
}
}

View file

@ -19,14 +19,17 @@
#include "thread.h"
#include "gki.h"
#include "bt_defs.h"
#include "btc_main.h"
#include "btc_gatts.h"
#include "btc_gattc.h"
#include "btc_gap_ble.h"
#include "btc_blufi_prf.h"
static xTaskHandle xBtcTaskHandle = NULL;
static xQueueHandle xBtcQueue = 0;
static btc_func_t profile_tab[BTC_PID_NUM] = {
[BTC_PID_MAIN_INIT] = {btc_main_call_handler, NULL },
[BTC_PID_GATTS] = {btc_gatts_call_handler, btc_gatts_cb_handler },
[BTC_PID_GATTC] = {btc_gattc_call_handler, btc_gattc_cb_handler },
[BTC_PID_GAP_BLE] = {btc_gap_ble_call_handler, btc_gap_ble_cb_handler },
@ -36,7 +39,7 @@ static btc_func_t profile_tab[BTC_PID_NUM] = {
[BTC_PID_BT_HID] = {NULL, NULL},
[BTC_PID_SPP] = {NULL, NULL},
[BTC_PID_SPPLIKE] = {NULL, NULL},
[BTC_PID_BLUFI] = {NULL, NULL},
[BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler },
};
/*****************************************************************************
@ -51,6 +54,7 @@ static void btc_task(void *arg)
for (;;) {
if (pdTRUE == xQueueReceive(xBtcQueue, &msg, (portTickType)portMAX_DELAY)) {
LOG_DEBUG("%s msg %u %u %u %08x\n", __func__, msg.sig, msg.pid, msg.act, msg.arg);
switch (msg.sig) {
case BTC_SIG_API_CALL:
profile_tab[msg.pid].btc_call(&msg);
@ -74,7 +78,7 @@ static bt_status_t btc_task_post(btc_msg_t *msg)
return BT_STATUS_PARM_INVALID;
}
if (xQueueSend(xBtcQueue, &msg, 10/portTICK_RATE_MS) != pdTRUE) {
if (xQueueSend(xBtcQueue, msg, 10/portTICK_RATE_MS) != pdTRUE) {
LOG_ERROR("Btc Post failed\n");
return BT_STATUS_BUSY;
}
@ -102,6 +106,8 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
if (copy_func) {
copy_func(&lmsg, lmsg.arg, arg);
}
} else {
lmsg.arg = NULL;
}
return btc_task_post(&lmsg);
@ -110,8 +116,8 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
int btc_init(void)
{
xBtcQueue = xQueueCreate(60, sizeof(btc_msg_t));
xTaskCreate(btc_task, "Bt_prf", 4096, NULL, configMAX_PRIORITIES - 1, &xBtcTaskHandle);
xBtcQueue = xQueueCreate(BTC_TASK_QUEUE_NUM, sizeof(btc_msg_t));
xTaskCreate(btc_task, "Btc_task", BTC_TASK_STACK_SIZE, NULL, BTC_TASK_PRIO, &xBtcTaskHandle);
/* TODO: initial the profile_tab */

View file

@ -1,17 +0,0 @@
#ifndef __BTC_BT_COMMON_H__
#define __BTC_BT_COMMON_H__
#include "bt_types.h"
#include "bta_api.h"
typedef tBTA_DM_SEC_CBACK esp_bt_sec_cb_t;
typedef void (*bluetooth_init_cb_t)(void);
bt_status_t btc_enable_bluetooth(esp_bt_sec_cb_t *p_cback);
bt_status_t btc_disable_bluetooth(void);
bt_status_t btc_init_bluetooth(bluetooth_init_cb_t cb);
void btc_deinit_bluetooth(void);
#endif /* __BTC_BT_COMMON_H__ */

View file

@ -0,0 +1,50 @@
#ifndef __BTC_BT_MAIN_H__
#define __BTC_BT_MAIN_H__
#include "future.h"
#include "bt_types.h"
#include "bta_api.h"
#include "btc_main.h"
#include "btc_task.h"
typedef enum {
BTC_MAIN_ACT_INIT = 0,
BTC_MAIN_ACT_DEINIT,
BTC_MAIN_ACT_ENABLE,
BTC_MAIN_ACT_DISABLE,
} btc_main_act_t;
typedef enum {
BTC_MAIN_INIT_FUTURE = 0,
BTC_MAIN_DEINIT_FUTURE,
BTC_MAIN_ENABLE_FUTURE,
BTC_MAIN_DISABLE_FUTURE,
BTC_MAIN_FUTURE_NUM,
} btc_main_future_type_t;
future_t **btc_main_get_future_p(btc_main_future_type_t type);
#if 0
typedef union {
struct btc_main_init_args {
future_t *future;
} init;
struct btc_main_deinit_args {
future_t *future;
} deinit;
struct btc_main_init_args {
future_t *future;
} enable;
struct btc_main_init_args {
future_t *future;
} disable;
} btc_main_args_t;
bt_status_t btc_enable_bluetooth(future_t *future);
void btc_disable_bluetooth(future_t *future);
bt_status_t btc_init_bluetooth(future_t *future);
void btc_deinit_bluetooth(future_t *future);
#endif
void btc_main_call_handler(btc_msg_t *msg);
#endif /* __BTC_BT_MAIN_H__ */

View file

@ -7,6 +7,7 @@
#define BTC_TASK_QUEUE_NUM 20
#define BTC_TASK_STACK_SIZE 4096
#define BTC_TASK_NAME "btcT"
#define BTC_TASK_PRIO (configMAX_PRIORITIES - 5)
typedef struct btc_msg {
uint8_t sig; //event signal
@ -23,7 +24,8 @@ typedef enum {
} btc_sig_t; //btc message type
typedef enum {
BTC_PID_GATTS = 0,
BTC_PID_MAIN_INIT = 0,
BTC_PID_GATTS,
BTC_PID_GATTC,
BTC_PID_GAP_BLE,
BTC_PID_GAP_BT,
@ -45,4 +47,7 @@ typedef void (* btc_arg_deep_copy_t)(btc_msg_t *msg, void *dst, void *src);
bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func);
int btc_init(void);
void btc_deinit(void);
#endif /* __BTC_TASK_H__ */

View file

@ -27,14 +27,21 @@
#include "bta_gatt_api.h"
#include "bta_gatts_int.h"
#include "blufi_prf.h"
#include "btc_blufi_prf.h"
#include "btc_task.h"
#include "btc_manage.h"
#include "blufi_adv.h"
#include "blufi_int.h"
static uint8_t *success_msg = "BLUFI_CONFIG_OK";
static uint8_t *failed_msg = "BLUFI_CONFIG_FAILED";
#define BTC_BLUFI_CB_TO_APP(_event, _param) ((esp_profile_cb_t)btc_profile_cb_get(BTC_PID_BLUFI))(_event, _param)
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
void blufi_config_success(void);
void blufi_config_failed(void);
UINT16 esp32_uuid = SVC_BLUFI_UUID;
UINT8 esp32_manu[17] = {0xff,0x20,0x14,0x07,0x22,0x00,0x02,0x5B,0x00,0x33,0x49,0x31,0x30,0x4a,0x30,0x30,0x31};
@ -99,6 +106,33 @@ static tBLUFI_CB_ENV blufi_cb_env;
static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data);
/*******************************************************************************
**
** Function blufi_create_service
**
** Description Create a Service for the blufi profile
**
** Returns NULL
**
*******************************************************************************/
static void blufi_create_service(void)
{
tBTA_GATTS_IF server_if ;
tBT_UUID uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
UINT16 num_handle = BLUFI_HDL_NUM;
UINT8 inst = 0x00;
server_if = blufi_cb_env.gatt_if;
blufi_cb_env.inst_id = inst;
if(!blufi_cb_env.enabled)
{
LOG_ERROR("blufi service added error.");
return;
}
BTA_GATTS_CreateService(server_if, &uuid, inst, num_handle, true);
}
/*******************************************************************************
**
** Function blufi_profile_cb
@ -112,8 +146,6 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
{
tBTA_GATTS_RSP rsp;
tBT_UUID uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
tBLUFI_INST *p_inst = &blufi_cb_env.blufi_inst;
UINT8 net_event = 0xff;
UINT8 len = 0;
UINT8 *p_rec_data = NULL;
tBTA_GATT_STATUS status;
@ -169,10 +201,20 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
LOG_DEBUG("\n");
if (p_data->req_data.p_data->write_req.handle == blufi_cb_env.blufi_inst.blufi_hdl) {
btc_msg_t msg;
struct blufi_recv_evt_param recv_data;
memset(&recv_data, 0x00, sizeof(struct blufi_recv_evt_param));
p_rec_data = &p_data->req_data.p_data->write_req.value[0];
if (p_inst && p_inst->blufi_cback)
p_inst->blufi_cback(blufi_cb_env.blufi_inst.app_id, net_event, len, p_rec_data);
recv_data.data_len = p_data->req_data.p_data->write_req.len;
memcpy(recv_data.data, p_rec_data, recv_data.data_len);
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = BTC_BLUFI_CB_ACT_RECV_DATA;
btc_transfer_context(&msg, &recv_data, sizeof(struct blufi_recv_evt_param), NULL);
}
break;
case BTA_GATTS_CONF_EVT:
@ -180,12 +222,12 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
break;
case BTA_GATTS_CREATE_EVT:
uuid.uu.uuid16 = CHAR_BLUFI_UUID;
blufi_cb_env.clcb.cur_srvc_id = p_data->create.service_id;
blufi_cb_env.cur_srvc_id = p_data->create.service_id;
blufi_cb_env.is_primery = p_data->create.is_primary;
//start the blufi service after created
BTA_GATTS_StartService(p_data->create.service_id, BTA_GATT_TRANSPORT_LE);
//add the frist blufi characteristic --> write characteristic
BTA_GATTS_AddCharacteristic(blufi_cb_env.clcb.cur_srvc_id, &uuid,
BTA_GATTS_AddCharacteristic(blufi_cb_env.cur_srvc_id, &uuid,
(GATT_PERM_WRITE | GATT_PERM_READ),
(GATT_CHAR_PROP_BIT_READ | GATT_CHAR_PROP_BIT_WRITE | GATT_CHAR_PROP_BIT_NOTIFY));
break;
@ -196,20 +238,29 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
blufi_cb_env.blufi_inst.blufi_hdl = p_data->add_result.attr_id;
uuid.uu.uuid16 = GATT_UUID_CHAR_CLIENT_CONFIG;
BTA_GATTS_AddCharDescriptor (blufi_cb_env.clcb.cur_srvc_id,
BTA_GATTS_AddCharDescriptor (blufi_cb_env.cur_srvc_id,
(GATT_PERM_WRITE|GATT_PERM_WRITE),
&uuid);
}
break;
case BTA_GATTS_ADD_CHAR_DESCR_EVT:
/* Nothing */
case BTA_GATTS_ADD_CHAR_DESCR_EVT: {
/* call init finish */
btc_msg_t msg;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = BTC_BLUFI_CB_ACT_INIT_FINISH;
btc_transfer_context(&msg, NULL, 0, NULL);
break;
}
case BTA_GATTS_CONNECT_EVT:
//set the connection flag to true
blufi_env_clcb_alloc(p_data->conn.conn_id, p_data->conn.remote_bda);
LOG_DEBUG("\ndevice is connected "BT_BD_ADDR_STR", server_if=%d,reason=0x%x,connect_id=%d\n",
LOG_ERROR("\ndevice is connected "BT_BD_ADDR_STR", server_if=%d,reason=0x%x,connect_id=%d\n",
BT_BD_ADDR_HEX(p_data->conn.remote_bda), p_data->conn.server_if,
p_data->conn.reason, p_data->conn.conn_id);
blufi_cb_env.conn_id = p_data->conn.conn_id;
/*return whether the remote device is currently connected*/
int is_connected = BTA_DmGetConnectionState(p_data->conn.remote_bda);
LOG_DEBUG("is_connected=%d\n",is_connected);
@ -217,15 +268,15 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
break;
case BTA_GATTS_DISCONNECT_EVT:
//set the connection flag to true
blufi_cb_env.clcb.connected = false;
blufi_cb_env.connected = false;
break;
case BTA_GATTS_OPEN_EVT:
break;
case BTA_GATTS_CLOSE_EVT:
if(blufi_cb_env.clcb.connected && (blufi_cb_env.clcb.conn_id == p_data->conn.conn_id))
if(blufi_cb_env.connected && (blufi_cb_env.conn_id == p_data->conn.conn_id))
{
//set the connection channal congested flag to true
blufi_cb_env.clcb.congest = p_data->congest.congested;
blufi_cb_env.congest = p_data->congest.congested;
}
break;
case BTA_GATTS_LISTEN_EVT:
@ -237,111 +288,7 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
}
}
/*******************************************************************************
**
** Function blufi_create_service
**
** Description Create a Service for the blufi profile
**
** Returns NULL
**
*******************************************************************************/
void blufi_create_service(void)
{
tBTA_GATTS_IF server_if ;
tBT_UUID uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
UINT16 num_handle = BLUFI_HDL_NUM;
UINT8 inst = 0x00;
server_if = blufi_cb_env.gatt_if;
blufi_cb_env.inst_id = inst;
if(!blufi_cb_env.enabled)
{
LOG_ERROR("blufi service added error.");
return;
}
BTA_GATTS_CreateService(server_if, &uuid, inst, num_handle, true);
}
/*******************************************************************************
**
** Function blufi_env_clcb_alloc
**
** Description The function allocates a GATT profile connection link control block
**
** Returns NULL if not found. Otherwise pointer to the connection link block.
**
*******************************************************************************/
tBLUFI_CLCB *blufi_env_clcb_alloc (UINT16 conn_id, BD_ADDR remote_bda)
{
tBLUFI_CLCB *p_clcb = NULL;
p_clcb = &blufi_cb_env.clcb;
if(!p_clcb->in_use)
{
p_clcb->in_use = TRUE;
p_clcb->conn_id = conn_id;
p_clcb->connected = TRUE;
memcpy(p_clcb->remote_bda, remote_bda, BD_ADDR_LEN);
LOG_ERROR("p_clcb->conn_id = %x\n", conn_id);
}
return p_clcb;
}
/*******************************************************************************
**
** Function blufi_env_find_conn_id_by_bd_adddr
**
** Description The function searches all LCB with macthing bd address
**
** Returns total number of clcb found.
**
*******************************************************************************/
/*
UINT16 blufi_env_find_conn_id_by_bd_adddr(BD_ADDR remote_bda)
{
UINT8 i_clcb;
tBLUFI_CLCB *p_clcb = NULL;
for(i_clcb = 0, p_clcb = &blufi_cb_env.clcb; i_clcb < BLUFIT_MAX_APPS; i_clcb++, p_clcb++)
{
if(p_clcb->in_use && p_clcb->connected && memcmp(p_clcb->remote_bda, remote_bda, BD_ADDR_LEN) == 0)
{
return p_clcb->conn_id;
}
}
return GATT_INVALID_CONN_ID;
}
*/
/*******************************************************************************
**
** Function blufi_env_clcb_dealloc
**
** Description The function deallocates a GATT profile connection link control block
**
** Returns True the deallocation is successful
**
*******************************************************************************/
BOOLEAN blufi_env_clcb_dealloc(UINT16 conn_id)
{
// UINT8 i_clcb = 0;
// tBLUFI_CLCB *p_clcb = NULL;
return FALSE;
}
/*******************************************************************************
**
** Function blufi_init
**
** Description Initializa the GATT Service for blufi profiles.
**
*******************************************************************************/
tGATT_STATUS blufi_profile_init (tBLUFI_CBACK *call_back)
static tGATT_STATUS btc_blufi_profile_init(void)
{
tBT_UUID app_uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
@ -356,12 +303,6 @@ tGATT_STATUS blufi_profile_init (tBLUFI_CBACK *call_back)
memset(&blufi_cb_env,0,sizeof(tBLUFI_CB_ENV));
}
if(call_back != NULL)
{
blufi_cb_env.blufi_inst.blufi_cback = call_back;
}
/* register the blufi profile to the BTA_GATTS module*/
BTA_GATTS_AppRegister(&app_uuid, blufi_profile_cb);
@ -369,14 +310,14 @@ tGATT_STATUS blufi_profile_init (tBLUFI_CBACK *call_back)
return GATT_SUCCESS;
}
void blufi_msg_notify(UINT8 *blufi_msg, UINT8 len)
static void blufi_msg_notify(UINT8 *blufi_msg, UINT8 len)
{
BOOLEAN conn_status = blufi_cb_env.clcb.connected;
UINT16 conn_id = blufi_cb_env.clcb.conn_id;
BOOLEAN conn_status = blufi_cb_env.connected;
UINT16 conn_id = blufi_cb_env.conn_id;
UINT16 attr_id = blufi_cb_env.blufi_inst.blufi_hdl;
//notify rsp==false; indicate rsp==true.
BOOLEAN rsp = false;
if(!conn_status && blufi_cb_env.clcb.congest)
if(!conn_status && blufi_cb_env.congest)
{
LOG_ERROR("the conneciton for blufi profile has been loss");
return;
@ -386,14 +327,61 @@ void blufi_msg_notify(UINT8 *blufi_msg, UINT8 len)
blufi_msg, rsp);
}
void blufi_config_success(void)
static void btc_blufi_config_success(void)
{
uint8_t *success_msg = "BLUFI_CONFIG_OK";
LOG_DEBUG("config success\n");
blufi_msg_notify(success_msg, strlen(success_msg));
}
void blufi_config_failed(void)
static void btc_blufi_config_failed(void)
{
uint8_t *failed_msg = "BLUFI_CONFIG_FAILED";
LOG_DEBUG("config faield\n");
blufi_msg_notify(failed_msg, strlen(failed_msg));
}
void btc_blufi_cb_handler(btc_msg_t *msg)
{
esp_blufi_cb_param_t param;
switch (msg->act) {
case BTC_BLUFI_CB_ACT_INIT_FINISH:
param.init_finish.state = ESP_BLUFI_INIT_OK;
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_INIT_FINISH, &param);
break;
case BTC_BLUFI_CB_ACT_DEINIT_FINISH:
/* TODO: but now nothing */
break;
case BTC_BLUFI_CB_ACT_RECV_DATA:
memcpy(&param.recv_data, msg->arg, sizeof(struct blufi_recv_evt_param));
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_DATA, &param);
break;
default:
LOG_ERROR("%s UNKNOWN %d\n", msg->act);
break;
}
}
void btc_blufi_call_handler(btc_msg_t *msg)
{
btc_blufi_args_t *arg = (btc_blufi_args_t *)msg->arg;
switch (msg->act) {
case BTC_BLUFI_ACT_INIT:
btc_blufi_profile_init();
break;
case BTC_BLUFI_ACT_DEINIT:
/* TODO: but now nothing */
break;
case BTC_BLUFI_ACT_SEND_CFG_STATE:
if (arg->cfg_state.state == ESP_BLUFI_CONFIG_OK) {
btc_blufi_config_success();
} else {
btc_blufi_config_failed();
}
break;
default:
LOG_ERROR("%s UNKNOWN %d\n", msg->act);
break;
}
}

View file

@ -0,0 +1,40 @@
#ifndef __BLUFI_INT_H__
#define __BLUFI_INT_H__
//define the blufi serivce uuid
#define SVC_BLUFI_UUID 0xFFFF
//define the blufi Char uuid
#define CHAR_BLUFI_UUID 0xFF01
#define BLUFI_HDL_NUM 4
#define BLUFI_VAL_MAX_LEN (128)
#define BLUFI_MAX_STRING_DATA 128
typedef struct
{
UINT8 app_id;
UINT16 blufi_hdl;
}tBLUFI_INST;
/* service engine control block */
typedef struct
{
BOOLEAN enabled;
BOOLEAN is_primery;
UINT8 inst_id;
tGATT_IF gatt_if;
tBLUFI_INST blufi_inst;
BOOLEAN in_use;
BOOLEAN congest;
UINT16 conn_id;
BOOLEAN connected;
BD_ADDR remote_bda;
UINT32 trans_id;
UINT8 cur_srvc_id;
} tBLUFI_CB_ENV;
#endif /* __BLUFI_INT_H__ */

View file

@ -1,76 +0,0 @@
#include "bt_target.h"
#include "gatt_api.h"
#include "gattdefs.h"
//define the blufi serivce uuid
#define SVC_BLUFI_UUID 0xFFFF
//define the blufi Char uuid
#define CHAR_BLUFI_UUID 0xFF01
#define BLUFI_HDL_NUM 4
#define BLUFI_VAL_MAX_LEN (20)
#define BLUFI_MAX_STRING_DATA 33
typedef void (tBLUFI_CBACK)(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *data);
typedef enum
{
RECV_ACT_PASSWD = 0,
RECV_ACT_SSID,
RECV_ACT_MAX
} RECV_ACTION;
typedef struct
{
BD_ADDR remote_bda;
BOOLEAN need_rsp;
UINT16 clt_cfg;
} tBLUFI_WRITE_DATA;
typedef struct
{
BOOLEAN in_use;
BOOLEAN congest;
UINT16 conn_id;
BOOLEAN connected;
BD_ADDR remote_bda;
UINT32 trans_id;
UINT8 cur_srvc_id;
} tBLUFI_CLCB;
typedef struct
{
UINT8 app_id;
UINT16 blufi_hdl;
tBLUFI_CBACK* blufi_cback;
}tBLUFI_INST;
/* service engine control block */
typedef struct
{
BOOLEAN enabled;
BOOLEAN is_primery;
UINT8 inst_id;
tGATT_IF gatt_if;
tBLUFI_CLCB clcb; /* connection link*/
tBLUFI_INST blufi_inst;
} tBLUFI_CB_ENV;
void blufi_create_service(void);
tBLUFI_CLCB *blufi_env_clcb_alloc(UINT16 conn_id, BD_ADDR bda);
UINT16 blufi_env_find_conn_id_by_bd_adddr(BD_ADDR bda);
BOOLEAN blufi_env_clcb_dealloc(UINT16 conn_id);
tGATT_STATUS blufi_profile_init(tBLUFI_CBACK *call_back);
void blufi_msg_notify(UINT8 *blufi_msg, UINT8 len);

View file

@ -0,0 +1,38 @@
#ifndef __BTC_BLUFI_PRF_H__
#define __BTC_BLUFI_PRF_H__
#include "bt_target.h"
#include "btc_task.h"
#include "esp_blufi_api.h"
typedef enum {
BTC_BLUFI_ACT_INIT = 0,
BTC_BLUFI_ACT_DEINIT,
BTC_BLUFI_ACT_SEND_CFG_STATE,
} btc_blufi_act_t;
typedef enum {
BTC_BLUFI_CB_ACT_INIT_FINISH = 0,
BTC_BLUFI_CB_ACT_DEINIT_FINISH,
BTC_BLUFI_CB_ACT_RECV_DATA,
} btc_blufi_cb_act_t;
typedef union {
#if 0
//BTC_BLUFI_ACT_INIT = 0,
struct blufi_init_param {
} init;
//BTC_BLUFI_ACT_DEINIT,
struct blufi_deinit_param {
} deinit;
#endif
//BTC_BLUFI_ACT_SEND_CFG_STATE,
struct blufi_send_cfg_state_pram {
esp_blufi_config_state_t state;
} cfg_state;
} btc_blufi_args_t;
void btc_blufi_cb_handler(btc_msg_t *msg);
void btc_blufi_call_handler(btc_msg_t *msg);
#endif /* __BTC_BLUFI_PRF_H__ */

View file

@ -1548,7 +1548,7 @@ UINT8 *btm_ble_build_adv_data(tBTM_BLE_AD_MASK *p_data_mask, UINT8 **p_dst,
cp_len = len - MIN_ADV_LENGTH;
else
cp_len = p_data->p_manu->len;
LOG_ERROR("cp_len = %d\n,p_data->p_manu->len=%d\n",cp_len,p_data->p_manu->len);
LOG_DEBUG("cp_len = %d\n,p_data->p_manu->len=%d\n",cp_len,p_data->p_manu->len);
for(int i = 0; i < p_data->p_manu->len; i++)
{
LOG_DEBUG("p_data->p_manu->p_val[%d] = %x\n",i,p_data->p_manu->p_val[i]);
@ -1556,7 +1556,7 @@ UINT8 *btm_ble_build_adv_data(tBTM_BLE_AD_MASK *p_data_mask, UINT8 **p_dst,
*p++ = cp_len + 1;
*p++ = BTM_BLE_AD_TYPE_MANU;
ARRAY_TO_STREAM(p, p_data->p_manu->p_val, cp_len);
LOG_ERROR("p_addr = %p\n,p_data->p_manu->p_val = %p\n",p,p_data->p_manu->p_val);
LOG_DEBUG("p_addr = %p\n,p_data->p_manu->p_val = %p\n",p,p_data->p_manu->p_val);
len -= (cp_len + MIN_ADV_LENGTH);
data_mask &= ~BTM_BLE_AD_BIT_MANU;
}

View file

@ -32,7 +32,7 @@ COMPONENT_ADD_INCLUDEDIRS := bluedroid/bta/include \
CFLAGS += -Wno-error=unused-label -Wno-error=return-type -Wno-error=missing-braces -Wno-error=pointer-sign -Wno-error=parentheses
LIBS := btdm_app coexist
LIBS := btdm_app
COMPONENT_ADD_LDFLAGS := -lbt -L$(abspath lib) \
$(addprefix -l,$(LIBS)) \

View file

@ -26,65 +26,42 @@
#include <stdbool.h>
#include <stdio.h>
#include "bta_api.h"
#include "bta_gatt_api.h"
#include "controller.h"
#include "gatt_int.h"
#include "bt_trace.h"
#include "btm_api.h"
#include "bt_types.h"
#include "blufi_prf.h"
#include "blufi.h"
#include "blufi_adv.h"
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "esp_blufi_api.h"
static void BlufiDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data);
struct dm_evt {
tBTA_DM_SEC_EVT event;
tBTA_DM_SEC* p_data;
};
extern void wifi_set_blue_config(char *ssid, char *passwd);
#define HEADER_SSID "ssid"
#define HEADER_PASSWD "passwd"
#define HEADER_CONFIRM "confirm"
extern void wifi_set_blue_config(char *ssid, char *passwd);
static char tmp_ssid[33];
static char tmp_passwd[33];
static void BlufiDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data)
static char tmp_ssid[32 + 1];
static char tmp_passwd[64 + 1];
static void blufi_data_recv(uint8_t *data, int len)
{
char *p = NULL;
LOG_DEBUG("the data is:%s\n", p_data);
#if 0
switch(event)
{
case RECEIVE_NET_PASSWD_EVT:
LOG_ERROR("Received the network passwork");
break;
case RECEIVE_NET_SSD_EVT:
LOG_ERROR("Received the network SSID");
break;
default:
break;
}
#endif
p = strstr(p_data, HEADER_SSID);
LOG_DEBUG("the data is:%s\n", data);
p = strstr(data, HEADER_SSID);
if (p) {
LOG_ERROR("SSID: %s\n", p+strlen(HEADER_SSID)+1);
strcpy(tmp_ssid, p+strlen(HEADER_SSID)+1);
}
p = strstr(p_data, HEADER_PASSWD);
p = strstr(data, HEADER_PASSWD);
if (p) {
LOG_ERROR("PASSWORD: %s\n", p+strlen(HEADER_PASSWD)+1);
strcpy(tmp_passwd, p+strlen(HEADER_PASSWD)+1);
}
p = strstr(p_data, HEADER_CONFIRM);
p = strstr(data, HEADER_CONFIRM);
if (p) {
LOG_ERROR("CONFIRM\n");
wifi_set_blue_config(tmp_ssid, tmp_passwd);
@ -92,55 +69,42 @@ static void BlufiDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_dat
}
static esp_err_t blufi_dm_upstreams_evt(void *arg)
static void blufi_callback(uint32_t event, void *param)
{
struct dm_evt *evt = (struct dm_evt *)arg;
tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)evt->p_data;
switch (evt->event) {
case BTA_DM_ENABLE_EVT: {
/*set connectable,discoverable, pairable and paired only modes of local device*/
tBTA_DM_DISC disc_mode = BTA_DM_BLE_GENERAL_DISCOVERABLE;
tBTA_DM_CONN conn_mode = BTA_DM_BLE_CONNECTABLE;
BTA_DmSetVisibility(disc_mode, conn_mode, (uint8_t)BTA_DM_NON_PAIRABLE, (uint8_t)BTA_DM_CONN_ALL );
#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
/* Enable local privacy */
//BTA_DmBleConfigLocalPrivacy(BLE_LOCAL_PRIVACY_ENABLED);
do {
const controller_t *controller = controller_get_interface();
char bdstr[18];
bdaddr_to_string(controller->get_address(), bdstr, sizeof(bdstr));
LOG_DEBUG("BDA is: %s\n", bdstr);
} while (0);
#endif
blufi_profile_init(BlufiDataCallBack);
break;
default:
break;
}
/* actually, should post to blufi_task handle the procedure,
* now, as a demo, we do simplely */
switch (event) {
case ESP_BLUFI_EVENT_INIT_FINISH:
LOG_ERROR("blufi init finish\n");
break;
case ESP_BLUFI_EVENT_RECV_DATA: {
LOG_DEBUG("blufi recv data\n");
esp_blufi_cb_param_t *blufi_param = (esp_blufi_cb_param_t *)param;
blufi_data_recv(blufi_param->recv_data.data, blufi_param->recv_data.data_len);
break;
}
default:
break;
}
}
GKI_freebuf(evt);
static esp_err_t blufi_startup_in_blufi_task(void *arg)
{
/*set connectable,discoverable, pairable and paired only modes of local device*/
tBTA_DM_DISC disc_mode = BTA_DM_BLE_GENERAL_DISCOVERABLE;
tBTA_DM_CONN conn_mode = BTA_DM_BLE_CONNECTABLE;
BTA_DmSetVisibility(disc_mode, conn_mode, (uint8_t)BTA_DM_NON_PAIRABLE, (uint8_t)BTA_DM_CONN_ALL);
esp_blufi_register_callback(blufi_callback);
esp_blufi_profile_init();
return ESP_OK;
}
void blufi_bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data)
static void blufi_startup(void)
{
struct dm_evt *evt;
LOG_DEBUG("%s: %d\n", __func__, (uint16_t)event);
evt = (struct dm_evt *)GKI_getbuf(sizeof(struct dm_evt));
if (evt == NULL)
return;
evt->event = event;
evt->p_data = p_data;
blufi_transfer_context(blufi_dm_upstreams_evt, evt);
blufi_transfer_context(blufi_startup_in_blufi_task, NULL);
}
esp_err_t blufi_enable(void *arg)
@ -149,7 +113,12 @@ esp_err_t blufi_enable(void *arg)
BTM_SetTraceLevel(BT_TRACE_LEVEL_ERROR);
err = esp_enable_bluetooth(blufi_bte_dm_evt);
err = esp_enable_bluetooth();
if (err) {
LOG_ERROR("%s failed\n", __func__);
return err;
}
blufi_startup();
vTaskDelay(1000 / portTICK_PERIOD_MS);
return err;

View file

@ -93,8 +93,8 @@ static void blufi_task_deinit(void)
static void blufi_task_init(void)
{
xBlufiTaskQueue = xQueueCreate(10, sizeof(BtTaskEvt_t));
xTaskCreate(blufi_task, "BlUFI", 8192, NULL, configMAX_PRIORITIES - 3, xBlufiTaskHandle);
xBlufiTaskQueue = xQueueCreate(5, sizeof(BtTaskEvt_t));
xTaskCreate(blufi_task, "BlUFI", 4096, NULL, configMAX_PRIORITIES - 3, xBlufiTaskHandle);
}
void blufi_init(void) {

View file

@ -26,6 +26,7 @@
#include "bt.h"
#include "bta_api.h"
#include "esp_blufi_api.h"
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "blufi.h"
@ -42,7 +43,6 @@ const int CONNECTED_BIT = BIT0;
static wifi_scan_config_t scan_config;
static wifi_config_t sta_config;
static char tmp_ssid[33];
@ -59,8 +59,6 @@ void wifi_set_blue_config(char *ssid, char *passwd)
LOG_DEBUG("confirm true\n");
}
extern void blufi_config_failed(void);
extern void blufi_config_success(void);
static esp_err_t event_handler(void *ctx, system_event_t *event)
{
switch(event->event_id) {
@ -69,7 +67,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
break;
case SYSTEM_EVENT_STA_GOT_IP:
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
blufi_config_success();
esp_blufi_send_config_state(ESP_BLUFI_CONFIG_OK);
esp_disable_bluetooth(); //close bluetooth function
//esp_deinit_bluetooth(); //free bluetooth resource
break;
@ -98,7 +96,6 @@ static void initialise_wifi(void)
}
static int loop = 0;
void wifiTestTask(void *pvParameters)
{
esp_err_t ret;
@ -119,7 +116,7 @@ void wifiTestTask(void *pvParameters)
ret = esp_wifi_connect();
if (ret != ESP_OK) {
LOG_ERROR("esp_wifi connect failed\n");
blufi_config_failed();
esp_blufi_send_config_state(ESP_BLUFI_CONFIG_FAILED);
}
}
}
@ -133,10 +130,16 @@ void app_main()
system_init();
initialise_wifi();
vTaskDelay(3000 / portTICK_PERIOD_MS);
//vTaskDelay(3000 / portTICK_PERIOD_MS);
bt_controller_init();
xTaskCreatePinnedToCore(&wifiTestTask, "wifiTestTask", 2048, NULL, 20, NULL, 0);
esp_init_bluetooth(blufi_init);
LOG_ERROR("%s init bluetooth\n", __func__);
ret = esp_init_bluetooth();
if (ret) {
LOG_ERROR("%s init bluetooth failed\n", __func__);
return;
}
blufi_init();
}