esp_coexist.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef __ESP_COEXIST_H__
  7. #define __ESP_COEXIST_H__
  8. #include <stdbool.h>
  9. #include "esp_err.h"
  10. #include "hal/gpio_types.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define EXTERNAL_COEXIST_WIRE_1 0
  15. #define EXTERNAL_COEXIST_WIRE_2 1
  16. #define EXTERNAL_COEXIST_WIRE_3 2
  17. #define EXTERNAL_COEXIST_WIRE_4 3
  18. /**
  19. * @brief coex prefer value
  20. */
  21. typedef enum {
  22. ESP_COEX_PREFER_WIFI = 0, /*!< Prefer to WiFi, WiFi will have more opportunity to use RF */
  23. ESP_COEX_PREFER_BT, /*!< Prefer to bluetooth, bluetooth will have more opportunity to use RF */
  24. ESP_COEX_PREFER_BALANCE, /*!< Do balance of WiFi and bluetooth */
  25. ESP_COEX_PREFER_NUM, /*!< Prefer value numbers */
  26. } esp_coex_prefer_t;
  27. typedef enum {
  28. EXTERN_COEX_WIRE_1 = EXTERNAL_COEXIST_WIRE_1,
  29. EXTERN_COEX_WIRE_2 = EXTERNAL_COEXIST_WIRE_2,
  30. EXTERN_COEX_WIRE_3 = EXTERNAL_COEXIST_WIRE_3,
  31. EXTERN_COEX_WIRE_4 = EXTERNAL_COEXIST_WIRE_4,
  32. EXTERN_COEX_WIRE_NUM,
  33. } external_coex_wire_t;
  34. /**
  35. * @brief coex status type
  36. */
  37. typedef enum {
  38. ESP_COEX_ST_TYPE_WIFI = 0,
  39. ESP_COEX_ST_TYPE_BLE,
  40. ESP_COEX_ST_TYPE_BT,
  41. } esp_coex_status_type_t;
  42. #if CONFIG_EXTERNAL_COEX_ENABLE
  43. /**
  44. * @brief external coex gpio pti
  45. */
  46. typedef struct {
  47. union {
  48. uint32_t in_pin0 __attribute__((deprecated("Use 'request' instead")));
  49. gpio_num_t request; /**< request gpio signal from follower to leader */
  50. };
  51. union {
  52. uint32_t in_pin1 __attribute__((deprecated("Use 'priority' instead")));
  53. gpio_num_t priority; /**< request gpio signal priority from follower to leader */
  54. };
  55. union {
  56. uint32_t out_pin0 __attribute__((deprecated("Use 'grant' instead")));
  57. gpio_num_t grant; /**< grant gpio signal from leader to follower */
  58. };
  59. union {
  60. uint32_t out_pin1 __attribute__((deprecated("Use 'tx_line' instead")));
  61. gpio_num_t tx_line; /**< tx_line gpio signal from leader to follower, indicates whether the leader's WiFi is transmitting or not*/
  62. };
  63. } esp_external_coex_gpio_set_t;
  64. /**
  65. * @brief external coex pti level
  66. */
  67. typedef enum {
  68. EXTERN_COEX_PTI_MID = 0,
  69. EXTERN_COEX_PTI_HIGH,
  70. EXTERN_COEX_PTI_NUM,
  71. } esp_coex_pti_level_t;
  72. /**
  73. * @brief external coex role
  74. */
  75. typedef enum {
  76. EXTERNAL_COEX_LEADER_ROLE = 0,
  77. EXTERNAL_COEX_FOLLOWER_ROLE = 2,
  78. EXTERNAL_COEX_UNKNOWN_ROLE,
  79. } esp_extern_coex_work_mode_t;
  80. /**
  81. * @brief external coex advance setup
  82. */
  83. typedef struct {
  84. esp_extern_coex_work_mode_t work_mode;
  85. uint8_t delay_us;
  86. bool is_high_valid;
  87. } esp_external_coex_advance_t;
  88. #endif
  89. #define ESP_COEX_BLE_ST_MESH_CONFIG 0x08
  90. #define ESP_COEX_BLE_ST_MESH_TRAFFIC 0x10
  91. #define ESP_COEX_BLE_ST_MESH_STANDBY 0x20
  92. #define ESP_COEX_BT_ST_A2DP_STREAMING 0x10
  93. #define ESP_COEX_BT_ST_A2DP_PAUSED 0x20
  94. /**
  95. * @brief Get software coexist version string
  96. *
  97. * @return : version string
  98. */
  99. const char *esp_coex_version_get(void);
  100. /**
  101. * @deprecated Use esp_coex_status_bit_set() and esp_coex_status_bit_clear() instead.
  102. * Set coexist preference of performance
  103. * For example, if prefer to bluetooth, then it will make A2DP(play audio via classic bt)
  104. * more smooth while wifi is runnning something.
  105. * If prefer to wifi, it will do similar things as prefer to bluetooth.
  106. * Default, it prefer to balance.
  107. *
  108. * @param prefer : the prefer enumeration value
  109. * @return : ESP_OK - success, other - failed
  110. */
  111. esp_err_t esp_coex_preference_set(esp_coex_prefer_t prefer);
  112. /**
  113. * @brief Set coex schm status
  114. * @param type : WIFI/BLE/BT
  115. * @param status : WIFI/BLE/BT STATUS
  116. * @return : ESP_OK - success, other - failed
  117. */
  118. esp_err_t esp_coex_status_bit_set(esp_coex_status_type_t type, uint32_t status);
  119. /**
  120. * @brief Clear coex schm status
  121. * @param type : WIFI/BLE/BT
  122. * @param status : WIFI/BLE/BT STATUS
  123. * @return : ESP_OK - success, other - failed
  124. */
  125. esp_err_t esp_coex_status_bit_clear(esp_coex_status_type_t type, uint32_t status);
  126. #if CONFIG_EXTERNAL_COEX_ENABLE
  127. /**
  128. * @brief Configure work mode, the default work mode is leader role.
  129. * @param work_mode : work mode.
  130. * @return : ESP_OK - success, other - failed
  131. */
  132. esp_err_t esp_external_coex_set_work_mode(esp_extern_coex_work_mode_t work_mode);
  133. /**
  134. * @brief Setup gpio pin and corresponding pti level, start external coex,
  135. * the default work mode is leader role, the default output grant validate pin is high,
  136. * and the default delay output grant value is zero.
  137. * @param wire_type : to select the whole external coex gpio number.
  138. * @param gpio_pin : gpio pin number to choose.
  139. * @return : ESP_OK - success, other - failed
  140. */
  141. esp_err_t esp_enable_extern_coex_gpio_pin(external_coex_wire_t wire_type,
  142. esp_external_coex_gpio_set_t gpio_pin);
  143. /**
  144. * @brief Disable external coex.
  145. * @return : ESP_OK - success, other - failed
  146. */
  147. esp_err_t esp_disable_extern_coex_gpio_pin();
  148. #if SOC_EXTERNAL_COEX_ADVANCE
  149. /**
  150. * @brief Configure leader work mode, gpio pin correspondly and finally enable external coex,
  151. * demand not to call the legacy function of `esp_enable_extern_coex_gpio_pin` any more.
  152. * @param wire_type : to select the whole external coex gpio number.
  153. * @param request : request gpio pin number to select.
  154. * @param priority : priority gpio pin number to select.
  155. * @param grant : grant gpio pin number to select.
  156. * @return : ESP_OK - success, other - failed
  157. */
  158. esp_err_t esp_external_coex_leader_role_set_gpio_pin(external_coex_wire_t wire_type, uint32_t request, uint32_t priority,
  159. uint32_t grant) __attribute__((deprecated("Please use esp_external_coex_set_work_mode and esp_enable_extern_coex_gpio_pin instead")));
  160. /**
  161. * @brief Configure follower work mode, gpio pin correspondly and finally enable external coex,
  162. * demand not to call the legacy function of `esp_enable_extern_coex_gpio_pin` any more.
  163. * @param wire_type : to select the whole external coex gpio number.
  164. * @param request : request gpio pin number to select.
  165. * @param priority : priority gpio pin number to select.
  166. * @param grant : grant gpio pin number to select.
  167. * @return : ESP_OK - success, other - failed
  168. */
  169. esp_err_t esp_external_coex_follower_role_set_gpio_pin(external_coex_wire_t wire_type, uint32_t request, uint32_t priority,
  170. uint32_t grant) __attribute__((deprecated("Please use esp_external_coex_set_work_mode and esp_enable_extern_coex_gpio_pin instead")));
  171. /**
  172. * @brief Configure output grant signal latency in delay microseconds only for leader role of external coex,
  173. * demand to call this function before `esp_external_coex_leader_role_set_gpio_pin`,
  174. * if users want to setup output delay value.
  175. * @param delay_us : to setup how many microseconds the output signal performs latency.
  176. * @return : ESP_OK - success, other - failed
  177. */
  178. esp_err_t esp_external_coex_set_grant_delay(uint8_t delay_us);
  179. /**
  180. * @brief Configure output grant signal is high validate or not only for leader role of external coex,
  181. * demand to call this function before `esp_external_coex_leader_role_set_gpio_pin`,
  182. * if users want to setup output grant validate pin value.
  183. * @param is_high_valid : to select true means the output grant signal validate is high, other - validate is low.
  184. * @return : ESP_OK - success, other - failed
  185. */
  186. esp_err_t esp_external_coex_set_validate_high(bool is_high_valid);
  187. #endif /* SOC_EXTERNAL_COEX_ADVANCE */
  188. #endif /* CONFIG_EXTERNAL_COEX_ENABLE */
  189. #if CONFIG_ESP_COEX_SW_COEXIST_ENABLE && CONFIG_SOC_IEEE802154_SUPPORTED
  190. /**
  191. * @brief Enable Wi-Fi and 802.15.4 coexistence.
  192. * @return : ESP_OK - success, other - failed
  193. */
  194. esp_err_t esp_coex_wifi_i154_enable(void);
  195. #endif
  196. #ifdef __cplusplus
  197. }
  198. #endif
  199. #endif /* __ESP_COEXIST_H__ */