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