Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

83 linhas
2.5KB

  1. /**
  2. * Copyright (c) 2011-2019 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 SdCard_h
  26. #define SdCard_h
  27. #include "SdioCard.h"
  28. #include "SdSpiCard.h"
  29. #if HAS_SDIO_CLASS
  30. typedef SdCardInterface SdCard;
  31. #else // HAS_SDIO_CLASS
  32. typedef SdSpiCard SdCard;
  33. #endif // HAS_SDIO_CLASS
  34. /** Determine card configuration type.
  35. *
  36. * \param[in] cfg Card configuration.
  37. * \return true if SPI.
  38. */
  39. inline bool isSpi(SdSpiConfig cfg) {(void)cfg; return true;}
  40. /** Determine card configuration type.
  41. *
  42. * \param[in] cfg Card configuration.
  43. * \return true if SPI.
  44. */
  45. inline bool isSpi(SdioConfig cfg) {(void)cfg; return false;}
  46. /**
  47. * \class SdCardFactory
  48. * \brief Setup a SPI card or SDIO card.
  49. */
  50. class SdCardFactory {
  51. public:
  52. /** Initialize SPI card.
  53. *
  54. * \param[in] config SPI configuration.
  55. * \return generic card pointer.
  56. */
  57. SdCard* newCard(SdSpiConfig config) {
  58. m_spiCard.begin(config);
  59. return &m_spiCard;
  60. }
  61. /** Initialize SDIO card.
  62. *
  63. * \param[in] config SDIO configuration.
  64. * \return generic card pointer or nullptr if SDIO is not supported.
  65. */
  66. SdCard* newCard(SdioConfig config) {
  67. #if HAS_SDIO_CLASS
  68. m_sdioCard.begin(config);
  69. return &m_sdioCard;
  70. #else // HAS_SDIO_CLASS
  71. (void)config;
  72. return nullptr;
  73. #endif // HAS_SDIO_CLASS
  74. }
  75. private:
  76. #if HAS_SDIO_CLASS
  77. SdioCard m_sdioCard;
  78. #endif // HAS_SDIO_CLASS
  79. SdSpiCard m_spiCard;
  80. };
  81. #endif // SdCard_h