mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/bluetooth_fix_API_esp_bt_gap_set_scan_mode' into 'master'
Modify esp_bt_gap_set_scan_mode() to be able to set connection modes as well as discoverable modes See merge request idf/esp-idf!2208
This commit is contained in:
commit
5beb2802e0
@ -37,7 +37,7 @@ esp_err_t esp_bt_gap_register_callback(esp_bt_gap_cb_t callback)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode)
|
||||
esp_err_t esp_bt_gap_set_scan_mode(esp_bt_connection_mode_t c_mode, esp_bt_discovery_mode_t d_mode)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_gap_bt_args_t arg;
|
||||
@ -49,7 +49,8 @@ esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode)
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BT;
|
||||
msg.act = BTC_GAP_BT_ACT_SET_SCAN_MODE;
|
||||
arg.set_scan_mode.mode = mode;
|
||||
arg.set_scan_mode.c_mode = c_mode;
|
||||
arg.set_scan_mode.d_mode = d_mode;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -47,10 +47,15 @@ typedef enum {
|
||||
|
||||
/// Discoverability and Connectability mode
|
||||
typedef enum {
|
||||
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 connectable */
|
||||
} esp_bt_scan_mode_t;
|
||||
ESP_BT_NON_CONNECTABLE, /*!< Non-connectable */
|
||||
ESP_BT_CONNECTABLE, /*!< Connectable */
|
||||
} esp_bt_connection_mode_t;
|
||||
|
||||
typedef enum {
|
||||
ESP_BT_NON_DISCOVERABLE, /*!< Non-discoverable */
|
||||
ESP_BT_LIMITED_DISCOVERABLE, /*!< Limited Discoverable */
|
||||
ESP_BT_GENERAL_DISCOVERABLE, /*!< General Discoverable */
|
||||
} esp_bt_discovery_mode_t;
|
||||
|
||||
/// Bluetooth Device Property type
|
||||
typedef enum {
|
||||
@ -350,7 +355,8 @@ esp_err_t esp_bt_gap_register_callback(esp_bt_gap_cb_t callback);
|
||||
* @brief Set discoverability and connectability mode for legacy bluetooth. This function should
|
||||
* be called after esp_bluedroid_enable() completes successfully
|
||||
*
|
||||
* @param[in] mode : one of the enums of bt_scan_mode_t
|
||||
* @param[in] c_mode : one of the enums of esp_bt_connection_mode_t
|
||||
* @param[in] d_mode : one of the enums of esp_bt_discovery_mode_t
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Succeed
|
||||
@ -358,7 +364,7 @@ esp_err_t esp_bt_gap_register_callback(esp_bt_gap_cb_t callback);
|
||||
* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
|
||||
* - ESP_FAIL: others
|
||||
*/
|
||||
esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode);
|
||||
esp_err_t esp_bt_gap_set_scan_mode(esp_bt_connection_mode_t c_mode, esp_bt_discovery_mode_t d_mode);
|
||||
|
||||
/**
|
||||
* @brief Start device discovery. This function should be called after esp_bluedroid_enable() completes successfully.
|
||||
|
@ -48,29 +48,35 @@ static inline void btc_gap_bt_cb_to_app(esp_bt_gap_cb_event_t event, esp_bt_gap_
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_bt_set_scan_mode(esp_bt_scan_mode_t mode)
|
||||
static void btc_bt_set_scan_mode(esp_bt_connection_mode_t c_mode, esp_bt_discovery_mode_t d_mode)
|
||||
{
|
||||
tBTA_DM_DISC disc_mode;
|
||||
tBTA_DM_CONN conn_mode;
|
||||
|
||||
switch (mode) {
|
||||
case ESP_BT_SCAN_MODE_NONE:
|
||||
disc_mode = BTA_DM_NON_DISC;
|
||||
switch (c_mode) {
|
||||
case ESP_BT_NON_CONNECTABLE:
|
||||
conn_mode = BTA_DM_NON_CONN;
|
||||
break;
|
||||
|
||||
case ESP_BT_SCAN_MODE_CONNECTABLE:
|
||||
disc_mode = BTA_DM_NON_DISC;
|
||||
case ESP_BT_CONNECTABLE:
|
||||
conn_mode = BTA_DM_CONN;
|
||||
break;
|
||||
|
||||
case ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE:
|
||||
disc_mode = BTA_DM_GENERAL_DISC;
|
||||
conn_mode = BTA_DM_CONN;
|
||||
break;
|
||||
|
||||
default:
|
||||
BTC_TRACE_WARNING("invalid scan mode (0x%x)", mode);
|
||||
BTC_TRACE_WARNING("invalid connection mode (0x%x)", c_mode);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (d_mode) {
|
||||
case ESP_BT_NON_DISCOVERABLE:
|
||||
disc_mode = BTA_DM_NON_DISC;
|
||||
break;
|
||||
case ESP_BT_LIMITED_DISCOVERABLE:
|
||||
disc_mode = BTA_DM_LIMITED_DISC;
|
||||
break;
|
||||
case ESP_BT_GENERAL_DISCOVERABLE:
|
||||
disc_mode = BTA_DM_GENERAL_DISC;
|
||||
break;
|
||||
default:
|
||||
BTC_TRACE_WARNING("invalid discovery mode (0x%x)", d_mode);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -761,7 +767,7 @@ void btc_gap_bt_call_handler(btc_msg_t *msg)
|
||||
BTC_TRACE_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->set_scan_mode.mode);
|
||||
btc_bt_set_scan_mode(arg->set_scan_mode.c_mode, arg->set_scan_mode.d_mode);
|
||||
break;
|
||||
}
|
||||
case BTC_GAP_BT_ACT_START_DISCOVERY: {
|
||||
|
@ -54,7 +54,8 @@ typedef enum {
|
||||
typedef union {
|
||||
// BTC_BT_GAP_ACT_SET_SCAN_MODE,
|
||||
struct set_bt_scan_mode_args {
|
||||
esp_bt_scan_mode_t mode;
|
||||
esp_bt_connection_mode_t c_mode;
|
||||
esp_bt_discovery_mode_t d_mode;
|
||||
} set_scan_mode;
|
||||
|
||||
// BTC_GAP_BT_ACT_START_DISCOVERY
|
||||
|
@ -618,7 +618,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
|
||||
esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
|
||||
|
||||
/* set discoverable and connectable mode, wait to be connected */
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -100,9 +100,9 @@ static void bt_av_hdl_a2d_evt(uint16_t event, void *p_param)
|
||||
ESP_LOGI(BT_AV_TAG, "A2DP connection state: %s, [%02x:%02x:%02x:%02x:%02x:%02x]",
|
||||
s_a2d_conn_state_str[a2d->conn_stat.state], bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
|
||||
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||
} else if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_CONNECTED){
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_NONE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_NON_CONNECTABLE, ESP_BT_NON_DISCOVERABLE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
|
||||
esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
|
||||
|
||||
/* set discoverable and connectable mode, wait to be connected */
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -328,7 +328,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
|
||||
esp_a2d_source_init();
|
||||
|
||||
/* set discoverable and connectable mode */
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||
|
||||
/* start device discovery */
|
||||
ESP_LOGI(BT_AV_TAG, "Starting device discovery...");
|
||||
@ -434,7 +434,7 @@ static void bt_app_av_state_connecting(uint16_t event, void *param)
|
||||
ESP_LOGI(BT_AV_TAG, "a2dp connected");
|
||||
s_a2d_state = APP_AV_STATE_CONNECTED;
|
||||
s_media_state = APP_AV_MEDIA_STATE_IDLE;
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_NONE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_NON_CONNECTABLE, ESP_BT_NON_DISCOVERABLE);
|
||||
} else if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
|
||||
s_a2d_state = APP_AV_STATE_UNCONNECTED;
|
||||
}
|
||||
@ -530,7 +530,7 @@ static void bt_app_av_state_connected(uint16_t event, void *param)
|
||||
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
|
||||
ESP_LOGI(BT_AV_TAG, "a2dp disconnected");
|
||||
s_a2d_state = APP_AV_STATE_UNCONNECTED;
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -564,7 +564,7 @@ static void bt_app_av_state_disconnecting(uint16_t event, void *param)
|
||||
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
|
||||
ESP_LOGI(BT_AV_TAG, "a2dp disconnected");
|
||||
s_a2d_state = APP_AV_STATE_UNCONNECTED;
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ void bt_app_gap_start_up(void)
|
||||
esp_bt_dev_set_device_name(dev_name);
|
||||
|
||||
/* set discoverable and connectable mode, wait to be connected */
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||
|
||||
/* register GAP callback function */
|
||||
esp_bt_gap_register_callback(bt_app_gap_cb);
|
||||
|
@ -57,7 +57,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
||||
case ESP_SPP_INIT_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
||||
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||
esp_spp_start_srv(sec_mask,role_slave, 0, SPP_SERVER_NAME);
|
||||
break;
|
||||
case ESP_SPP_DISCOVERY_COMP_EVT:
|
||||
|
@ -104,7 +104,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
||||
case ESP_SPP_INIT_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
||||
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||
esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps);
|
||||
|
||||
break;
|
||||
|
@ -76,7 +76,7 @@ static void esp_spp_cb(uint16_t e, void *p)
|
||||
case ESP_SPP_INIT_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
||||
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||
esp_spp_start_srv(sec_mask,role_slave, 0, SPP_SERVER_NAME);
|
||||
break;
|
||||
case ESP_SPP_DISCOVERY_COMP_EVT:
|
||||
|
@ -114,7 +114,7 @@ static void esp_spp_cb(uint16_t e, void *p)
|
||||
case ESP_SPP_INIT_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
||||
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||
esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps);
|
||||
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user