Select one of the symbols to view example projects that use it.
 
Outline
#include "common/bt_target.h"
#include "esp_bt_main.h"
#include "btc/btc_task.h"
#include "btc/btc_main.h"
#include "esp_bt.h"
#include "osi/future.h"
#include "osi/allocator.h"
#include "config/stack_config.h"
#include "hci_log/bt_hci_log.h"
#include "bt_common.h"
bd_already_enable
bd_already_init
esp_bluedroid_get_status()
esp_bluedroid_enable()
esp_bluedroid_disable()
esp_bluedroid_init()
esp_bluedroid_init_with_cfg(esp_bluedroid_config_t *)
esp_bluedroid_deinit()
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/bt/host/bluedroid/api/esp_bt_main.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include "common/bt_target.h" #include "esp_bt_main.h" #include "btc/btc_task.h" #include "btc/btc_main.h" #if (BT_CONTROLLER_INCLUDED == TRUE) #include "esp_bt.h" #endif #include "osi/future.h" #include "osi/allocator.h" #include "config/stack_config.h" #include "hci_log/bt_hci_log.h" #include "bt_common.h"5 includes static bool bd_already_enable = false; static bool bd_already_init = false; esp_bluedroid_status_t esp_bluedroid_get_status(void) { if (bd_already_init) { if (bd_already_enable) { return ESP_BLUEDROID_STATUS_ENABLED; }{...} else { return ESP_BLUEDROID_STATUS_INITIALIZED; }{...} }{...} else { return ESP_BLUEDROID_STATUS_UNINITIALIZED; }{...} }{ ... } esp_err_t esp_bluedroid_enable(void) { btc_msg_t msg; future_t **future_p; if (!bd_already_init) { LOG_ERROR("Bludroid not initialised\n"); return ESP_ERR_INVALID_STATE; }{...} if (bd_already_enable) { LOG_ERROR("Bluedroid already enabled\n"); return ESP_ERR_INVALID_STATE; }{...} future_p = btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE); *future_p = future_new(); if (*future_p == NULL) { LOG_ERROR("Bluedroid enable failed\n"); return ESP_ERR_NO_MEM; }{...} msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_MAIN_INIT; msg.act = BTC_MAIN_ACT_ENABLE; if (btc_transfer_context(&msg, NULL, 0, NULL, NULL) != BT_STATUS_SUCCESS) { LOG_ERROR("Bluedroid enable failed\n"); return ESP_FAIL; }{...} if (future_await(*future_p) == FUTURE_FAIL) { LOG_ERROR("Bluedroid enable failed\n"); return ESP_FAIL; }{...} bd_already_enable = true; return ESP_OK; }{ ... } esp_err_t esp_bluedroid_disable(void) { btc_msg_t msg; future_t **future_p; if (!bd_already_enable) { LOG_ERROR("Bluedroid already disabled\n"); return ESP_ERR_INVALID_STATE; }{...} future_p = btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE); *future_p = future_new(); if (*future_p == NULL) { LOG_ERROR("Bluedroid disable failed\n"); return ESP_ERR_NO_MEM; }{...} msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_MAIN_INIT; msg.act = BTC_MAIN_ACT_DISABLE; if (btc_transfer_context(&msg, NULL, 0, NULL, NULL) != BT_STATUS_SUCCESS) { LOG_ERROR("Bluedroid disable failed\n"); return ESP_FAIL; }{...} if (future_await(*future_p) == FUTURE_FAIL) { LOG_ERROR("Bluedroid disable failed\n"); return ESP_FAIL; }{...} bd_already_enable = false; return ESP_OK; }{ ... } esp_err_t esp_bluedroid_init(void) { esp_bluedroid_config_t cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); return esp_bluedroid_init_with_cfg(&cfg); }{ ... } esp_err_t esp_bluedroid_init_with_cfg(esp_bluedroid_config_t *cfg) { btc_msg_t msg; future_t **future_p; bt_status_t ret; if (!cfg) { LOG_ERROR("%s cfg is NULL", __func__); return ESP_ERR_INVALID_ARG; }{...} #if (BT_CONTROLLER_INCLUDED == TRUE) if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) { LOG_ERROR("Controller not initialised\n"); return ESP_ERR_INVALID_STATE; }{...} #endif/* ... */ if (bd_already_init) { LOG_ERROR("Bluedroid already initialised\n"); return ESP_ERR_INVALID_STATE; }{...} #if HEAP_MEMORY_DEBUG osi_mem_dbg_init(); #endif ret = bluedriod_config_init(cfg); if (ret != BT_STATUS_SUCCESS) { LOG_ERROR("Bluedroid stack initialize fail, ret:%d", ret); return ESP_FAIL; }{...} /* * BTC Init *//* ... */ ret = btc_init(); if (ret != BT_STATUS_SUCCESS) { LOG_ERROR("Bluedroid Initialize Fail"); return ESP_FAIL; }{...} future_p = btc_main_get_future_p(BTC_MAIN_INIT_FUTURE); *future_p = future_new(); if (*future_p == NULL) { LOG_ERROR("Bluedroid Initialize Fail!"); return ESP_ERR_NO_MEM; }{...} msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_MAIN_INIT; msg.act = BTC_MAIN_ACT_INIT; if (btc_transfer_context(&msg, NULL, 0, NULL, NULL) != BT_STATUS_SUCCESS) { LOG_ERROR("Bluedroid Initialize Fail"); return ESP_FAIL; }{...} if (future_await(*future_p) == FUTURE_FAIL) { LOG_ERROR("Bluedroid Initialize Fail"); return ESP_FAIL; }{...} bd_already_init = true; #if (BT_HCI_LOG_INCLUDED == TRUE) bt_hci_log_init(); #endif // (BT_HCI_LOG_INCLUDED == TRUE) return ESP_OK; }{ ... } esp_err_t esp_bluedroid_deinit(void) { btc_msg_t msg; future_t **future_p; if (!bd_already_init) { LOG_ERROR("Bluedroid already de-initialised\n"); return ESP_ERR_INVALID_STATE; }{...} if (bd_already_enable) { LOG_ERROR("Bludroid already enabled, do disable first\n"); return ESP_ERR_INVALID_STATE; }{...} future_p = btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE); *future_p = future_new(); if (*future_p == NULL) { LOG_ERROR("Bluedroid de-initialise failed\n"); return ESP_ERR_NO_MEM; }{...} msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_MAIN_INIT; msg.act = BTC_MAIN_ACT_DEINIT; if (btc_transfer_context(&msg, NULL, 0, NULL, NULL) != BT_STATUS_SUCCESS) { LOG_ERROR("Bluedroid de-initialise failed\n"); return ESP_FAIL; }{...} if (future_await(*future_p) == FUTURE_FAIL) { LOG_ERROR("Bluedroid de-initialise failed\n"); return ESP_FAIL; }{...} btc_deinit(); bluedriod_config_deinit(); #if (BT_HCI_LOG_INCLUDED == TRUE) bt_hci_log_deinit(); #endif // (BT_HCI_LOG_INCLUDED == TRUE) bd_already_init = false; return ESP_OK; }{ ... } #if defined(CONFIG_EXAMPLE_CI_ID) && defined(CONFIG_EXAMPLE_CI_PIPELINE_ID) char *esp_bluedroid_get_example_name(void) { static char example_name[ESP_BLE_ADV_NAME_LEN_MAX]; memset(example_name, 0, sizeof(example_name)); sprintf(example_name, "BE%02X_%05X_%02X", CONFIG_EXAMPLE_CI_ID & 0xFF, CONFIG_EXAMPLE_CI_PIPELINE_ID & 0xFFFFF, CONFIG_IDF_FIRMWARE_CHIP_ID & 0xFF); return example_name; }{...} /* ... */#endif
Details