feat(bt/bluedroid): Add new version of API for Bluedroid host stack initialization

This commit is contained in:
liqigan
2023-08-29 16:49:49 +08:00
committed by BOT
parent d9da8f1953
commit 0df585dc35
81 changed files with 756 additions and 370 deletions

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -7,6 +7,9 @@
#ifndef __ESP_BT_MAIN_H__
#define __ESP_BT_MAIN_H__
#include <stdbool.h>
#include <stdint.h>
#include "esp_err.h"
#ifdef __cplusplus
@@ -22,6 +25,18 @@ typedef enum {
ESP_BLUEDROID_STATUS_ENABLED /*!< Bluetooth initialized and enabled */
} esp_bluedroid_status_t;
/**
* @brief Bluetooth stack configuration
*/
typedef struct {
bool ssp_en; /*!< Whether SSP(secure simple pairing) or legacy pairing is used for Classic Bluetooth */
} esp_bluedroid_config_t;
#define BT_BLUEDROID_INIT_CONFIG_DEFAULT() \
{ \
.ssp_en = true, \
}
/**
* @brief Get bluetooth stack status
*
@@ -31,7 +46,7 @@ typedef enum {
esp_bluedroid_status_t esp_bluedroid_get_status(void);
/**
* @brief Enable bluetooth, must after esp_bluedroid_init().
* @brief Enable bluetooth, must after esp_bluedroid_init()/esp_bluedroid_init_with_cfg().
*
* @return
* - ESP_OK : Succeed
@@ -55,7 +70,18 @@ esp_err_t esp_bluedroid_disable(void);
* - ESP_OK : Succeed
* - Other : Failed
*/
esp_err_t esp_bluedroid_init(void);
esp_err_t esp_bluedroid_init(void) __attribute__((deprecated("Please use esp_bluedroid_init_with_cfg")));
/**
* @brief Init and alloc the resource for bluetooth, must be prior to every bluetooth stuff.
*
* @param cfg Initial configuration of ESP Bluedroid stack.
*
* @return
* - ESP_OK : Succeed
* - Other : Failed
*/
esp_err_t esp_bluedroid_init_with_cfg(esp_bluedroid_config_t *cfg);
/**
* @brief Deinit and free the resource for bluetooth, must be after every bluetooth stuff.

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -277,9 +277,10 @@ typedef void (*esp_hd_cb_t)(esp_hidd_cb_event_t event, esp_hidd_cb_param_t *para
esp_err_t esp_bt_hid_device_register_callback(esp_hd_cb_t callback);
/**
* @brief Initializes HIDD interface. This function should be called after esp_bluedroid_init() and
* esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_register_callback.
* When the operation is complete, the callback function will be called with ESP_HIDD_INIT_EVT.
* @brief Initializes HIDD interface. This function should be called after
* esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be
* called after esp_bt_hid_device_register_callback. When the operation is complete, the callback
* function will be called with ESP_HIDD_INIT_EVT.
*
* @return
* - ESP_OK: success
@@ -288,9 +289,10 @@ esp_err_t esp_bt_hid_device_register_callback(esp_hd_cb_t callback);
esp_err_t esp_bt_hid_device_init(void);
/**
* @brief De-initializes HIDD interface. This function should be called after esp_bluedroid_init() and
* esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init(). When the
* operation is complete, the callback function will be called with ESP_HIDD_DEINIT_EVT.
* @brief De-initializes HIDD interface. This function should be called after
* esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be
* called after esp_bt_hid_device_init(). When the operation is complete, the callback function will be
* called with ESP_HIDD_DEINIT_EVT.
*
* @return
* - ESP_OK: success
@@ -300,9 +302,9 @@ esp_err_t esp_bt_hid_device_deinit(void);
/**
* @brief Registers HIDD parameters with SDP and sets l2cap Quality of Service. This function should be
* called after esp_bluedroid_init() and esp_bluedroid_enable() success, and should be called after
* esp_bt_hid_device_init(). When the operation is complete, the callback function will be called
* with ESP_HIDD_REGISTER_APP_EVT.
* called after esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success,
* and should be called after esp_bt_hid_device_init(). When the operation is complete, the callback
* function will be called with ESP_HIDD_REGISTER_APP_EVT.
*
* @param[in] app_param: HIDD parameters
* @param[in] in_qos: incoming QoS parameters
@@ -317,9 +319,9 @@ esp_err_t esp_bt_hid_device_register_app(esp_hidd_app_param_t *app_param, esp_hi
/**
* @brief Removes HIDD parameters from SDP and resets l2cap Quality of Service. This function should be
* called after esp_bluedroid_init() and esp_bluedroid_enable() success, and should be called after
* esp_bt_hid_device_init(). When the operation is complete, the callback function will be called
* with ESP_HIDD_UNREGISTER_APP_EVT.
* called after esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success,
* and should be called after esp_bt_hid_device_init(). When the operation is complete, the callback
* function will be called with ESP_HIDD_UNREGISTER_APP_EVT.
*
* @return
* - ESP_OK: success
@@ -329,8 +331,9 @@ esp_err_t esp_bt_hid_device_unregister_app(void);
/**
* @brief Connects to the peer HID Host with virtual cable. This function should be called after
* esp_bluedroid_init() and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init().
* When the operation is complete, the callback function will be called with ESP_HIDD_OPEN_EVT.
* esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be
* called after esp_bt_hid_device_init(). When the operation is complete, the callback function will
* be called with ESP_HIDD_OPEN_EVT.
*
* @param[in] bd_addr: Remote host bluetooth device address.
*
@@ -342,8 +345,9 @@ esp_err_t esp_bt_hid_device_connect(esp_bd_addr_t bd_addr);
/**
* @brief Disconnects from the currently connected HID Host. This function should be called after
* esp_bluedroid_init() and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init().
* When the operation is complete, the callback function will be called with ESP_HIDD_CLOSE_EVT.
* esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be
* called after esp_bt_hid_device_init(). When the operation is complete, the callback function will
* be called with ESP_HIDD_CLOSE_EVT.
*
* @note The disconnect operation will not remove the virtually cabled device. If the connect request from the
* different HID Host, it will reject the request.
@@ -356,8 +360,9 @@ esp_err_t esp_bt_hid_device_disconnect(void);
/**
* @brief Sends HID report to the currently connected HID Host. This function should be called after
* esp_bluedroid_init() and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init().
* When the operation is complete, the callback function will be called with ESP_HIDD_SEND_REPORT_EVT.
* esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be
* called after esp_bt_hid_device_init(). When the operation is complete, the callback function will
* be called with ESP_HIDD_SEND_REPORT_EVT.
*
* @param[in] type: type of report
* @param[in] id: report id as defined by descriptor
@@ -372,9 +377,9 @@ esp_err_t esp_bt_hid_device_send_report(esp_hidd_report_type_t type, uint8_t id,
/**
* @brief Sends HID Handshake with error info for invalid set_report to the currently connected HID Host.
* This function should be called after esp_bluedroid_init() and esp_bluedroid_enable() success, and
* should be called after esp_bt_hid_device_init(). When the operation is complete, the callback
* function will be called with ESP_HIDD_REPORT_ERR_EVT.
* This function should be called after esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and
* esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init(). When the
* operation is complete, the callback function will be called with ESP_HIDD_REPORT_ERR_EVT.
*
* @param[in] error: type of error
*
@@ -385,9 +390,10 @@ esp_err_t esp_bt_hid_device_send_report(esp_hidd_report_type_t type, uint8_t id,
esp_err_t esp_bt_hid_device_report_error(esp_hidd_handshake_error_t error);
/**
* @brief Remove the virtually cabled device. This function should be called after esp_bluedroid_init()
* and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init(). When the
* operation is complete, the callback function will be called with ESP_HIDD_VC_UNPLUG_EVT.
* @brief Remove the virtually cabled device. This function should be called after
* esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be
* called after esp_bt_hid_device_init(). When the operation is complete, the callback function will be
* called with ESP_HIDD_VC_UNPLUG_EVT.
*
* @note If the connection exists, then HID Device will send a `VIRTUAL_CABLE_UNPLUG` control command to
* the peer HID Host, and the connection will be destroyed. If the connection does not exist, then HID

View File

@@ -318,8 +318,9 @@ esp_err_t esp_bt_hid_host_register_callback(esp_hh_cb_t callback);
/**
* @brief This function initializes HID host. This function should be called after esp_bluedroid_enable() and
* esp_bluedroid_init() success, and should be called after esp_bt_hid_host_register_callback().
* When the operation is complete the callback function will be called with ESP_HIDH_INIT_EVT.
* esp_bluedroid_init()/esp_bluedroid_init_with_cfg() success, and should be called after
* esp_bt_hid_host_register_callback(). When the operation is complete the callback function will be called
* with ESP_HIDH_INIT_EVT.
*
* @return
* - ESP_OK: success
@@ -329,7 +330,7 @@ esp_err_t esp_bt_hid_host_init(void);
/**
* @brief Closes the interface. This function should be called after esp_bluedroid_enable() and
* esp_bluedroid_init() success, and should be called after esp_bt_hid_host_init().
* esp_bluedroid_init()/esp_bluedroid_init_with_cfg() success, and should be called after esp_bt_hid_host_init().
* When the operation is complete the callback function will be called with ESP_HIDH_DEINIT_EVT.
*
* @return - ESP_OK: success