SdSpiBaseClass.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /**
  26. * \file
  27. * \brief Base class for external SPI driver.
  28. */
  29. #ifndef SdSpiBaseClass_h
  30. #define SdSpiBaseClass_h
  31. /**
  32. * \class SdSpiBaseClass
  33. * \brief Base class for external SPI drivers
  34. */
  35. class SdSpiBaseClass {
  36. public:
  37. /** Activate SPI hardware. */
  38. virtual void activate() {}
  39. /** Initialize the SPI bus.
  40. *
  41. * \param[in] config SPI configuration.
  42. */
  43. virtual void begin(SdSpiConfig config) = 0;
  44. /** Deactivate SPI hardware. */
  45. virtual void deactivate() {}
  46. /** deactivate SPI driver. */
  47. virtual void end() {}
  48. /** Receive a byte.
  49. *
  50. * \return The byte.
  51. */
  52. virtual uint8_t receive() = 0;
  53. /** Receive multiple bytes.
  54. *
  55. * \param[out] buf Buffer to receive the data.
  56. * \param[in] count Number of bytes to receive.
  57. *
  58. * \return Zero for no error or nonzero error code.
  59. */
  60. virtual uint8_t receive(uint8_t* buf, size_t count) = 0;
  61. /** Send a byte.
  62. *
  63. * \param[in] data Byte to send
  64. */
  65. virtual void send(uint8_t data) = 0;
  66. /** Send multiple bytes.
  67. *
  68. * \param[in] buf Buffer for data to be sent.
  69. * \param[in] count Number of bytes to send.
  70. */
  71. virtual void send(const uint8_t* buf, size_t count) = 0;
  72. /** Save high speed SPISettings after SD initialization.
  73. *
  74. * \param[in] maxSck Maximum SCK frequency.
  75. */
  76. virtual void setSckSpeed(uint32_t maxSck) {(void)maxSck;}
  77. };
  78. #endif // SdSpiBaseClass_h