|
|
@@ -1,16 +1,8 @@
|
|
|
-// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
|
|
|
-//
|
|
|
-// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
-// you may not use this file except in compliance with the License.
|
|
|
-// You may obtain a copy of the License at
|
|
|
-//
|
|
|
-// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
-//
|
|
|
-// Unless required by applicable law or agreed to in writing, software
|
|
|
-// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
-// See the License for the specific language governing permissions and
|
|
|
-// limitations under the License.
|
|
|
+/*
|
|
|
+ * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
+ *
|
|
|
+ * SPDX-License-Identifier: Apache-2.0
|
|
|
+ */
|
|
|
|
|
|
#include "diskio_impl.h"
|
|
|
#include "ffconf.h"
|
|
|
@@ -23,14 +15,32 @@ static sdmmc_card_t* s_cards[FF_VOLUMES] = { NULL };
|
|
|
|
|
|
static const char* TAG = "diskio_sdmmc";
|
|
|
|
|
|
-DSTATUS ff_sdmmc_initialize (BYTE pdrv)
|
|
|
+//Check if SD/MMC card is present
|
|
|
+static DSTATUS ff_sdmmc_card_available(BYTE pdrv)
|
|
|
{
|
|
|
+ sdmmc_card_t* card = s_cards[pdrv];
|
|
|
+ assert(card);
|
|
|
+ esp_err_t err = sdmmc_get_status(card);
|
|
|
+ if (unlikely(err != ESP_OK)) {
|
|
|
+ ESP_LOGE(TAG, "Check status failed (0x%x)", err);
|
|
|
+ return STA_NOINIT;
|
|
|
+ }
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+* ff_sdmmc_status() and ff_sdmmc_initialize() return STA_NOINIT when sdmmc_get_status()
|
|
|
+* fails. This error value is checked throughout the FATFS code.
|
|
|
+* Both functions return 0 on success.
|
|
|
+*/
|
|
|
+DSTATUS ff_sdmmc_initialize (BYTE pdrv)
|
|
|
+{
|
|
|
+ return ff_sdmmc_card_available(pdrv);
|
|
|
+}
|
|
|
+
|
|
|
DSTATUS ff_sdmmc_status (BYTE pdrv)
|
|
|
{
|
|
|
- return 0;
|
|
|
+ return ff_sdmmc_card_available(pdrv);
|
|
|
}
|
|
|
|
|
|
DRESULT ff_sdmmc_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count)
|