1+ #define FASTLED_INTERNAL
12#include " FastLED.h"
23
4+
35#if defined(__SAM3X8E__)
46volatile uint32_t fuckit;
57#endif
68
9+ FASTLED_NAMESPACE_BEGIN
10+
711void *pSmartMatrix = NULL ;
812
9- CFastLED LEDS;
10- CFastLED & FastSPI_LED = LEDS;
11- CFastLED & FastSPI_LED2 = LEDS;
12- CFastLED & FastLED = LEDS;
13+ CFastLED FastLED;
1314
1415CLEDController *CLEDController::m_pHead = NULL ;
1516CLEDController *CLEDController::m_pTail = NULL ;
17+ static uint32_t lastshow = 0 ;
1618
1719// uint32_t CRGB::Squant = ((uint32_t)((__TIME__[4]-'0') * 28))<<16 | ((__TIME__[6]-'0')*50)<<8 | ((__TIME__[7]-'0')*28);
1820
@@ -31,10 +33,15 @@ CLEDController &CFastLED::addLeds(CLEDController *pLed,
3133
3234 pLed->init ();
3335 pLed->setLeds (data + nOffset, nLeds);
36+ FastLED.setMaxRefreshRate (pLed->getMaxRefreshRate (),true );
3437 return *pLed;
3538}
3639
3740void CFastLED::show (uint8_t scale) {
41+ // guard against showing too rapidly
42+ while (m_nMinMicros && ((micros ()-lastshow) < m_nMinMicros));
43+ lastshow = micros ();
44+
3845 CLEDController *pCur = CLEDController::head ();
3946 while (pCur) {
4047 uint8_t d = pCur->getDither ();
@@ -69,6 +76,9 @@ CLEDController & CFastLED::operator[](int x) {
6976}
7077
7178void CFastLED::showColor (const struct CRGB & color, uint8_t scale) {
79+ while (m_nMinMicros && ((micros ()-lastshow) < m_nMinMicros));
80+ lastshow = micros ();
81+
7282 CLEDController *pCur = CLEDController::head ();
7383 while (pCur) {
7484 uint8_t d = pCur->getDither ();
@@ -98,7 +108,11 @@ void CFastLED::clearData() {
98108void CFastLED::delay (unsigned long ms) {
99109 unsigned long start = millis ();
100110 while ((millis ()-start) < ms) {
111+ #ifndef FASTLED_ACCURATE_CLOCK
112+ // make sure to allow at least one ms to pass to ensure the clock moves
113+ // forward
101114 ::delay (1 );
115+ #endif
102116 show ();
103117 }
104118}
@@ -127,6 +141,48 @@ void CFastLED::setDither(uint8_t ditherMode) {
127141 }
128142}
129143
144+ //
145+ // template<int m, int n> void transpose8(unsigned char A[8], unsigned char B[8]) {
146+ // uint32_t x, y, t;
147+ //
148+ // // Load the array and pack it into x and y.
149+ // y = *(unsigned int*)(A);
150+ // x = *(unsigned int*)(A+4);
151+ //
152+ // // x = (A[0]<<24) | (A[m]<<16) | (A[2*m]<<8) | A[3*m];
153+ // // y = (A[4*m]<<24) | (A[5*m]<<16) | (A[6*m]<<8) | A[7*m];
154+ //
155+ // // pre-transform x
156+ // t = (x ^ (x >> 7)) & 0x00AA00AA; x = x ^ t ^ (t << 7);
157+ // t = (x ^ (x >>14)) & 0x0000CCCC; x = x ^ t ^ (t <<14);
158+ //
159+ // // pre-transform y
160+ // t = (y ^ (y >> 7)) & 0x00AA00AA; y = y ^ t ^ (t << 7);
161+ // t = (y ^ (y >>14)) & 0x0000CCCC; y = y ^ t ^ (t <<14);
162+ //
163+ // // final transform
164+ // t = (x & 0xF0F0F0F0) | ((y >> 4) & 0x0F0F0F0F);
165+ // y = ((x << 4) & 0xF0F0F0F0) | (y & 0x0F0F0F0F);
166+ // x = t;
167+ //
168+ // B[7*n] = y; y >>= 8;
169+ // B[6*n] = y; y >>= 8;
170+ // B[5*n] = y; y >>= 8;
171+ // B[4*n] = y;
172+ //
173+ // B[3*n] = x; x >>= 8;
174+ // B[2*n] = x; x >>= 8;
175+ // B[n] = x; x >>= 8;
176+ // B[0] = x;
177+ // // B[0]=x>>24; B[n]=x>>16; B[2*n]=x>>8; B[3*n]=x>>0;
178+ // // B[4*n]=y>>24; B[5*n]=y>>16; B[6*n]=y>>8; B[7*n]=y>>0;
179+ // }
180+ //
181+ // void transposeLines(Lines & out, Lines & in) {
182+ // transpose8<1,2>(in.bytes, out.bytes);
183+ // transpose8<1,2>(in.bytes + 8, out.bytes + 1);
184+ // }
185+
130186extern int noise_min;
131187extern int noise_max;
132188
@@ -142,3 +198,50 @@ void CFastLED::countFPS(int nFrames) {
142198 lastframe = millis ();
143199 }
144200}
201+
202+ void CFastLED::setMaxRefreshRate (uint16_t refresh, bool constrain) {
203+ if (constrain) {
204+ // if we're constraining, the new value of m_nMinMicros _must_ be higher than previously (because we're only
205+ // allowed to slow things down if constraining)
206+ if (refresh > 0 ) {
207+ m_nMinMicros = ( (1000000 /refresh) > m_nMinMicros) ? (1000000 /refresh) : m_nMinMicros;
208+ }
209+ } else if (refresh > 0 ) {
210+ m_nMinMicros = 1000000 / refresh;
211+ } else {
212+ m_nMinMicros = 0 ;
213+ }
214+ }
215+
216+
217+ #ifdef NEED_CXX_BITS
218+ namespace __cxxabiv1
219+ {
220+ extern " C" void __cxa_pure_virtual (void ) {}
221+ /* guard variables */
222+
223+ /* The ABI requires a 64-bit type. */
224+ __extension__ typedef int __guard __attribute__ ((mode(__DI__)));
225+
226+ extern " C" int __cxa_guard_acquire (__guard *);
227+ extern " C" void __cxa_guard_release (__guard *);
228+ extern " C" void __cxa_guard_abort (__guard *);
229+
230+ extern " C" int __cxa_guard_acquire (__guard *g)
231+ {
232+ return !*(char *)(g);
233+ }
234+
235+ extern " C" void __cxa_guard_release (__guard *g)
236+ {
237+ *(char *)g = 1 ;
238+ }
239+
240+ extern " C" void __cxa_guard_abort (__guard *)
241+ {
242+
243+ }
244+ }
245+ #endif
246+
247+ FASTLED_NAMESPACE_END
0 commit comments