選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

61 行
2.0KB

  1. /* Arduino SdSpi Library
  2. * Copyright (C) 2013 by William Greiman
  3. *
  4. * This file is part of the Arduino SdSpi Library
  5. *
  6. * This Library is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This Library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with the Arduino SdSpi Library. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. */
  20. #include <SdSpi.h>
  21. #if USE_SOFTWARE_SPI
  22. #include <SoftSPI.h>
  23. static
  24. SoftSPI<SOFT_SPI_MISO_PIN, SOFT_SPI_MOSI_PIN, SOFT_SPI_SCK_PIN, 0> softSpiBus;
  25. //------------------------------------------------------------------------------
  26. /**
  27. * initialize SPI pins
  28. */
  29. void SdSpi::begin() {
  30. softSpiBus.begin();
  31. }
  32. //------------------------------------------------------------------------------
  33. /**
  34. * Initialize hardware SPI - dummy for soft SPI
  35. */
  36. void SdSpi::init(uint8_t sckDivisor) {}
  37. //------------------------------------------------------------------------------
  38. /** Soft SPI receive byte */
  39. uint8_t SdSpi::receive() {
  40. return softSpiBus.receive();
  41. }
  42. //------------------------------------------------------------------------------
  43. /** Soft SPI read data */
  44. uint8_t SdSpi::receive(uint8_t* buf, size_t n) {
  45. for (size_t i = 0; i < n; i++) {
  46. buf[i] = receive();
  47. }
  48. return 0;
  49. }
  50. //------------------------------------------------------------------------------
  51. /** Soft SPI send byte */
  52. void SdSpi::send(uint8_t data) {
  53. softSpiBus.send(data);
  54. }
  55. //------------------------------------------------------------------------------
  56. void SdSpi::send(const uint8_t* buf , size_t n) {
  57. for (size_t i = 0; i < n; i++) {
  58. send(buf[i]);
  59. }
  60. }
  61. #endif // USE_SOFTWARE_SPI