控制器 && VHCI

应用程序示例

请检查 ESP-IDF 示例中的 bluetooth 文件夹,它包含如下示例:

bluetooth/ble_adv

这是一个带有虚拟 HCI 接口的 BLE 广播 demo。BLE 广播时发送 Reset/ADV_PARAM/ADV_DATA/ADV_ENABLE HCI 命令。

API 参考手册

头文件

类型定义

typedef struct esp_vhci_host_callback esp_vhci_host_callback_t

esp_vhci_host_callback used for vhci call host function to notify what host need to do

枚举

enum esp_bt_mode_t

Bluetooth mode for controller enable/disable.

Values:

ESP_BT_MODE_IDLE = 0x00

Bluetooth is not running

ESP_BT_MODE_BLE = 0x01

Run BLE mode

ESP_BT_MODE_CLASSIC_BT = 0x02

Run Classic BT mode

ESP_BT_MODE_BTDM = 0x03

Run dual mode

结构体

struct esp_bt_controller_config_t

Controller config options, depend on config mask. Config mask indicate which functions enabled, this means some options or parameters of some functions enabled by config mask.

Public Members

uint8_t hci_uart_no

If use UART1/2 as HCI IO interface, indicate UART number

uint32_t hci_uart_baudrate

If use UART1/2 as HCI IO interface, indicate UART baudrate

struct esp_vhci_host_callback

esp_vhci_host_callback used for vhci call host function to notify what host need to do

Public Members

void (*notify_host_send_available)(void)

callback used to notify that the host can send packet to controller

int (*notify_host_recv)(uint8_t *data, uint16_t len)

callback used to notify that the controller has a packet to send to the host

函数

esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)

Initialize BT controller to allocate task and other resource.

Return
ESP_OK - success, other - failed
Parameters
  • cfg: Initial configuration of BT controller. This function should be called only once, before any other BT functions are called.

void esp_bt_controller_deinit(void)

De-initialize BT controller to free resource and delete task.

This function should be called only once, after any other BT functions are called. This function is not whole completed, esp_bt_controller_init cannot called after this function.

esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)

Enable BT controller.

Return
ESP_OK - success, other - failed
Parameters
  • mode: : the mode(BLE/BT/BTDM) to enable. Now only support BTDM.

esp_err_t esp_bt_controller_disable(esp_bt_mode_t mode)

Disable BT controller.

Return
ESP_OK - success, other - failed
Parameters
  • mode: : the mode(BLE/BT/BTDM) to disable. Now only support BTDM.

esp_bt_controller_status_t esp_bt_controller_get_status(void)

Get BT controller is initialised/de-initialised/enabled/disabled.

Return
status value

bool esp_vhci_host_check_send_available(void)

esp_vhci_host_check_send_available used for check actively if the host can send packet to controller or not.

Return
true for ready to send, false means cannot send packet

void esp_vhci_host_send_packet(uint8_t *data, uint16_t len)

esp_vhci_host_send_packet host send packet to controller

Parameters
  • data: the packet point ,
  • len: the packet length

void esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback)

esp_vhci_host_register_callback register the vhci referece callback, the call back struct defined by vhci_host_callback structure.

Parameters