PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

252 lines
6.4KB

  1. #define FASTLED_INTERNAL
  2. #include <stdint.h>
  3. #include "FastLED.h"
  4. FASTLED_NAMESPACE_BEGIN
  5. #define RAND16_SEED 1337
  6. uint16_t rand16seed = RAND16_SEED;
  7. // memset8, memcpy8, memmove8:
  8. // optimized avr replacements for the standard "C" library
  9. // routines memset, memcpy, and memmove.
  10. //
  11. // There are two techniques that make these routines
  12. // faster than the standard avr-libc routines.
  13. // First, the loops are unrolled 2X, meaning that
  14. // the average loop overhead is cut in half.
  15. // And second, the compare-and-branch at the bottom
  16. // of each loop decrements the low byte of the
  17. // counter, and if the carry is clear, it branches
  18. // back up immediately. Only if the low byte math
  19. // causes carry do we bother to decrement the high
  20. // byte and check that result for carry as well.
  21. // Results for a 100-byte buffer are 20-40% faster
  22. // than standard avr-libc, at a cost of a few extra
  23. // bytes of code.
  24. #if defined(__AVR__)
  25. extern "C" {
  26. //__attribute__ ((noinline))
  27. void * memset8 ( void * ptr, uint8_t val, uint16_t num )
  28. {
  29. asm volatile(
  30. " movw r26, %[ptr] \n\t"
  31. " sbrs %A[num], 0 \n\t"
  32. " rjmp Lseteven_%= \n\t"
  33. " rjmp Lsetodd_%= \n\t"
  34. "Lsetloop_%=: \n\t"
  35. " st X+, %[val] \n\t"
  36. "Lsetodd_%=: \n\t"
  37. " st X+, %[val] \n\t"
  38. "Lseteven_%=: \n\t"
  39. " subi %A[num], 2 \n\t"
  40. " brcc Lsetloop_%= \n\t"
  41. " sbci %B[num], 0 \n\t"
  42. " brcc Lsetloop_%= \n\t"
  43. : [num] "+r" (num)
  44. : [ptr] "r" (ptr),
  45. [val] "r" (val)
  46. : "memory"
  47. );
  48. return ptr;
  49. }
  50. //__attribute__ ((noinline))
  51. void * memcpy8 ( void * dst, const void* src, uint16_t num )
  52. {
  53. asm volatile(
  54. " movw r30, %[src] \n\t"
  55. " movw r26, %[dst] \n\t"
  56. " sbrs %A[num], 0 \n\t"
  57. " rjmp Lcpyeven_%= \n\t"
  58. " rjmp Lcpyodd_%= \n\t"
  59. "Lcpyloop_%=: \n\t"
  60. " ld __tmp_reg__, Z+ \n\t"
  61. " st X+, __tmp_reg__ \n\t"
  62. "Lcpyodd_%=: \n\t"
  63. " ld __tmp_reg__, Z+ \n\t"
  64. " st X+, __tmp_reg__ \n\t"
  65. "Lcpyeven_%=: \n\t"
  66. " subi %A[num], 2 \n\t"
  67. " brcc Lcpyloop_%= \n\t"
  68. " sbci %B[num], 0 \n\t"
  69. " brcc Lcpyloop_%= \n\t"
  70. : [num] "+r" (num)
  71. : [src] "r" (src),
  72. [dst] "r" (dst)
  73. : "memory"
  74. );
  75. return dst;
  76. }
  77. //__attribute__ ((noinline))
  78. void * memmove8 ( void * dst, const void* src, uint16_t num )
  79. {
  80. if( src > dst) {
  81. // if src > dst then we can use the forward-stepping memcpy8
  82. return memcpy8( dst, src, num);
  83. } else {
  84. // if src < dst then we have to step backward:
  85. dst = (char*)dst + num;
  86. src = (char*)src + num;
  87. asm volatile(
  88. " movw r30, %[src] \n\t"
  89. " movw r26, %[dst] \n\t"
  90. " sbrs %A[num], 0 \n\t"
  91. " rjmp Lmoveven_%= \n\t"
  92. " rjmp Lmovodd_%= \n\t"
  93. "Lmovloop_%=: \n\t"
  94. " ld __tmp_reg__, -Z \n\t"
  95. " st -X, __tmp_reg__ \n\t"
  96. "Lmovodd_%=: \n\t"
  97. " ld __tmp_reg__, -Z \n\t"
  98. " st -X, __tmp_reg__ \n\t"
  99. "Lmoveven_%=: \n\t"
  100. " subi %A[num], 2 \n\t"
  101. " brcc Lmovloop_%= \n\t"
  102. " sbci %B[num], 0 \n\t"
  103. " brcc Lmovloop_%= \n\t"
  104. : [num] "+r" (num)
  105. : [src] "r" (src),
  106. [dst] "r" (dst)
  107. : "memory"
  108. );
  109. return dst;
  110. }
  111. }
  112. } /* end extern "C" */
  113. #endif /* AVR */
  114. #if 0
  115. // TEST / VERIFICATION CODE ONLY BELOW THIS POINT
  116. #include <Arduino.h>
  117. #include "lib8tion.h"
  118. void test1abs( int8_t i)
  119. {
  120. Serial.print("abs("); Serial.print(i); Serial.print(") = ");
  121. int8_t j = abs8(i);
  122. Serial.print(j); Serial.println(" ");
  123. }
  124. void testabs()
  125. {
  126. delay(5000);
  127. for( int8_t q = -128; q != 127; q++) {
  128. test1abs(q);
  129. }
  130. for(;;){};
  131. }
  132. void testmul8()
  133. {
  134. delay(5000);
  135. byte r, c;
  136. Serial.println("mul8:");
  137. for( r = 0; r <= 20; r += 1) {
  138. Serial.print(r); Serial.print(" : ");
  139. for( c = 0; c <= 20; c += 1) {
  140. byte t;
  141. t = mul8( r, c);
  142. Serial.print(t); Serial.print(' ');
  143. }
  144. Serial.println(' ');
  145. }
  146. Serial.println("done.");
  147. for(;;){};
  148. }
  149. void testscale8()
  150. {
  151. delay(5000);
  152. byte r, c;
  153. Serial.println("scale8:");
  154. for( r = 0; r <= 240; r += 10) {
  155. Serial.print(r); Serial.print(" : ");
  156. for( c = 0; c <= 240; c += 10) {
  157. byte t;
  158. t = scale8( r, c);
  159. Serial.print(t); Serial.print(' ');
  160. }
  161. Serial.println(' ');
  162. }
  163. Serial.println(' ');
  164. Serial.println("scale8_video:");
  165. for( r = 0; r <= 100; r += 4) {
  166. Serial.print(r); Serial.print(" : ");
  167. for( c = 0; c <= 100; c += 4) {
  168. byte t;
  169. t = scale8_video( r, c);
  170. Serial.print(t); Serial.print(' ');
  171. }
  172. Serial.println(' ');
  173. }
  174. Serial.println("done.");
  175. for(;;){};
  176. }
  177. void testqadd8()
  178. {
  179. delay(5000);
  180. byte r, c;
  181. for( r = 0; r <= 240; r += 10) {
  182. Serial.print(r); Serial.print(" : ");
  183. for( c = 0; c <= 240; c += 10) {
  184. byte t;
  185. t = qadd8( r, c);
  186. Serial.print(t); Serial.print(' ');
  187. }
  188. Serial.println(' ');
  189. }
  190. Serial.println("done.");
  191. for(;;){};
  192. }
  193. void testnscale8x3()
  194. {
  195. delay(5000);
  196. byte r, g, b, sc;
  197. for( byte z = 0; z < 10; z++) {
  198. r = random8(); g = random8(); b = random8(); sc = random8();
  199. Serial.print("nscale8x3_video( ");
  200. Serial.print(r); Serial.print(", ");
  201. Serial.print(g); Serial.print(", ");
  202. Serial.print(b); Serial.print(", ");
  203. Serial.print(sc); Serial.print(") = [ ");
  204. nscale8x3_video( r, g, b, sc);
  205. Serial.print(r); Serial.print(", ");
  206. Serial.print(g); Serial.print(", ");
  207. Serial.print(b); Serial.print("]");
  208. Serial.println(' ');
  209. }
  210. Serial.println("done.");
  211. for(;;){};
  212. }
  213. #endif
  214. FASTLED_NAMESPACE_END