main/task_ble.c

changeset 31
ec5c7794dcd6
equal deleted inserted replaced
30:7448b8dd4288 31:ec5c7794dcd6
1 /**
2 * @file task_ble.c
3 * @brief BLE task. Secure GATT server.
4 */
5
6 #include "config.h"
7
8
9 static const char *TAG = "task_ble";
10
11
12
13 void task_ble( void * pvParameters )
14 {
15 esp_err_t ret;
16
17 ESP_LOGI(TAG, "Starting BLE task");
18
19 /*
20 * Initialize Bluetooth
21 */
22 ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
23
24 esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
25 ret = esp_bt_controller_init(&bt_cfg);
26 if (ret) {
27 ESP_LOGE(TAG, "init controller failed: %s", esp_err_to_name(ret));
28 goto deadend;
29 }
30
31 ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
32 if (ret) {
33 ESP_LOGE(TAG, "enable controller failed: %s", esp_err_to_name(ret));
34 goto deadend;
35 }
36
37 ESP_LOGI(TAG, "init bluetooth");
38 ret = esp_bluedroid_init();
39 if (ret) {
40 ESP_LOGE(TAG, "init bluetooth failed: %s", esp_err_to_name(ret));
41 goto deadend;
42 }
43
44 ret = esp_bluedroid_enable();
45 if (ret) {
46 ESP_LOGE(TAG, "enable bluetooth failed: %s", esp_err_to_name(ret));
47 goto deadend;
48 }
49
50 ret = ble_balkon_gatts_register();
51 if (ret)
52 goto deadend;
53
54 ble_balkon_gap_register();
55
56 ret = ble_balkon_gatts_app_register();
57 if (ret)
58 goto deadend;
59
60 ret = ble_balkon_gatts_set_mtu();
61 if (ret)
62 goto deadend;
63
64 ESP_LOGI(TAG, "Start BLE done, enter loop");
65
66 for(;;) {
67
68
69 vTaskDelay(20 / portTICK_PERIOD_MS);
70 } /* for(;;) */
71
72
73 /*
74 * Error point for init errors.
75 */
76 deadend:
77 ESP_LOGI(TAG, "Startup error loop");
78 for(;;) {
79 vTaskDelay(50 / portTICK_PERIOD_MS);
80 }
81 }
82

mercurial