]> granicus.if.org Git - esp-idf/commitdiff
component/bt: add module btc_gap_bt and port function esp_bt_gap_set_scan_mode
authorwangmengyang <wangmengyang@espressif.com>
Fri, 24 Feb 2017 09:28:33 +0000 (17:28 +0800)
committerwangmengyang <wangmengyang@espressif.com>
Fri, 24 Feb 2017 09:28:33 +0000 (17:28 +0800)
components/bt/bluedroid/api/esp_gap_bt_api.c [new file with mode: 0644]
components/bt/bluedroid/api/include/esp_gap_bt_api.h
components/bt/bluedroid/btc/core/btc_main.c
components/bt/bluedroid/btc/core/btc_task.c
components/bt/bluedroid/btc/profile/std/gap/btc_gap_bt.c
components/bt/bluedroid/btc/profile/std/include/btc_gap_bt.h
examples/09_a2dp/components/bluedroid_demos/app_project/SampleAV.c

diff --git a/components/bt/bluedroid/api/esp_gap_bt_api.c b/components/bt/bluedroid/api/esp_gap_bt_api.c
new file mode 100644 (file)
index 0000000..7b74435
--- /dev/null
@@ -0,0 +1,39 @@
+// 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 <string.h>
+
+#include "esp_bt_main.h"
+#include "esp_gap_bt_api.h"
+#include "bt_trace.h"
+#include "btc_manage.h"
+#include "btc_gap_bt.h"
+
+esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode)
+{
+    btc_msg_t msg;
+    btc_gap_bt_args_t arg;
+
+    if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
+        return ESP_ERR_INVALID_STATE;
+    }
+    
+    msg.sig = BTC_SIG_API_CALL;
+    msg.pid = BTC_PID_GAP_BT;
+    msg.act = BTC_GAP_BT_ACT_SET_SCAN_MODE;
+    arg.scan_mode.mode = mode;
+
+    return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+}
+
index 393d33a1d017b222c656bf434ace6c2bc5f16f6d..6f7df2cad61d21045714f4d059cd46536295b8ae 100644 (file)
@@ -25,10 +25,10 @@ extern "C" {
 
 /// Discoverability and Connectability mode
 typedef enum {
-    BT_SCAN_MODE_NONE = 0,                      /*!< Neither discoverable nor connectable */
-    BT_SCAN_MODE_CONNECTABLE,                   /*!< Connectable but not discoverable */
-    BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE       /*!< both discoverable and connectaable */
-} bt_scan_mode_t;
+    ESP_BT_SCAN_MODE_NONE = 0,                      /*!< Neither discoverable nor connectable */
+    ESP_BT_SCAN_MODE_CONNECTABLE,                   /*!< Connectable but not discoverable */
+    ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE       /*!< both discoverable and connectaable */
+} esp_bt_scan_mode_t;
 
 /**
  * @brief           Set discoverability and connectability mode for legacy bluetooth
@@ -39,7 +39,7 @@ typedef enum {
  *                  - ESP_OK : Succeed
  *                  - ESP_ERR_INVALID_ARG: if argument invalid
  */
-esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode);
+esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode);
 
 
 /**
index 323a81f75ac98ff755dc22a86cea3318d875f4fe..d4c98dffe1d58b6beca72a5a1f1b630810e2b19b 100644 (file)
@@ -43,14 +43,14 @@ static void btc_enable_bluetooth(void)
 {
     if (BTA_EnableBluetooth(btc_sec_callback) != BTA_SUCCESS) {
         future_ready(*btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE), FUTURE_FAIL);
-       }
+    }
 }
 
 static void btc_disable_bluetooth(void)
 {
     if (BTA_DisableBluetooth() != BTA_SUCCESS) {
         future_ready(*btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE), FUTURE_FAIL);
-       }
+    }
 }
 
 void btc_init_callback(void)
index a245f54d287b9e993adc39b3de6811bc42c97afc..6e88afaabb355d7cd89bca0f0b3235b917934f27 100644 (file)
@@ -23,6 +23,7 @@
 #include "btc_gatts.h"
 #include "btc_gattc.h"
 #include "btc_gap_ble.h"
+#include "btc_gap_bt.h"
 #include "btc_blufi_prf.h"
 #include "bta_gatt_api.h"
 
@@ -35,7 +36,7 @@ static btc_func_t profile_tab[BTC_PID_NUM] = {
     [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  },
-    [BTC_PID_GAP_BT]    = {NULL, NULL}, // {btc_gap_bt_call_handler,    btc_gap_bt_cb_handler   },
+    [BTC_PID_GAP_BT]    = {btc_gap_bt_call_handler,     btc_gap_bt_cb_handler   },
     [BTC_PID_SDP]       = {NULL, NULL},
     [BTC_PID_BLE_HID]   = {NULL, NULL},
     [BTC_PID_BT_HID]    = {NULL, NULL},
index 275e600dfaa2bccf340fe79e9ce3d98d2324a192..ee6dd82653d70df5a5c6d38e25c40515aa4d379a 100644 (file)
 // limitations under the License.
 
 #include "esp_gap_bt_api.h"
+#include "btc_gap_bt.h"
 #include "bta_api.h"
 #include "bt_trace.h"
 #include <string.h>
 
-esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode)
+void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
+{
+    switch (msg->act) {
+    default:
+        // LOG_ERROR("Unhandled deep copy %d\n", msg->act);
+        break;
+    }
+}
+
+static void btc_gap_bt_arg_deep_free(btc_msg_t *msg)
+{
+    LOG_DEBUG("%s \n", __func__);
+    switch (msg->act) {
+    default:
+        // LOG_DEBUG("Unhandled deep free %d\n", msg->act);
+        break;
+    }
+}
+
+static void btc_bt_set_scan_mode(esp_bt_scan_mode_t mode)
 {
     tBTA_DM_DISC disc_mode;
     tBTA_DM_CONN conn_mode;
 
     switch (mode) {
-    case BT_SCAN_MODE_NONE:
+    case ESP_BT_SCAN_MODE_NONE:
         disc_mode = BTA_DM_NON_DISC;
         conn_mode = BTA_DM_NON_CONN;
         break;
 
-    case BT_SCAN_MODE_CONNECTABLE:
+    case ESP_BT_SCAN_MODE_CONNECTABLE:
         disc_mode = BTA_DM_NON_DISC;
         conn_mode = BTA_DM_CONN;
         break;
 
-    case BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE:
+    case ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE:
         disc_mode = BTA_DM_GENERAL_DISC;
         conn_mode = BTA_DM_CONN;
         break;
 
     default:
-        // BTIF_TRACE_ERROR("invalid scan mode (0x%x)", mode);
-        return ESP_ERR_INVALID_ARG;
+        LOG_WARN("invalid scan mode (0x%x)", mode);
+        return;
     }
 
-    // BTIF_TRACE_EVENT("set property scan mode : %x", mode);
     BTA_DmSetVisibility(disc_mode, conn_mode, BTA_DM_IGNORE, BTA_DM_IGNORE);
+    return;
+}
 
-    return ESP_OK;
+void btc_gap_bt_call_handler(btc_msg_t *msg)
+{
+    btc_gap_bt_args_t *arg = (btc_gap_bt_args_t *)msg->arg;
+    LOG_DEBUG("%s act %d\n", __func__, msg->act);
+    switch (msg->act) {
+    case BTC_GAP_BT_ACT_SET_SCAN_MODE: {
+        btc_bt_set_scan_mode(arg->scan_mode.mode);
+        break;
+    }
+    default:
+        break;
+    }
+    btc_gap_bt_arg_deep_free(msg);
 }
 
+/* to be fixed */
 esp_err_t esp_bt_gap_set_device_name(const char *name)
 {
     if (name == NULL || *name == '\0') {
index d6f2e5b535c7e5aa69009f9c88b434e05f04ba39..a1e1ee940e075406dfa76a07b32bbba4410abed9 100644 (file)
 #ifndef __BTC_GAP_BT_H__
 #define __BTC_GAP_BT_H__
 
+#include "esp_bt_defs.h"
+#include "esp_gap_bt_api.h"
+#include "btc_task.h"
 
+typedef enum {
+    BTC_GAP_BT_ACT_SET_SCAN_MODE = 0
+} btc_gap_bt_act_t;
 
+/* btc_gap_bt_args_t */
+typedef union {
+    // BTC_GAP_BT_ACT_SET_SCAN_MODE,
+    struct scan_mode_args {
+        esp_bt_scan_mode_t mode;
+    } scan_mode;
+} btc_gap_bt_args_t;
 
+void btc_gap_bt_call_handler(btc_msg_t *msg);
+void btc_gap_bt_cb_handler(btc_msg_t *msg);
 
-#define /* __BTC_GAP_BT_H__ */
+void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
+
+#endif /* __BTC_GAP_BT_H__ */
index 3bf8cf7f892c4ce359a000fbbc878e3158cb8e75..79c06343ec726b82de3e059e46c7b7aecf6089a8 100644 (file)
@@ -86,7 +86,7 @@ static void bt_app_handle_evt(uint16_t event, void *p_param)
         esp_avrc_ct_init();
         esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
         
-        esp_bt_gap_set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
+        esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
         break;
     }
     case ESP_A2D_CONNECTION_STATE_EVT: {