|
|
|
|
|
|
|
|
/** High Capacity SD card */
|
|
|
/** High Capacity SD card */
|
|
|
uint8_t const SD_CARD_TYPE_SDHC = 3;
|
|
|
uint8_t const SD_CARD_TYPE_SDHC = 3;
|
|
|
//------------------------------------------------------------------------------
|
|
|
//------------------------------------------------------------------------------
|
|
|
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
uint8_t KinetisSDHC_InitCard(void);
|
|
|
|
|
|
uint8_t KinetisSDHC_GetCardType(void);
|
|
|
|
|
|
int KinetisSDHC_ReadBlock(void * buff, uint32_t sector);
|
|
|
|
|
|
int KinetisSDHC_WriteBlock(const void * buff, uint32_t sector);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__)
|
|
|
|
|
|
#include "NXP_SDHC.h"
|
|
|
|
|
|
#define BUILTIN_SDCARD 254
|
|
|
#endif
|
|
|
#endif
|
|
|
#define BUILTIN_SDCARD 254
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
//------------------------------------------------------------------------------
|
|
|
/**
|
|
|
/**
|
|
|
* \class Sd2Card
|
|
|
* \class Sd2Card
|
|
|
|
|
|
|
|
|
/* Initialize an SD flash memory card with the selected SPI clock rate
|
|
|
/* Initialize an SD flash memory card with the selected SPI clock rate
|
|
|
* and the SD chip select pin. */
|
|
|
* and the SD chip select pin. */
|
|
|
uint8_t init(uint8_t sckRateID, uint8_t chipSelectPin) {
|
|
|
uint8_t init(uint8_t sckRateID, uint8_t chipSelectPin) {
|
|
|
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
|
|
|
|
|
|
|
|
#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__)
|
|
|
if (chipSelectPin == BUILTIN_SDCARD) {
|
|
|
if (chipSelectPin == BUILTIN_SDCARD) {
|
|
|
chipSelectPin_ = BUILTIN_SDCARD;
|
|
|
chipSelectPin_ = BUILTIN_SDCARD;
|
|
|
uint8_t ret = KinetisSDHC_InitCard();
|
|
|
|
|
|
type_ = KinetisSDHC_GetCardType();
|
|
|
|
|
|
|
|
|
uint8_t ret = SDHC_CardInit();
|
|
|
|
|
|
type_ = SDHC_CardGetType();
|
|
|
return (ret == 0) ? true : false;
|
|
|
return (ret == 0) ? true : false;
|
|
|
}
|
|
|
}
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
uint8_t type(void) const {return type_;}
|
|
|
uint8_t type(void) const {return type_;}
|
|
|
/** Returns the current value, true or false, for partial block read. */
|
|
|
/** Returns the current value, true or false, for partial block read. */
|
|
|
uint8_t readBlock(uint32_t block, uint8_t* dst) {
|
|
|
uint8_t readBlock(uint32_t block, uint8_t* dst) {
|
|
|
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
|
|
|
|
|
|
|
|
#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__)
|
|
|
if (chipSelectPin_ == BUILTIN_SDCARD) {
|
|
|
if (chipSelectPin_ == BUILTIN_SDCARD) {
|
|
|
return (KinetisSDHC_ReadBlock(dst, block) == 0) ? true : false;
|
|
|
|
|
|
|
|
|
return (SDHC_CardReadBlock(dst, block) == 0) ? true : false;
|
|
|
}
|
|
|
}
|
|
|
#endif
|
|
|
#endif
|
|
|
return SD_readBlock(block, dst);
|
|
|
return SD_readBlock(block, dst);
|
|
|
}
|
|
|
}
|
|
|
/** Return the card type: SD V1, SD V2 or SDHC */
|
|
|
/** Return the card type: SD V1, SD V2 or SDHC */
|
|
|
uint8_t writeBlock(uint32_t block, const uint8_t* src) {
|
|
|
uint8_t writeBlock(uint32_t block, const uint8_t* src) {
|
|
|
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
|
|
|
|
|
|
|
|
#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__)
|
|
|
if (chipSelectPin_ == BUILTIN_SDCARD) {
|
|
|
if (chipSelectPin_ == BUILTIN_SDCARD) {
|
|
|
return (KinetisSDHC_WriteBlock(src, block) == 0) ? true : false;
|
|
|
|
|
|
|
|
|
return (SDHC_CardWriteBlock(src, block) == 0) ? true : false;
|
|
|
}
|
|
|
}
|
|
|
#endif
|
|
|
#endif
|
|
|
return SD_writeBlock(block, src);
|
|
|
return SD_writeBlock(block, src);
|