bt.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __BT_H__
  14. #define __BT_H__
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "esp_err.h"
  18. #include "sdkconfig.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /**
  23. * @brief Controller config options, depend on config mask.
  24. * Config mask indicate which functions enabled, this means
  25. * some options or parameters of some functions enabled by config mask.
  26. */
  27. typedef struct {
  28. uint8_t hci_uart_no; /*!< If use UART1/2 as HCI IO interface, indicate UART number */
  29. uint32_t hci_uart_baudrate; /*!< If use UART1/2 as HCI IO interface, indicate UART baudrate */
  30. } esp_bt_controller_config_t;
  31. #ifdef CONFIG_BT_ENABLED
  32. #ifdef CONFIG_BT_HCI_UART_NO
  33. #define BT_HCI_UART_NO_DEFAULT CONFIG_BT_HCI_UART_NO
  34. #else
  35. #define BT_HCI_UART_NO_DEFAULT 1
  36. #endif /* BT_HCI_UART_NO_DEFAULT */
  37. #ifdef CONFIG_BT_HCI_UART_BAUDRATE
  38. #define BT_HCI_UART_BAUDRATE_DEFAULT CONFIG_BT_HCI_UART_BAUDRATE
  39. #else
  40. #define BT_HCI_UART_BAUDRATE_DEFAULT 921600
  41. #endif /* BT_HCI_UART_BAUDRATE_DEFAULT */
  42. #define BT_CONTROLLER_INIT_CONFIG_DEFAULT() { \
  43. .hci_uart_no = BT_HCI_UART_NO_DEFAULT,\
  44. .hci_uart_baudrate = BT_HCI_UART_BAUDRATE_DEFAULT,\
  45. };
  46. #else
  47. #define BT_CONTROLLER_INIT_CONFIG_DEFAULT() {0}; _Static_assert(0, "please enable bluetooth in menuconfig to use bt.h");
  48. #endif
  49. /**
  50. * @brief Bluetooth mode for controller enable/disable
  51. */
  52. typedef enum {
  53. ESP_BT_MODE_IDLE = 0x00, /*!< Bluetooth is not running */
  54. ESP_BT_MODE_BLE = 0x01, /*!< Run BLE mode */
  55. ESP_BT_MODE_CLASSIC_BT = 0x02, /*!< Run Classic BT mode */
  56. ESP_BT_MODE_BTDM = 0x03, /*!< Run dual mode */
  57. } esp_bt_mode_t;
  58. /**
  59. * @brief Bluetooth controller enable/disable/initialised/de-initialised status
  60. */
  61. typedef enum {
  62. ESP_BT_CONTROLLER_STATUS_IDLE = 0,
  63. ESP_BT_CONTROLLER_STATUS_INITED,
  64. ESP_BT_CONTROLLER_STATUS_ENABLED,
  65. ESP_BT_CONTROLLER_STATUS_NUM,
  66. } esp_bt_controller_status_t;
  67. /**
  68. * @brief Initialize BT controller to allocate task and other resource.
  69. * @param cfg: Initial configuration of BT controller.
  70. * This function should be called only once, before any other BT functions are called.
  71. * @return ESP_OK - success, other - failed
  72. */
  73. esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg);
  74. /**
  75. * @brief De-initialize BT controller to free resource and delete task.
  76. *
  77. * This function should be called only once, after any other BT functions are called.
  78. * This function is not whole completed, esp_bt_controller_init cannot called after this function.
  79. */
  80. void esp_bt_controller_deinit(void);
  81. /**
  82. * @brief Enable BT controller
  83. * @param mode : the mode(BLE/BT/BTDM) to enable.
  84. * Now only support BTDM.
  85. * @return ESP_OK - success, other - failed
  86. */
  87. esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode);
  88. /**
  89. * @brief Disable BT controller
  90. * @param mode : the mode(BLE/BT/BTDM) to disable.
  91. * Now only support BTDM.
  92. * @return ESP_OK - success, other - failed
  93. */
  94. esp_err_t esp_bt_controller_disable(esp_bt_mode_t mode);
  95. /**
  96. * @brief Get BT controller is initialised/de-initialised/enabled/disabled
  97. * @return status value
  98. */
  99. esp_bt_controller_status_t esp_bt_controller_get_status(void);
  100. /** @brief esp_vhci_host_callback
  101. * used for vhci call host function to notify what host need to do
  102. */
  103. typedef struct esp_vhci_host_callback {
  104. void (*notify_host_send_available)(void); /*!< callback used to notify that the host can send packet to controller */
  105. 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*/
  106. } esp_vhci_host_callback_t;
  107. /** @brief esp_vhci_host_check_send_available
  108. * used for check actively if the host can send packet to controller or not.
  109. * @return true for ready to send, false means cannot send packet
  110. */
  111. bool esp_vhci_host_check_send_available(void);
  112. /** @brief esp_vhci_host_send_packet
  113. * host send packet to controller
  114. * @param data the packet point
  115. *,@param len the packet length
  116. */
  117. void esp_vhci_host_send_packet(uint8_t *data, uint16_t len);
  118. /** @brief esp_vhci_host_register_callback
  119. * register the vhci referece callback, the call back
  120. * struct defined by vhci_host_callback structure.
  121. * @param callback esp_vhci_host_callback type variable
  122. */
  123. void esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback);
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. #endif /* __BT_H__ */