From 5dd5c481ad297dadfe53fdfbdf844414af5dc02d Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 6 Jun 2020 15:09:12 +0200 Subject: [PATCH] sdcard code sanitizations --- include/sdcard.h | 2 ++ src/sdcard.cpp | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/sdcard.h b/include/sdcard.h index e369deb3..7102c460 100644 --- a/include/sdcard.h +++ b/include/sdcard.h @@ -15,7 +15,9 @@ #endif #endif +#ifdef HAS_SDS011 #include "sds011read.h" +#endif #ifndef SDCARD_CS #define SDCARD_CS SS diff --git a/src/sdcard.cpp b/src/sdcard.cpp index 37458cb4..5047ee2e 100644 --- a/src/sdcard.cpp +++ b/src/sdcard.cpp @@ -1,12 +1,12 @@ // routines for writing data to an SD-card, if present -#if (HAS_SDCARD) - // Local logging tag static const char TAG[] = __FILE__; #include "sdcard.h" +#ifdef HAS_SDCARD + static bool useSDCard; File fileSDCard; @@ -14,10 +14,13 @@ File fileSDCard; bool sdcard_init() { ESP_LOGI(TAG, "looking for SD-card..."); -#if HAS_SDCARD == 1 - pinMode(SDCARD_CS, OUTPUT); + // for usage of SD drivers on ESP32 platform see + // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdspi_host.html + // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdmmc_host.html + +#if HAS_SDCARD == 1 // use SD SPI host driver useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK); -#elif HAS_SDCARD == 2 +#elif HAS_SDCARD == 2 // use SD MMC host driver useSDCard = SD_MMC.begin(); #endif