forked from m5stack/M5Tab5-UserDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhosted_safe.cpp
More file actions
71 lines (60 loc) · 2.08 KB
/
hosted_safe.cpp
File metadata and controls
71 lines (60 loc) · 2.08 KB
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
/*
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
#include "integration/wifi/hosted_safe.h"
#include <driver/sdmmc_host.h>
#include <esp_err.h>
#include <esp_log.h>
#include <esp_wifi.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "esp_hosted.h"
namespace custom::integration::wifi
{
namespace
{
constexpr const char* kTag = "hosted-safe";
constexpr TickType_t kSlaveBootGuardDelay = pdMS_TO_TICKS(150);
void cleanup_transport()
{
const esp_err_t deinit_err = esp_hosted_deinit();
if (deinit_err != ESP_OK && deinit_err != ESP_ERR_INVALID_STATE)
{
ESP_LOGW(kTag, "esp_hosted_deinit reported: %s", esp_err_to_name(deinit_err));
}
const esp_err_t sdmmc_err = sdmmc_host_deinit();
if (sdmmc_err != ESP_OK && sdmmc_err != ESP_ERR_INVALID_STATE)
{
ESP_LOGW(kTag, "sdmmc_host_deinit reported: %s", esp_err_to_name(sdmmc_err));
}
}
} // namespace
bool HostedSafeStart()
{
vTaskDelay(kSlaveBootGuardDelay);
esp_err_t err = esp_hosted_init();
if (err != ESP_OK)
{
ESP_LOGE(kTag, "esp_hosted_init failed: %s", esp_err_to_name(err));
cleanup_transport();
return false;
}
wifi_init_config_t wifi_cfg = WIFI_INIT_CONFIG_DEFAULT();
err = esp_wifi_remote_init(&wifi_cfg);
if (err != ESP_OK)
{
ESP_LOGE(kTag, "esp_wifi_remote_init failed: %s", esp_err_to_name(err));
const esp_err_t remote_err = esp_wifi_remote_deinit();
if (remote_err != ESP_OK && remote_err != ESP_ERR_INVALID_STATE)
{
ESP_LOGW(kTag, "esp_wifi_remote_deinit reported: %s", esp_err_to_name(remote_err));
}
cleanup_transport();
return false;
}
ESP_LOGI(kTag, "Hosted link established");
return true;
}
} // namespace custom::integration::wifi