mirror of
https://github.com/CTCaer/hekate.git
synced 2024-11-22 18:06:40 +00:00
bdk: sd: better removal detection handling
This commit is contained in:
parent
2f7e841b50
commit
7f32c6d211
1 changed files with 16 additions and 7 deletions
|
@ -26,7 +26,8 @@ static bool sd_mounted = false;
|
|||
static bool sd_init_done = false;
|
||||
static bool insertion_event = false;
|
||||
static u16 sd_errors[3] = { 0 }; // Init and Read/Write errors.
|
||||
static u32 sd_mode = SD_UHS_SDR104;
|
||||
static u32 sd_mode = SD_DEFAULT_SPEED;
|
||||
|
||||
|
||||
sdmmc_t sd_sdmmc;
|
||||
sdmmc_storage_t sd_storage;
|
||||
|
@ -93,21 +94,26 @@ int sd_init_retry(bool power_cycle)
|
|||
{
|
||||
case SD_INIT_FAIL: // Reset to max.
|
||||
return 0;
|
||||
|
||||
case SD_1BIT_HS25:
|
||||
bus_width = SDMMC_BUS_WIDTH_1;
|
||||
type = SDHCI_TIMING_SD_HS25;
|
||||
break;
|
||||
|
||||
case SD_4BIT_HS25:
|
||||
type = SDHCI_TIMING_SD_HS25;
|
||||
break;
|
||||
|
||||
case SD_UHS_SDR82:
|
||||
type = SDHCI_TIMING_UHS_SDR82;
|
||||
break;
|
||||
|
||||
case SD_UHS_SDR104:
|
||||
type = SDHCI_TIMING_UHS_SDR104;
|
||||
break;
|
||||
default:
|
||||
sd_mode = SD_UHS_SDR104;
|
||||
sd_mode = SD_DEFAULT_SPEED;
|
||||
break;
|
||||
}
|
||||
|
||||
int res = sdmmc_storage_init_sd(&sd_storage, &sd_sdmmc, bus_width, type);
|
||||
|
@ -135,7 +141,7 @@ bool sd_initialize(bool power_cycle)
|
|||
return true;
|
||||
else if (!sdmmc_get_sd_inserted()) // SD Card is not inserted.
|
||||
{
|
||||
sd_mode = SD_UHS_SDR104;
|
||||
sd_mode = SD_DEFAULT_SPEED;
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
@ -194,8 +200,12 @@ bool sd_mount()
|
|||
|
||||
static void _sd_deinit(bool deinit)
|
||||
{
|
||||
if (deinit && sd_mode == SD_INIT_FAIL)
|
||||
sd_mode = SD_UHS_SDR104;
|
||||
if (deinit)
|
||||
{
|
||||
insertion_event = false;
|
||||
if (sd_mode == SD_INIT_FAIL)
|
||||
sd_mode = SD_DEFAULT_SPEED;
|
||||
}
|
||||
|
||||
if (sd_init_done)
|
||||
{
|
||||
|
@ -205,8 +215,7 @@ static void _sd_deinit(bool deinit)
|
|||
if (deinit)
|
||||
{
|
||||
sdmmc_storage_end(&sd_storage);
|
||||
sd_init_done = false;
|
||||
insertion_event = false;
|
||||
sd_init_done = false;
|
||||
}
|
||||
}
|
||||
sd_mounted = false;
|
||||
|
|
Loading…
Reference in a new issue