PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
6.4KB

  1. #define FASTLED_INTERNAL
  2. #include "FastLED.h"
  3. #if defined(__SAM3X8E__)
  4. volatile uint32_t fuckit;
  5. #endif
  6. FASTLED_NAMESPACE_BEGIN
  7. void *pSmartMatrix = NULL;
  8. CFastLED FastLED;
  9. CLEDController *CLEDController::m_pHead = NULL;
  10. CLEDController *CLEDController::m_pTail = NULL;
  11. static uint32_t lastshow = 0;
  12. uint32_t _frame_cnt=0;
  13. uint32_t _retry_cnt=0;
  14. // uint32_t CRGB::Squant = ((uint32_t)((__TIME__[4]-'0') * 28))<<16 | ((__TIME__[6]-'0')*50)<<8 | ((__TIME__[7]-'0')*28);
  15. CFastLED::CFastLED() {
  16. // clear out the array of led controllers
  17. // m_nControllers = 0;
  18. m_Scale = 255;
  19. m_nFPS = 0;
  20. m_pPowerFunc = NULL;
  21. m_nPowerData = 0xFFFFFFFF;
  22. }
  23. CLEDController &CFastLED::addLeds(CLEDController *pLed,
  24. struct CRGB *data,
  25. int nLedsOrOffset, int nLedsIfOffset) {
  26. int nOffset = (nLedsIfOffset > 0) ? nLedsOrOffset : 0;
  27. int nLeds = (nLedsIfOffset > 0) ? nLedsIfOffset : nLedsOrOffset;
  28. pLed->init();
  29. pLed->setLeds(data + nOffset, nLeds);
  30. FastLED.setMaxRefreshRate(pLed->getMaxRefreshRate(),true);
  31. return *pLed;
  32. }
  33. void CFastLED::show(uint8_t scale) {
  34. // guard against showing too rapidly
  35. while(m_nMinMicros && ((micros()-lastshow) < m_nMinMicros));
  36. lastshow = micros();
  37. // If we have a function for computing power, use it!
  38. if(m_pPowerFunc) {
  39. scale = (*m_pPowerFunc)(scale, m_nPowerData);
  40. }
  41. CLEDController *pCur = CLEDController::head();
  42. while(pCur) {
  43. uint8_t d = pCur->getDither();
  44. if(m_nFPS < 100) { pCur->setDither(0); }
  45. pCur->showLeds(scale);
  46. pCur->setDither(d);
  47. pCur = pCur->next();
  48. }
  49. countFPS();
  50. }
  51. int CFastLED::count() {
  52. int x = 0;
  53. CLEDController *pCur = CLEDController::head();
  54. while( pCur) {
  55. x++;
  56. pCur = pCur->next();
  57. }
  58. return x;
  59. }
  60. CLEDController & CFastLED::operator[](int x) {
  61. CLEDController *pCur = CLEDController::head();
  62. while(x-- && pCur) {
  63. pCur = pCur->next();
  64. }
  65. if(pCur == NULL) {
  66. return *(CLEDController::head());
  67. } else {
  68. return *pCur;
  69. }
  70. }
  71. void CFastLED::showColor(const struct CRGB & color, uint8_t scale) {
  72. while(m_nMinMicros && ((micros()-lastshow) < m_nMinMicros));
  73. lastshow = micros();
  74. // If we have a function for computing power, use it!
  75. if(m_pPowerFunc) {
  76. scale = (*m_pPowerFunc)(scale, m_nPowerData);
  77. }
  78. CLEDController *pCur = CLEDController::head();
  79. while(pCur) {
  80. uint8_t d = pCur->getDither();
  81. if(m_nFPS < 100) { pCur->setDither(0); }
  82. pCur->showColor(color, scale);
  83. pCur->setDither(d);
  84. pCur = pCur->next();
  85. }
  86. countFPS();
  87. }
  88. void CFastLED::clear(bool writeData) {
  89. if(writeData) {
  90. showColor(CRGB(0,0,0), 0);
  91. }
  92. clearData();
  93. }
  94. void CFastLED::clearData() {
  95. CLEDController *pCur = CLEDController::head();
  96. while(pCur) {
  97. pCur->clearLedData();
  98. pCur = pCur->next();
  99. }
  100. }
  101. void CFastLED::delay(unsigned long ms) {
  102. unsigned long start = millis();
  103. do {
  104. #ifndef FASTLED_ACCURATE_CLOCK
  105. // make sure to allow at least one ms to pass to ensure the clock moves
  106. // forward
  107. ::delay(1);
  108. #endif
  109. show();
  110. yield();
  111. }
  112. while((millis()-start) < ms);
  113. }
  114. void CFastLED::setTemperature(const struct CRGB & temp) {
  115. CLEDController *pCur = CLEDController::head();
  116. while(pCur) {
  117. pCur->setTemperature(temp);
  118. pCur = pCur->next();
  119. }
  120. }
  121. void CFastLED::setCorrection(const struct CRGB & correction) {
  122. CLEDController *pCur = CLEDController::head();
  123. while(pCur) {
  124. pCur->setCorrection(correction);
  125. pCur = pCur->next();
  126. }
  127. }
  128. void CFastLED::setDither(uint8_t ditherMode) {
  129. CLEDController *pCur = CLEDController::head();
  130. while(pCur) {
  131. pCur->setDither(ditherMode);
  132. pCur = pCur->next();
  133. }
  134. }
  135. //
  136. // template<int m, int n> void transpose8(unsigned char A[8], unsigned char B[8]) {
  137. // uint32_t x, y, t;
  138. //
  139. // // Load the array and pack it into x and y.
  140. // y = *(unsigned int*)(A);
  141. // x = *(unsigned int*)(A+4);
  142. //
  143. // // x = (A[0]<<24) | (A[m]<<16) | (A[2*m]<<8) | A[3*m];
  144. // // y = (A[4*m]<<24) | (A[5*m]<<16) | (A[6*m]<<8) | A[7*m];
  145. //
  146. // // pre-transform x
  147. // t = (x ^ (x >> 7)) & 0x00AA00AA; x = x ^ t ^ (t << 7);
  148. // t = (x ^ (x >>14)) & 0x0000CCCC; x = x ^ t ^ (t <<14);
  149. //
  150. // // pre-transform y
  151. // t = (y ^ (y >> 7)) & 0x00AA00AA; y = y ^ t ^ (t << 7);
  152. // t = (y ^ (y >>14)) & 0x0000CCCC; y = y ^ t ^ (t <<14);
  153. //
  154. // // final transform
  155. // t = (x & 0xF0F0F0F0) | ((y >> 4) & 0x0F0F0F0F);
  156. // y = ((x << 4) & 0xF0F0F0F0) | (y & 0x0F0F0F0F);
  157. // x = t;
  158. //
  159. // B[7*n] = y; y >>= 8;
  160. // B[6*n] = y; y >>= 8;
  161. // B[5*n] = y; y >>= 8;
  162. // B[4*n] = y;
  163. //
  164. // B[3*n] = x; x >>= 8;
  165. // B[2*n] = x; x >>= 8;
  166. // B[n] = x; x >>= 8;
  167. // B[0] = x;
  168. // // B[0]=x>>24; B[n]=x>>16; B[2*n]=x>>8; B[3*n]=x>>0;
  169. // // B[4*n]=y>>24; B[5*n]=y>>16; B[6*n]=y>>8; B[7*n]=y>>0;
  170. // }
  171. //
  172. // void transposeLines(Lines & out, Lines & in) {
  173. // transpose8<1,2>(in.bytes, out.bytes);
  174. // transpose8<1,2>(in.bytes + 8, out.bytes + 1);
  175. // }
  176. extern int noise_min;
  177. extern int noise_max;
  178. void CFastLED::countFPS(int nFrames) {
  179. static int br = 0;
  180. static uint32_t lastframe = 0; // millis();
  181. if(br++ >= nFrames) {
  182. uint32_t now = millis();
  183. now -= lastframe;
  184. if( now == 0 ) {
  185. now = 1; // prevent division by zero below
  186. }
  187. m_nFPS = (br * 1000) / now;
  188. br = 0;
  189. lastframe = millis();
  190. }
  191. }
  192. void CFastLED::setMaxRefreshRate(uint16_t refresh, bool constrain) {
  193. if(constrain) {
  194. // if we're constraining, the new value of m_nMinMicros _must_ be higher than previously (because we're only
  195. // allowed to slow things down if constraining)
  196. if(refresh > 0) {
  197. m_nMinMicros = ( (1000000/refresh) > m_nMinMicros) ? (1000000/refresh) : m_nMinMicros;
  198. }
  199. } else if(refresh > 0) {
  200. m_nMinMicros = 1000000 / refresh;
  201. } else {
  202. m_nMinMicros = 0;
  203. }
  204. }
  205. extern "C" int atexit(void (* /*func*/ )()) { return 0; }
  206. #ifdef FASTLED_NEEDS_YIELD
  207. extern "C" void yield(void) { }
  208. #endif
  209. #ifdef NEED_CXX_BITS
  210. namespace __cxxabiv1
  211. {
  212. #if !defined(ESP8266) && !defined(ESP32)
  213. extern "C" void __cxa_pure_virtual (void) {}
  214. #endif
  215. /* guard variables */
  216. /* The ABI requires a 64-bit type. */
  217. __extension__ typedef int __guard __attribute__((mode(__DI__)));
  218. extern "C" int __cxa_guard_acquire (__guard *) __attribute__((weak));
  219. extern "C" void __cxa_guard_release (__guard *) __attribute__((weak));
  220. extern "C" void __cxa_guard_abort (__guard *) __attribute__((weak));
  221. extern "C" int __cxa_guard_acquire (__guard *g)
  222. {
  223. return !*(char *)(g);
  224. }
  225. extern "C" void __cxa_guard_release (__guard *g)
  226. {
  227. *(char *)g = 1;
  228. }
  229. extern "C" void __cxa_guard_abort (__guard *)
  230. {
  231. }
  232. }
  233. #endif
  234. FASTLED_NAMESPACE_END