bt.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**
  22. * @brief Bluetooth mode for controller enable/disable
  23. */
  24. typedef enum {
  25. ESP_BT_MODE_ILDE = 0x00, /*!< Bluetooth is not run */
  26. ESP_BT_MODE_BLE = 0x01, /*!< Run BLE mode */
  27. ESP_BT_MODE_CLASSIC_BT = 0x02, /*!< Run Classic BT mode */
  28. ESP_BT_MODE_BTDM = 0x03, /*!< Run dual mode */
  29. } esp_bt_mode_t;
  30. /**
  31. * @brief Bluetooth controller enable/disable/initialised/de-initialised status
  32. */
  33. typedef enum {
  34. ESP_BT_CONTROLLER_STATUS_IDLE = 0,
  35. ESP_BT_CONTROLLER_STATUS_INITED,
  36. ESP_BT_CONTROLLER_STATUS_ENABLED,
  37. ESP_BT_CONTROLLER_STATUS_NUM,
  38. } esp_bt_controller_status_t;
  39. /**
  40. * @brief Initialize BT controller to allocate task and other resource.
  41. *
  42. * This function should be called only once, before any other BT functions are called.
  43. */
  44. void esp_bt_controller_init(void);
  45. /**
  46. * @brief De-initialize BT controller to free resource and delete task.
  47. *
  48. * This function should be called only once, after any other BT functions are called.
  49. * This function is not whole completed, esp_bt_controller_init cannot called after this function.
  50. */
  51. void esp_bt_controller_deinit(void);
  52. /**
  53. * @brief Enable BT controller
  54. * @param mode : the mode(BLE/BT/BTDM) to enable.
  55. * Now only support BTDM.
  56. * @return ESP_OK - success, other - failed
  57. */
  58. esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode);
  59. /**
  60. * @brief Disable BT controller
  61. * @param mode : the mode(BLE/BT/BTDM) to disable.
  62. * Now only support BTDM.
  63. * @return ESP_OK - success, other - failed
  64. */
  65. esp_err_t esp_bt_controller_disable(esp_bt_mode_t mode);
  66. /**
  67. * @brief Get BT controller is initialised/de-initialised/enabled/disabled
  68. * @return status value
  69. */
  70. esp_bt_controller_status_t esp_bt_controller_get_status(void);
  71. /** @brief esp_vhci_host_callback
  72. * used for vhci call host function to notify what host need to do
  73. */
  74. typedef struct esp_vhci_host_callback {
  75. void (*notify_host_send_available)(void); /*!< callback used to notify that the host can send packet to controller */
  76. 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*/
  77. } esp_vhci_host_callback_t;
  78. /** @brief esp_vhci_host_check_send_available
  79. * used for check actively if the host can send packet to controller or not.
  80. * @return true for ready to send, false means cannot send packet
  81. */
  82. bool esp_vhci_host_check_send_available(void);
  83. /** @brief esp_vhci_host_send_packet
  84. * host send packet to controller
  85. * @param data the packet point
  86. *,@param len the packet length
  87. */
  88. void esp_vhci_host_send_packet(uint8_t *data, uint16_t len);
  89. /** @brief esp_vhci_host_register_callback
  90. * register the vhci referece callback, the call back
  91. * struct defined by vhci_host_callback structure.
  92. * @param callback esp_vhci_host_callback type variable
  93. */
  94. void esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback);
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif /* __BT_H__ */