Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions custom/integration/wifi/hosted_safe.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions custom/integration/wifi/hosted_safe.h

This file was deleted.

108 changes: 108 additions & 0 deletions custom/integration/wifi_remote/hosted_safe.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
#include "integration/wifi_remote/hosted_safe.h"

#include "driver/gpio.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sdkconfig.h"

#if CONFIG_M5TAB5_USE_ESP_HOSTED
# include "esp_hosted_api.h"
# include "esp_wifi.h"
# include "esp_wifi_remote.h"
#endif

static const char* TAG = "hosted_safe";
static bool s_hosted_ready = false;

#if CONFIG_M5TAB5_USE_ESP_HOSTED
static void slave_pulse_reset(void)
{
const gpio_num_t rst = 54;
const gpio_config_t io = {
.pin_bit_mask = 1ULL << rst,
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = 0,
.pull_down_en = 0,
.intr_type = GPIO_INTR_DISABLE,
};
gpio_config(&io);
gpio_set_level(rst, 0);
vTaskDelay(pdMS_TO_TICKS(5));
gpio_set_level(rst, 1);
}
#endif

bool hosted_try_init_with_retries(void)
{
#if !CONFIG_M5TAB5_USE_ESP_HOSTED
ESP_LOGI(TAG, "ESP-Hosted disabled via Kconfig.");
return false;
#else
if (s_hosted_ready)
{
return true;
}

int retries = CONFIG_M5TAB5_HOSTED_BOOT_RETRIES;
while (retries-- >= 0)
{
ESP_LOGI(
TAG, "Resetting SDIO slave and waiting %d ms ...", CONFIG_M5TAB5_HOSTED_BOOT_DELAY_MS);
slave_pulse_reset();
vTaskDelay(pdMS_TO_TICKS(CONFIG_M5TAB5_HOSTED_BOOT_DELAY_MS));

esp_err_t err = esp_hosted_init();
if (err != ESP_OK)
{
ESP_LOGW(TAG, "esp_hosted_init failed (%s)", esp_err_to_name(err));
}
else
{
ESP_LOGI(TAG, "ESP-Hosted initialized.");
s_hosted_ready = true;

wifi_init_config_t wifi_cfg = WIFI_INIT_CONFIG_DEFAULT();
err = esp_wifi_remote_init(&wifi_cfg);
if (err != ESP_OK)
{
ESP_LOGW(TAG,
"esp_wifi_remote_init failed (%s), continuing without Wi-Fi.",
esp_err_to_name(err));
hosted_deinit_safe();
s_hosted_ready = false;
}
}

if (s_hosted_ready)
{
return true;
}

ESP_LOGW(TAG, "ESP-Hosted init failed; %d retry(ies) left.", retries);
vTaskDelay(pdMS_TO_TICKS(250));
}

ESP_LOGW(TAG, "ESP-Hosted not available; booting without Wi-Fi.");
return false;
#endif
}

void hosted_deinit_safe(void)
{
#if CONFIG_M5TAB5_USE_ESP_HOSTED
if (!s_hosted_ready)
{
return;
}

esp_wifi_remote_deinit();
esp_hosted_deinit();
s_hosted_ready = false;
#endif
}
21 changes: 21 additions & 0 deletions custom/integration/wifi_remote/hosted_safe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
#pragma once

#include <stdbool.h>

#include "esp_err.h"

#ifdef __cplusplus
extern "C" {
#endif

bool hosted_try_init_with_retries(void);
void hosted_deinit_safe(void);

#ifdef __cplusplus
}
#endif
20 changes: 20 additions & 0 deletions platforms/tab5/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
menu "M5Tab5 Connectivity"

config M5TAB5_USE_ESP_HOSTED
bool "Enable ESP-Hosted (Wi-Fi over SDIO)"
default n
help
When enabled, the app will initialize the ESP-Hosted SDIO slave (ESP32-Cx).
When disabled, boot never touches SDIO/Hosted and Wi-Fi is unavailable.

config M5TAB5_HOSTED_BOOT_RETRIES
int "Hosted init retries at boot"
range 0 10
default 3

config M5TAB5_HOSTED_BOOT_DELAY_MS
int "Delay after slave reset before SDIO init (ms)"
range 0 5000
default 500

endmenu
Loading
Loading