Select one of the symbols to view example projects that use it.
 
Outline
#include "esp_coexist.h"
#include "private/esp_coexist_internal.h"
#include "soc/soc_caps.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "esp_rom_gpio.h"
#include "hal/gpio_hal.h"
#include "esp_attr.h"
#include "esp_private/gpio.h"
#include "esp_private/esp_modem_clock.h"
#define EXTERNAL_COEX_SIGNAL_I0_IDX
#define EXTERNAL_COEX_SIGNAL_I1_IDX
#define EXTERNAL_COEX_SIGNAL_O0_IDX
#define EXTERNAL_COEX_SIGNAL_O1_IDX
#define EXTERNAL_COEX_SIGNAL_I0_IDX
#define EXTERNAL_COEX_SIGNAL_I1_IDX
#define EXTERNAL_COEX_SIGNAL_O0_IDX
#define EXTERNAL_COEX_SIGNAL_O1_TXLINE_IDX
esp_coex_version_get()
esp_coex_preference_set(esp_coex_prefer_t)
#define GPIO_PIN_REG
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/esp_coex/src/coexist.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include "esp_coexist.h" #include "private/esp_coexist_internal.h" #include "soc/soc_caps.h" #if CONFIG_EXTERNAL_COEX_ENABLE #include "esp_log.h" #include "driver/gpio.h" #include "esp_rom_gpio.h" #include "hal/gpio_hal.h" #include "esp_attr.h" #include "esp_private/gpio.h"/* ... */ #endif #if SOC_MODEM_CLOCK_IS_INDEPENDENT #include "esp_private/esp_modem_clock.h" #endif #if SOC_EXTERNAL_COEX_ADVANCE #define EXTERNAL_COEX_SIGNAL_I0_IDX EXTERN_ACTIVE_I_IDX #define EXTERNAL_COEX_SIGNAL_I1_IDX EXTERN_PRIORITY_I_IDX #define EXTERNAL_COEX_SIGNAL_O0_IDX EXTERN_ACTIVE_O_IDX #define EXTERNAL_COEX_SIGNAL_O1_IDX EXTERN_PRIORITY_O_IDX/* ... */ #else #define EXTERNAL_COEX_SIGNAL_I0_IDX GPIO_BT_ACTIVE_IDX #define EXTERNAL_COEX_SIGNAL_I1_IDX GPIO_BT_PRIORITY_IDX #define EXTERNAL_COEX_SIGNAL_O0_IDX GPIO_WLAN_ACTIVE_IDX/* ... */ #endif #if SOC_EXTERNAL_COEX_LEADER_TX_LINE #define EXTERNAL_COEX_SIGNAL_O1_TXLINE_IDX BB_DIAG9_IDX #endif const char *esp_coex_version_get(void) { return coex_version_get(); }{ ... } esp_err_t esp_coex_preference_set(esp_coex_prefer_t prefer) { return coex_preference_set((coex_prefer_t)prefer); }{ ... } #if CONFIG_EXTERNAL_COEX_ENABLE #define GPIO_PIN_REG(a) (GPIO_PIN0_REG + a * 0x04) static const char *TAG = "external_coex"; static esp_external_coex_advance_t g_external_coex_params = { EXTERNAL_COEX_LEADER_ROLE, 0, true }; esp_err_t esp_external_coex_set_work_mode(esp_extern_coex_work_mode_t work_mode) { #if !SOC_EXTERNAL_COEX_ADVANCE if(work_mode != EXTERNAL_COEX_LEADER_ROLE) { return ESP_ERR_INVALID_ARG; }{...} /* ... */#endif g_external_coex_params.work_mode = work_mode; return ESP_OK; }{...} bool is_legal_external_coex_gpio(external_coex_wire_t wire_type, esp_external_coex_gpio_set_t gpio_pin) { switch (wire_type) { case EXTERN_COEX_WIRE_4: { if(!GPIO_IS_VALID_GPIO(gpio_pin.tx_line) || gpio_pin.tx_line == gpio_pin.priority || gpio_pin.tx_line == gpio_pin.grant || gpio_pin.tx_line == gpio_pin.request) { return false; }{...} }{...} __attribute__((fallthrough));... case EXTERN_COEX_WIRE_3: { if(!GPIO_IS_VALID_GPIO(gpio_pin.priority) || gpio_pin.priority == gpio_pin.grant || gpio_pin.priority == gpio_pin.request) { return false; }{...} }{...} __attribute__((fallthrough));... case EXTERN_COEX_WIRE_2: { if(!GPIO_IS_VALID_GPIO(gpio_pin.grant) || gpio_pin.grant == gpio_pin.request) { return false; }{...} }{...} __attribute__((fallthrough));... case EXTERN_COEX_WIRE_1: { if(!GPIO_IS_VALID_GPIO(gpio_pin.request)) { return false; }{...} break; }{...} default: return false;... }{...} return true; }{...} #if SOC_EXTERNAL_COEX_ADVANCE esp_err_t esp_external_coex_set_gpio_pin(esp_external_coex_gpio_set_t *gpio_pin, external_coex_wire_t wire_type, uint32_t request, uint32_t priority, uint32_t grant) { switch (wire_type) { case EXTERN_COEX_WIRE_3: gpio_pin->priority = priority; __attribute__((fallthrough));... case EXTERN_COEX_WIRE_2: gpio_pin->grant = grant; __attribute__((fallthrough));... case EXTERN_COEX_WIRE_1: { gpio_pin->request = request; break; }{...} default: { gpio_pin->request = request; gpio_pin->priority = priority; gpio_pin->grant = grant; break; }{...} }{...} return ESP_OK; }{...} esp_err_t esp_external_coex_set_grant_delay(uint8_t delay_us) { g_external_coex_params.delay_us = delay_us; return ESP_OK; }{...} esp_err_t esp_external_coex_set_validate_high(bool is_high_valid) { g_external_coex_params.is_high_valid = is_high_valid; return ESP_OK; }{...} esp_err_t esp_external_coex_leader_role_set_gpio_pin(external_coex_wire_t wire_type, uint32_t request, uint32_t priority, uint32_t grant) { esp_external_coex_set_work_mode(EXTERNAL_COEX_LEADER_ROLE); esp_external_coex_gpio_set_t gpio_pin; esp_external_coex_set_gpio_pin(&gpio_pin, wire_type, request, priority, grant); return esp_enable_extern_coex_gpio_pin(wire_type, gpio_pin); }{...} esp_err_t esp_external_coex_follower_role_set_gpio_pin(external_coex_wire_t wire_type, uint32_t request, uint32_t priority, uint32_t grant) { esp_external_coex_set_work_mode(EXTERNAL_COEX_FOLLOWER_ROLE); esp_external_coex_gpio_set_t gpio_pin; esp_external_coex_set_gpio_pin(&gpio_pin, wire_type, request, priority, grant); return esp_enable_extern_coex_gpio_pin(wire_type, gpio_pin); }{...} /* ... */#endif /* SOC_EXTERNAL_COEX_ADVANCE */ esp_err_t esp_enable_extern_coex_gpio_pin(external_coex_wire_t wire_type, esp_external_coex_gpio_set_t gpio_pin) { if(false == is_legal_external_coex_gpio(wire_type, gpio_pin)) { ESP_LOGE(TAG, "Configure external coex with unexpected gpio pin!!!"); return ESP_ERR_INVALID_ARG; }{...} esp_coex_external_set_wire_type(wire_type); if(EXTERNAL_COEX_LEADER_ROLE == g_external_coex_params.work_mode) { switch (wire_type) { #if SOC_EXTERNAL_COEX_LEADER_TX_LINE case EXTERN_COEX_WIRE_4: { esp_coex_external_set_txline(true); gpio_func_sel(gpio_pin.tx_line, PIN_FUNC_GPIO); gpio_set_direction(gpio_pin.tx_line, GPIO_MODE_OUTPUT); REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT(gpio_pin.tx_line)); esp_rom_gpio_connect_out_signal(gpio_pin.tx_line, EXTERNAL_COEX_SIGNAL_O1_TXLINE_IDX, false, false); }{...} __attribute__((fallthrough));/* ... */ #endif case EXTERN_COEX_WIRE_3: { gpio_func_sel(gpio_pin.priority, PIN_FUNC_GPIO); gpio_set_direction(gpio_pin.priority, GPIO_MODE_INPUT); esp_rom_gpio_connect_in_signal(gpio_pin.priority, EXTERNAL_COEX_SIGNAL_I1_IDX, false); REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.priority), GPIO_PIN1_SYNC1_BYPASS, 2); REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.priority), GPIO_PIN1_SYNC2_BYPASS, 2); }{...} __attribute__((fallthrough));... case EXTERN_COEX_WIRE_2: { gpio_func_sel(gpio_pin.grant, PIN_FUNC_GPIO); gpio_set_direction(gpio_pin.grant, GPIO_MODE_OUTPUT); REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT(gpio_pin.grant)); esp_rom_gpio_connect_out_signal(gpio_pin.grant, EXTERNAL_COEX_SIGNAL_O0_IDX, false, false); }{...} __attribute__((fallthrough));... case EXTERN_COEX_WIRE_1: { gpio_func_sel(gpio_pin.request, PIN_FUNC_GPIO); gpio_set_direction(gpio_pin.request, GPIO_MODE_INPUT); esp_rom_gpio_connect_in_signal(gpio_pin.request, EXTERNAL_COEX_SIGNAL_I0_IDX, false); REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.request), GPIO_PIN1_SYNC1_BYPASS, 2); REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.request), GPIO_PIN1_SYNC2_BYPASS, 2); break; }{...} default: { return ESP_FAIL; }{...} }{...} }{...} else if(EXTERNAL_COEX_FOLLOWER_ROLE == g_external_coex_params.work_mode) { #if SOC_EXTERNAL_COEX_ADVANCE switch (wire_type) { case EXTERN_COEX_WIRE_4: { gpio_func_sel(gpio_pin.tx_line, PIN_FUNC_GPIO); gpio_set_direction(gpio_pin.tx_line, GPIO_MODE_INPUT); esp_rom_gpio_connect_in_signal(gpio_pin.tx_line, EXTERNAL_COEX_SIGNAL_I1_IDX, false); REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.tx_line), GPIO_PIN1_SYNC1_BYPASS, 2); REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.tx_line), GPIO_PIN1_SYNC2_BYPASS, 2); }{...} __attribute__((fallthrough));... case EXTERN_COEX_WIRE_3: { gpio_func_sel(gpio_pin.priority, PIN_FUNC_GPIO); gpio_set_direction(gpio_pin.priority, GPIO_MODE_OUTPUT); REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT(gpio_pin.priority)); esp_rom_gpio_connect_out_signal(gpio_pin.priority, EXTERNAL_COEX_SIGNAL_O1_IDX, false, false); }{...} __attribute__((fallthrough));... case EXTERN_COEX_WIRE_2: { gpio_func_sel(gpio_pin.grant, PIN_FUNC_GPIO); gpio_set_direction(gpio_pin.grant, GPIO_MODE_INPUT); esp_rom_gpio_connect_in_signal(gpio_pin.grant, EXTERNAL_COEX_SIGNAL_I0_IDX, false); REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.grant), GPIO_PIN1_SYNC1_BYPASS, 2); REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.grant), GPIO_PIN1_SYNC2_BYPASS, 2); }{...} __attribute__((fallthrough));... case EXTERN_COEX_WIRE_1: { gpio_func_sel(gpio_pin.request, PIN_FUNC_GPIO); gpio_set_direction(gpio_pin.request, GPIO_MODE_OUTPUT); REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT(gpio_pin.request)); esp_rom_gpio_connect_out_signal(gpio_pin.request, EXTERNAL_COEX_SIGNAL_O0_IDX, false, false); break; }{...} default: { return ESP_FAIL; }{...} }{...} /* ... */#else return ESP_ERR_INVALID_ARG; #endif /* SOC_EXTERNAL_COEX_ADVANCE */ }{...} #if SOC_MODEM_CLOCK_IS_INDEPENDENT modem_clock_module_enable(PERIPH_COEX_MODULE); #endif #if SOC_EXTERNAL_COEX_ADVANCE esp_coex_external_params(g_external_coex_params, 0, 0); #endif esp_err_t ret = esp_coex_external_set(EXTERN_COEX_PTI_MID, EXTERN_COEX_PTI_MID, EXTERN_COEX_PTI_HIGH); #if SOC_MODEM_CLOCK_IS_INDEPENDENT modem_clock_module_disable(PERIPH_COEX_MODULE); #endif if (ESP_OK != ret) { return ESP_FAIL; }{...} return ESP_OK; }{...} esp_err_t esp_disable_extern_coex_gpio_pin(void) { esp_coex_external_stop(); return ESP_OK; }{...} /* ... */#endif /* External Coex */ #if CONFIG_ESP_COEX_SW_COEXIST_ENABLE && CONFIG_SOC_IEEE802154_SUPPORTED esp_err_t esp_coex_wifi_i154_enable(void) { // TODO: Add a scheme for wifi and 154 coex. // Remove this function if FCC-50 closes. coex_enable(); coex_schm_status_bit_set(1, 1); return ESP_OK; }{...} /* ... */#endif
Details
Show:
from
Types: Columns: