diff --git a/firmware/drivers/sdmmc_host.c b/firmware/drivers/sdmmc_host.c index 8db8fcfc92..337de92561 100644 --- a/firmware/drivers/sdmmc_host.c +++ b/firmware/drivers/sdmmc_host.c @@ -21,6 +21,7 @@ #include "system.h" #include "storage.h" #include "disk_cache.h" +#include "led.h" #include "debug.h" #include "panic.h" #include "logf.h" @@ -48,6 +49,29 @@ DECLARE_FIRST_DRIVE(int sdmmc_mmc_first_drive); static volatile long sdmmc_mmc_last_activity; #endif +static bool sdmmc_host_any_active(void) +{ +#if CONFIG_STORAGE & STORAGE_SD + for (size_t i = 0; i < ARRAYLEN(sdmmc_sd_hosts); ++i) + if (sdmmc_sd_hosts[i]->led_active) + return true; +#endif + +#if CONFIG_STORAGE & STORAGE_MMC + for (size_t i = 0; i < ARRAYLEN(sdmmc_mmc_hosts); ++i) + if (sdmmc_mmc_hosts[i]->led_active) + return true; +#endif + + return false; +} + +static void sdmmc_host_set_led(struct sdmmc_host *host, bool on) +{ + host->led_active = on; + led(sdmmc_host_any_active()); +} + static int sdmmc_host_get_logical_drive(struct sdmmc_host *host) { switch (host->config.type) @@ -734,6 +758,7 @@ static int sdmmc_host_transfer(struct sdmmc_host *host, int rc = -1; mutex_lock(&host->lock); + sdmmc_host_set_led(host, true); if (!host->enabled) goto out; @@ -843,6 +868,7 @@ static int sdmmc_host_transfer(struct sdmmc_host *host, } out: + sdmmc_host_set_led(host, false); mutex_unlock(&host->lock); return rc; } diff --git a/firmware/export/sdmmc_host.h b/firmware/export/sdmmc_host.h index 5258460196..d4a431bbdb 100644 --- a/firmware/export/sdmmc_host.h +++ b/firmware/export/sdmmc_host.h @@ -242,6 +242,7 @@ struct sdmmc_host bool initialized : 1; bool is_hcs_card : 1; bool use_cmd23 : 1; + bool led_active : 1; /* LED active may be read without lock */ /* Controller implemented by the target */ const struct sdmmc_controller_ops *ops;