#ifndef BIWAK_SD_H_
#define BIWAK_SD_H_
//----------------------------------------------------------------------------
///
/// \brief  SD-Card
///
///         See implementation files for further information.
//
/// \date   20220707
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Includes-----------------------------------------------------------------


//---Own------------------------------

#include <biwak/biwak.h>
#include <biwak/gpio.hpp>


//---Forward declarations-----------------------------------------------------


#if defined (MCU_PLATFORM_STM32)
   #define SPI_HANDLE_TYPE    SPI_HandleTypeDef
   #include <HALWrapper/stm32_dma.h>       // SD wants that
   #include <HALWrapper/stm32_sd.h>
#else
   #define SD_HandleTypeDef    void
#endif

#if defined STM32F1
   #define SD_HandleTypeDef    void
#endif

#if defined STM32F3
   #define SD_HandleTypeDef    void
#endif

#if defined STM32L0
   #define SD_HandleTypeDef    void
#endif

#if defined ( STM32L1 )
   #define SD_HandleTypeDef    void
#endif

#if defined STM32G4
   #define SD_HandleTypeDef    void
#endif

#if defined STM32G0
   #define SD_HandleTypeDef    void
#endif


//---Defines------------------------------------------------------------------



//---Declaration--------------------------------------------------------------


struct SSdConfig;

class CSd
{

   private:
      const SSdConfig &configData;
      SD_HandleTypeDef *m_pHandler;

      CGpio    m_gpioCk;
      CGpio    m_gpioCmd;
      CGpio    m_gpioD0;
      CGpio    m_gpioD1;
      CGpio    m_gpioD2;
      CGpio    m_gpioD3;

      int m_initSta;

      //ESpi eSpi;
   //public:
      //CGpio gpioSck, gpioMosi, gpioMiso;

   public:

      CSd(const SSdConfig &configData);
      ~CSd();

      int init();
      void initClock();
      void info();
      int read(void *data, int addr, size_t blocks) const;
      int write(const void *data, int addr, size_t blocks) const;
      int erase(int addr);
      int errorCode();
};


//---fin----------------------------------------------------------------------
#endif // ? ! BIWAK_SD_H_
