FastLED 3.9.7
Loading...
Searching...
No Matches
fastspi.h
Go to the documentation of this file.
1
3
4#ifndef __INC_FASTSPI_H
5#define __INC_FASTSPI_H
6
7#include "FastLED.h"
8
9#include "controller.h"
10#include "lib8tion.h"
11
12#include "fastspi_bitbang.h"
13
14
15
16#if defined(FASTLED_TEENSY3) && (F_CPU > 48000000)
17#define DATA_RATE_MHZ(X) (((48000000L / 1000000L) / X))
18#define DATA_RATE_KHZ(X) (((48000000L / 1000L) / X))
19#elif defined(FASTLED_TEENSY4) || (defined(ESP32) && defined(FASTLED_ALL_PINS_HARDWARE_SPI)) || (defined(ESP8266) && defined(FASTLED_ALL_PINS_HARDWARE_SPI) || defined(FASTLED_STUB_IMPL))
20// just use clocks
21#define DATA_RATE_MHZ(X) (1000000 * (X))
22#define DATA_RATE_KHZ(X) (1000 * (X))
23#else
25#define DATA_RATE_MHZ(X) ((F_CPU / 1000000L) / X)
27#define DATA_RATE_KHZ(X) ((F_CPU / 1000L) / X)
28#endif
29
31//
32// External SPI template definition with partial instantiation(s) to map to hardware SPI ports on platforms/builds where the pin
33// mappings are known at compile time.
34//
36
38
39#if defined(FASTLED_STUB_IMPL)
40
41
42template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
43class SPIOutput : public StubSPIOutput {};
44
45
46#else
47
48#if !defined(FASTLED_ALL_PINS_HARDWARE_SPI)
50template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
51class SPIOutput : public AVRSoftwareSPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {};
52#endif
53
55template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
56class SoftwareSPIOutput : public AVRSoftwareSPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {};
57
58#ifndef FASTLED_FORCE_SOFTWARE_SPI
59
60#if defined(NRF51) && defined(FASTLED_ALL_PINS_HARDWARE_SPI)
61template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
62class SPIOutput : public NRF51SPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {};
63#endif
64
65#if defined(NRF52_SERIES) && defined(FASTLED_ALL_PINS_HARDWARE_SPI)
66template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
67class SPIOutput : public NRF52SPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {};
68#endif
69
70#if defined(FASTLED_APOLLO3) && defined(FASTLED_ALL_PINS_HARDWARE_SPI)
71template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
72class SPIOutput : public APOLLO3HardwareSPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {};
73#endif
74
75#if defined(ESP32) && defined(FASTLED_ALL_PINS_HARDWARE_SPI)
76template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
77class SPIOutput : public ESP32SPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {};
78#endif
79
80#if defined(ESP8266) && defined(FASTLED_ALL_PINS_HARDWARE_SPI)
81template<uint8_t _DATA_PIN, uint8_t _CLOCK_PIN, uint32_t _SPI_CLOCK_DIVIDER>
82class SPIOutput : public ESP8266SPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {};
83#endif
84
85
86
87
88#if defined(SPI_DATA) && defined(SPI_CLOCK)
89
90#if defined(FASTLED_TEENSY3) && defined(ARM_HARDWARE_SPI)
91
92template<uint32_t SPI_SPEED>
93class SPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> : public ARMHardwareSPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED, 0x4002C000> {};
94
95#if defined(SPI2_DATA)
96
97template<uint32_t SPI_SPEED>
98class SPIOutput<SPI2_DATA, SPI2_CLOCK, SPI_SPEED> : public ARMHardwareSPIOutput<SPI2_DATA, SPI2_CLOCK, SPI_SPEED, 0x4002C000> {};
99
100template<uint32_t SPI_SPEED>
101class SPIOutput<SPI_DATA, SPI2_CLOCK, SPI_SPEED> : public ARMHardwareSPIOutput<SPI_DATA, SPI2_CLOCK, SPI_SPEED, 0x4002C000> {};
102
103template<uint32_t SPI_SPEED>
104class SPIOutput<SPI2_DATA, SPI_CLOCK, SPI_SPEED> : public ARMHardwareSPIOutput<SPI2_DATA, SPI_CLOCK, SPI_SPEED, 0x4002C000> {};
105#endif
106
107#elif defined(FASTLED_TEENSY4) && defined(ARM_HARDWARE_SPI)
108
109template<uint32_t SPI_SPEED>
110class SPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> : public Teensy4HardwareSPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED, SPI, 0> {};
111
112template<uint32_t SPI_SPEED>
113class SPIOutput<SPI1_DATA, SPI1_CLOCK, SPI_SPEED> : public Teensy4HardwareSPIOutput<SPI1_DATA, SPI1_CLOCK, SPI_SPEED, SPI1, 1> {};
114
115template<uint32_t SPI_SPEED>
116class SPIOutput<SPI2_DATA, SPI2_CLOCK, SPI_SPEED> : public Teensy4HardwareSPIOutput<SPI2_DATA, SPI2_CLOCK, SPI_SPEED, SPI2, 2> {};
117
118#elif defined(FASTLED_TEENSYLC) && defined(ARM_HARDWARE_SPI)
119
120#define DECLARE_SPI0(__DATA,__CLOCK) template<uint32_t SPI_SPEED>\
121 class SPIOutput<__DATA, __CLOCK, SPI_SPEED> : public ARMHardwareSPIOutput<__DATA, __CLOCK, SPI_SPEED, 0x40076000> {};
122 #define DECLARE_SPI1(__DATA,__CLOCK) template<uint32_t SPI_SPEED>\
123 class SPIOutput<__DATA, __CLOCK, SPI_SPEED> : public ARMHardwareSPIOutput<__DATA, __CLOCK, SPI_SPEED, 0x40077000> {};
124
125DECLARE_SPI0(7,13);
126DECLARE_SPI0(8,13);
127DECLARE_SPI0(11,13);
128DECLARE_SPI0(12,13);
129DECLARE_SPI0(7,14);
130DECLARE_SPI0(8,14);
131DECLARE_SPI0(11,14);
132DECLARE_SPI0(12,14);
133DECLARE_SPI1(0,20);
134DECLARE_SPI1(1,20);
135DECLARE_SPI1(21,20);
136
137#elif defined(__SAM3X8E__)
138
139template<uint32_t SPI_SPEED>
140class SPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> : public SAMHardwareSPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> {};
141
142#elif defined(AVR_HARDWARE_SPI)
143
144template<uint32_t SPI_SPEED>
145class SPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> : public AVRHardwareSPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> {};
146
147#if defined(SPI_UART0_DATA)
148
149template<uint32_t SPI_SPEED>
150class SPIOutput<SPI_UART0_DATA, SPI_UART0_CLOCK, SPI_SPEED> : public AVRUSART0SPIOutput<SPI_UART0_DATA, SPI_UART0_CLOCK, SPI_SPEED> {};
151
152#endif
153
154#if defined(SPI_UART1_DATA)
155
156template<uint32_t SPI_SPEED>
157class SPIOutput<SPI_UART1_DATA, SPI_UART1_CLOCK, SPI_SPEED> : public AVRUSART1SPIOutput<SPI_UART1_DATA, SPI_UART1_CLOCK, SPI_SPEED> {};
158
159#endif
160
161#elif defined(ARDUNIO_CORE_SPI)
162
163template<uint32_t SPI_SPEED>
164class SPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED> : public ArdunioCoreSPIOutput<SPI_DATA, SPI_CLOCK, SPI_SPEED, SPI> {};
165
166#endif
167
168#else
169# if !defined(FASTLED_INTERNAL) && !defined(FASTLED_ALL_PINS_HARDWARE_SPI) && !defined(ESP32)
170# ifdef FASTLED_HAS_PRAGMA_MESSAGE
171# pragma message "No hardware SPI pins defined. All SPI access will default to bitbanged output"
172# else
173# warning "No hardware SPI pins defined. All SPI access will default to bitbanged output"
174# endif
175# endif
176#endif
177
178// #if defined(USART_DATA) && defined(USART_CLOCK)
179// template<uint32_t SPI_SPEED>
180// class AVRSPIOutput<USART_DATA, USART_CLOCK, SPI_SPEED> : public AVRUSARTSPIOutput<USART_DATA, USART_CLOCK, SPI_SPEED> {};
181// #endif
182
183#else
184# if !defined(FASTLED_INTERNAL) && !defined(FASTLED_ALL_PINS_HARDWARE_SPI)
185# ifdef FASTLED_HAS_PRAGMA_MESSAGE
186# pragma message "Forcing software SPI - no hardware SPI for you!"
187# else
188# warning "Forcing software SPI - no hardware SPI for you!"
189# endif
190# endif
191#endif
192
193#endif // !defined(FASTLED_STUB_IMPL)
194
196
197#endif
central include file for FastLED, defines the CFastLED class/object
Software SPI (aka bit-banging) support Includes aggressive optimizations for when the clock and data ...
Hardware SPI output.
Definition fastspi.h:51
Software SPI output.
Definition fastspi.h:56
deprecated: base definitions used by led controllers for writing out led data
Software SPI (aka bit-banging) support.
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.
#define FASTLED_NAMESPACE_END
End of the FastLED namespace.
Definition namespace.h:16
#define FASTLED_NAMESPACE_BEGIN
Start of the FastLED namespace.
Definition namespace.h:14