esp_coexist.h 7.5 KB

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