esp_coexist.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 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. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * @brief coex prefer value
  15. */
  16. typedef enum {
  17. ESP_COEX_PREFER_WIFI = 0, /*!< Prefer to WiFi, WiFi will have more opportunity to use RF */
  18. ESP_COEX_PREFER_BT, /*!< Prefer to bluetooth, bluetooth will have more opportunity to use RF */
  19. ESP_COEX_PREFER_BALANCE, /*!< Do balance of WiFi and bluetooth */
  20. ESP_COEX_PREFER_NUM, /*!< Prefer value numbers */
  21. } esp_coex_prefer_t;
  22. typedef enum {
  23. EXTERN_COEX_WIRE_1 = 0,
  24. EXTERN_COEX_WIRE_2,
  25. EXTERN_COEX_WIRE_3,
  26. EXTERN_COEX_WIRE_NUM,
  27. } external_coex_wire_t;
  28. /**
  29. * @brief coex status type
  30. */
  31. typedef enum {
  32. ESP_COEX_ST_TYPE_WIFI = 0,
  33. ESP_COEX_ST_TYPE_BLE,
  34. ESP_COEX_ST_TYPE_BT,
  35. } esp_coex_status_type_t;
  36. #if CONFIG_EXTERNAL_COEX_ENABLE
  37. /**
  38. * @brief external coex gpio pti
  39. */
  40. typedef struct {
  41. uint32_t in_pin0;
  42. uint32_t in_pin1;
  43. uint32_t out_pin0;
  44. uint32_t out_pin1;
  45. } esp_external_coex_gpio_set_t;
  46. /**
  47. * @brief external coex pti level
  48. */
  49. typedef enum {
  50. EXTERN_COEX_PTI_MID = 0,
  51. EXTERN_COEX_PTI_HIGH,
  52. EXTERN_COEX_PTI_NUM,
  53. } esp_coex_pti_level_t;
  54. /**
  55. * @brief external coex follower pti
  56. */
  57. typedef struct {
  58. uint32_t pti_val1;
  59. uint32_t pti_val2;
  60. } esp_external_coex_follower_pti_t;
  61. /**
  62. * @brief external coex role
  63. */
  64. typedef enum {
  65. EXTERNAL_COEX_LEADER_ROLE = 0,
  66. EXTERNAL_COEX_FOLLOWER_ROLE = 2,
  67. EXTERNAL_COEX_UNKNOWN_ROLE,
  68. } esp_extern_coex_work_mode_t;
  69. /**
  70. * @brief external coex wiretype & role composition
  71. */
  72. typedef enum {
  73. wire_3_leader_mode = 0,
  74. wire_2_leader_mode,
  75. wire_1_leader_mode,
  76. wire_3_follower_mode,
  77. wire_2_follower_mode,
  78. wire_1_follower_mode,
  79. } external_coex_classification;
  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 Setup gpio pin and corresponding pti level, start external coex,
  129. * the default work mode is leader role, the default output grant validate pin is high,
  130. * and the default delay output grant value is zero.
  131. * @param wire_type : to select the whole external coex gpio number.
  132. * @param gpio_pin : gpio pin number to choose.
  133. * @return : ESP_OK - success, other - failed
  134. */
  135. esp_err_t esp_enable_extern_coex_gpio_pin(external_coex_wire_t wire_type,
  136. esp_external_coex_gpio_set_t gpio_pin);
  137. /**
  138. * @brief Disable external coex.
  139. * @return : ESP_OK - success, other - failed
  140. */
  141. esp_err_t esp_disable_extern_coex_gpio_pin();
  142. #if SOC_EXTERNAL_COEX_ADVANCE
  143. /**
  144. * @brief Configure leader work mode, gpio pin correspondly and finally enable external coex,
  145. * demand not to call the legacy function of `esp_enable_extern_coex_gpio_pin` any more.
  146. * @param wire_type : to select the whole external coex gpio number.
  147. * @param gpio_pin : gpio pin number to select.
  148. * @return : ESP_OK - success, other - failed
  149. */
  150. esp_err_t esp_external_coex_leader_role_set_gpio_pin(external_coex_wire_t wire_type, uint32_t in_pin0,
  151. uint32_t in_pin1, uint32_t out_pin0);
  152. /**
  153. * @brief Configure follower work mode, gpio pin correspondly and finally enable external coex,
  154. * demand not to call the legacy function of `esp_enable_extern_coex_gpio_pin` any more.
  155. * @param wire_type : to select the whole external coex gpio number.
  156. * @param gpio_pin : gpio pin number to select.
  157. * @return : ESP_OK - success, other - failed
  158. */
  159. esp_err_t esp_external_coex_follower_role_set_gpio_pin(external_coex_wire_t wire_type, uint32_t in_pin0,
  160. uint32_t out_pin0, uint32_t out_pin1);
  161. /**
  162. * @brief Configure output grant signal latency in delay microseconds only for leader role of external coex,
  163. * demand to call this function before `esp_external_coex_leader_role_set_gpio_pin`,
  164. * if users want to setup output delay value.
  165. * @param delay_us : to setup how many microseconds the output signal performs latency.
  166. * @return : ESP_OK - success, other - failed
  167. */
  168. esp_err_t esp_external_coex_set_grant_delay(uint8_t delay_us);
  169. /**
  170. * @brief Configure output grant signal is high validate or not only for leader role of external coex,
  171. * demand to call this function before `esp_external_coex_leader_role_set_gpio_pin`,
  172. * if users want to setup output grant validate pin value.
  173. * @param is_high_valid : to select true means the output grant signal validate is high, other - validate is low.
  174. * @return : ESP_OK - success, other - failed
  175. */
  176. esp_err_t esp_external_coex_set_validate_high(bool is_high_valid);
  177. #endif
  178. #endif
  179. #if CONFIG_ESP_COEX_SW_COEXIST_ENABLE && CONFIG_SOC_IEEE802154_SUPPORTED
  180. /**
  181. * @brief Enable Wi-Fi and 802.15.4 coexistence.
  182. * @return : ESP_OK - success, other - failed
  183. */
  184. esp_err_t esp_coex_wifi_i154_enable(void);
  185. #endif
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189. #endif /* __ESP_COEXIST_H__ */