PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

160 lines
5.7KB

  1. #ifndef __INC_FASTSPI_H
  2. #define __INC_FASTSPI_H
  3. #include "FastLED.h"
  4. #include "controller.h"
  5. #include "lib8tion.h"
  6. #include "fastspi_bitbang.h"
  7. FASTLED_NAMESPACE_BEGIN
  8. #if defined(FASTLED_TEENSY3) && (F_CPU > 48000000)
  9. #define DATA_RATE_MHZ(X) (((48000000L / 1000000L) / X))
  10. #define DATA_RATE_KHZ(X) (((48000000L / 1000L) / X))
  11. #elif defined(FASTLED_TEENSY4) // && (ARM_HARDWARE_SPI)
  12. // just use clocks
  13. #define DATA_RATE_MHZ(X) (1000000 * (X))
  14. #define DATA_RATE_KHZ(X) (1000 * (X))
  15. #else
  16. #define DATA_RATE_MHZ(X) ((F_CPU / 1000000L) / X)
  17. #define DATA_RATE_KHZ(X) ((F_CPU / 1000L) / X)
  18. #endif
  19. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  20. //
  21. // External SPI template definition with partial instantiation(s) to map to hardware SPI ports on platforms/builds where the pin
  22. // mappings are known at compile time.
  23. //
  24. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  25. #if !defined(FASTLED_ALL_PINS_HARDWARE_SPI)
  26. template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
  27. class SPIOutput : public AVRSoftwareSPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {};
  28. #endif
  29. template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
  30. class SoftwareSPIOutput : public AVRSoftwareSPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {};
  31. #ifndef FASTLED_FORCE_SOFTWARE_SPI
  32. #if defined(NRF51) && defined(FASTLED_ALL_PINS_HARDWARE_SPI)
  33. template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
  34. class SPIOutput : public NRF51SPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {};
  35. #endif
  36. #if defined(NRF52_SERIES) && defined(FASTLED_ALL_PINS_HARDWARE_SPI)
  37. template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
  38. class SPIOutput : public NRF52SPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {};
  39. #endif
  40. #if defined(FASTLED_APOLLO3) && defined(FASTLED_ALL_PINS_HARDWARE_SPI)
  41. template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
  42. class SPIOutput : public APOLLO3HardwareSPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {};
  43. #endif
  44. #if defined(SPI_DATA) && defined(SPI_CLOCK)
  45. #if defined(FASTLED_TEENSY3) && defined(ARM_HARDWARE_SPI)
  46. template<uint32_t SPI_SPEED>
  47. class SPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> : public ARMHardwareSPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED, 0x4002C000> {};
  48. #if defined(SPI2_DATA)
  49. template<uint32_t SPI_SPEED>
  50. class SPIOutput<SPI2_DATA, SPI2_CLOCK, SPI_SPEED> : public ARMHardwareSPIOutput<SPI2_DATA, SPI2_CLOCK, SPI_SPEED, 0x4002C000> {};
  51. template<uint32_t SPI_SPEED>
  52. class SPIOutput<SPI_DATA, SPI2_CLOCK, SPI_SPEED> : public ARMHardwareSPIOutput<SPI_DATA, SPI2_CLOCK, SPI_SPEED, 0x4002C000> {};
  53. template<uint32_t SPI_SPEED>
  54. class SPIOutput<SPI2_DATA, SPI_CLOCK, SPI_SPEED> : public ARMHardwareSPIOutput<SPI2_DATA, SPI_CLOCK, SPI_SPEED, 0x4002C000> {};
  55. #endif
  56. #elif defined(FASTLED_TEENSY4) && defined(ARM_HARDWARE_SPI)
  57. template<uint32_t SPI_SPEED>
  58. class SPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> : public Teesy4HardwareSPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED, SPI, 0> {};
  59. template<uint32_t SPI_SPEED>
  60. class SPIOutput<SPI1_DATA, SPI_CLOCK, SPI_SPEED> : public Teesy4HardwareSPIOutput<SPI1_DATA, SPI1_CLOCK, SPI_SPEED, SPI1, 1> {};
  61. template<uint32_t SPI_SPEED>
  62. class SPIOutput<SPI2_DATA, SPI2_CLOCK, SPI_SPEED> : public Teesy4HardwareSPIOutput<SPI2_DATA, SPI2_CLOCK, SPI_SPEED, SPI2, 2> {};
  63. #elif defined(FASTLED_TEENSYLC) && defined(ARM_HARDWARE_SPI)
  64. #define DECLARE_SPI0(__DATA,__CLOCK) template<uint32_t SPI_SPEED>\
  65. class SPIOutput<__DATA, __CLOCK, SPI_SPEED> : public ARMHardwareSPIOutput<__DATA, __CLOCK, SPI_SPEED, 0x40076000> {};
  66. #define DECLARE_SPI1(__DATA,__CLOCK) template<uint32_t SPI_SPEED>\
  67. class SPIOutput<__DATA, __CLOCK, SPI_SPEED> : public ARMHardwareSPIOutput<__DATA, __CLOCK, SPI_SPEED, 0x40077000> {};
  68. DECLARE_SPI0(7,13);
  69. DECLARE_SPI0(8,13);
  70. DECLARE_SPI0(11,13);
  71. DECLARE_SPI0(12,13);
  72. DECLARE_SPI0(7,14);
  73. DECLARE_SPI0(8,14);
  74. DECLARE_SPI0(11,14);
  75. DECLARE_SPI0(12,14);
  76. DECLARE_SPI1(0,20);
  77. DECLARE_SPI1(1,20);
  78. DECLARE_SPI1(21,20);
  79. #elif defined(__SAM3X8E__)
  80. template<uint32_t SPI_SPEED>
  81. class SPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> : public SAMHardwareSPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> {};
  82. #elif defined(AVR_HARDWARE_SPI)
  83. template<uint32_t SPI_SPEED>
  84. class SPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> : public AVRHardwareSPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> {};
  85. #if defined(SPI_UART0_DATA)
  86. template<uint32_t SPI_SPEED>
  87. class SPIOutput<SPI_UART0_DATA, SPI_UART0_CLOCK, SPI_SPEED> : public AVRUSART0SPIOutput<SPI_UART0_DATA, SPI_UART0_CLOCK, SPI_SPEED> {};
  88. #endif
  89. #if defined(SPI_UART1_DATA)
  90. template<uint32_t SPI_SPEED>
  91. class SPIOutput<SPI_UART1_DATA, SPI_UART1_CLOCK, SPI_SPEED> : public AVRUSART1SPIOutput<SPI_UART1_DATA, SPI_UART1_CLOCK, SPI_SPEED> {};
  92. #endif
  93. #endif
  94. #else
  95. # if !defined(FASTLED_INTERNAL) && !defined(FASTLED_ALL_PINS_HARDWARE_SPI)
  96. # ifdef FASTLED_HAS_PRAGMA_MESSAGE
  97. # pragma message "No hardware SPI pins defined. All SPI access will default to bitbanged output"
  98. # else
  99. # warning "No hardware SPI pins defined. All SPI access will default to bitbanged output"
  100. # endif
  101. # endif
  102. #endif
  103. // #if defined(USART_DATA) && defined(USART_CLOCK)
  104. // template<uint32_t SPI_SPEED>
  105. // class AVRSPIOutput<USART_DATA, USART_CLOCK, SPI_SPEED> : public AVRUSARTSPIOutput<USART_DATA, USART_CLOCK, SPI_SPEED> {};
  106. // #endif
  107. #else
  108. # if !defined(FASTLED_INTERNAL) && !defined(FASTLED_ALL_PINS_HARDWARE_SPI)
  109. # ifdef FASTLED_HAS_PRAGMA_MESSAGE
  110. # pragma message "Forcing software SPI - no hardware SPI for you!"
  111. # else
  112. # warning "Forcing software SPI - no hardware SPI for you!"
  113. # endif
  114. # endif
  115. #endif
  116. FASTLED_NAMESPACE_END
  117. #endif