SdCardInterface.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * Copyright (c) 2011-2022 Bill Greiman
  3. * This file is part of the SdFat library for SD memory cards.
  4. *
  5. * MIT License
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef SdCardInterface_h
  26. #define SdCardInterface_h
  27. #include "../common/FsBlockDeviceInterface.h"
  28. #include "SdCardInfo.h"
  29. /**
  30. * \class SdCardInterface
  31. * \brief Abstract interface for an SD card.
  32. */
  33. class SdCardInterface : public FsBlockDeviceInterface {
  34. public:
  35. /** CMD6 Switch mode: Check Function Set Function.
  36. * \param[in] arg CMD6 argument.
  37. * \param[out] status return status data.
  38. *
  39. * \return true for success or false for failure.
  40. */
  41. virtual bool cardCMD6(uint32_t arg, uint8_t* status) = 0;
  42. /** end use of card */
  43. virtual void end() = 0;
  44. /** Erase a range of sectors.
  45. *
  46. * \param[in] firstSector The address of the first sector in the range.
  47. * \param[in] lastSector The address of the last sector in the range.
  48. *
  49. * \return true for success or false for failure.
  50. */
  51. virtual bool erase(uint32_t firstSector, uint32_t lastSector) = 0;
  52. /** \return error code. */
  53. virtual uint8_t errorCode() const = 0;
  54. /** \return error data. */
  55. virtual uint32_t errorData() const = 0;
  56. /** \return true if card is busy. */
  57. virtual bool isBusy() = 0;
  58. /** \return false by default */
  59. virtual bool hasDedicatedSpi() {return false;}
  60. /** \return false by default */
  61. bool virtual isDedicatedSpi() {return false;}
  62. /** Set SPI sharing state
  63. * \param[in] value desired state.
  64. * \return false by default.
  65. */
  66. virtual bool setDedicatedSpi(bool value) {
  67. (void)value;
  68. return false;
  69. }
  70. /**
  71. * Read a card's CID register.
  72. *
  73. * \param[out] cid pointer to area for returned data.
  74. *
  75. * \return true for success or false for failure.
  76. */
  77. virtual bool readCID(cid_t* cid) = 0;
  78. /**
  79. * Read a card's CSD register.
  80. *
  81. * \param[out] csd pointer to area for returned data.
  82. *
  83. * \return true for success or false for failure.
  84. */
  85. virtual bool readCSD(csd_t* csd) = 0;
  86. /** Read OCR register.
  87. *
  88. * \param[out] ocr Value of OCR register.
  89. * \return true for success or false for failure.
  90. */
  91. virtual bool readOCR(uint32_t* ocr) = 0;
  92. /** Read SCR register.
  93. *
  94. * \param[out] scr Value of SCR register.
  95. * \return true for success or false for failure.
  96. */
  97. virtual bool readSCR(scr_t *scr) = 0;
  98. /**
  99. * Determine the size of an SD flash memory card.
  100. *
  101. * \return The number of 512 byte data sectors in the card
  102. * or zero if an error occurs.
  103. */
  104. virtual uint32_t sectorCount() = 0;
  105. /** \return card status. */
  106. virtual uint32_t status() {return 0XFFFFFFFF;}
  107. /** Return the card type: SD V1, SD V2 or SDHC/SDXC
  108. * \return 0 - SD V1, 1 - SD V2, or 3 - SDHC/SDXC.
  109. */
  110. virtual uint8_t type() const = 0;
  111. /** Write one data sector in a multiple sector write sequence.
  112. * \param[in] src Pointer to the location of the data to be written.
  113. * \return true for success or false for failure.
  114. */
  115. virtual bool writeData(const uint8_t* src) = 0;
  116. /** Start a write multiple sectors sequence.
  117. *
  118. * \param[in] sector Address of first sector in sequence.
  119. *
  120. * \return true for success or false for failure.
  121. */
  122. virtual bool writeStart(uint32_t sector) = 0;
  123. /** End a write multiple sectors sequence.
  124. * \return true for success or false for failure.
  125. */
  126. virtual bool writeStop() = 0;
  127. };
  128. #endif // SdCardInterface_h