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.

ws2812serial_controller.h 1.1KB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef __INC_WS2812SERIAL_CONTROLLER_H
  2. #define __INC_WS2812SERIAL_CONTROLLER_H
  3. #ifdef USE_WS2812SERIAL
  4. FASTLED_NAMESPACE_BEGIN
  5. template<int DATA_PIN, EOrder RGB_ORDER>
  6. class CWS2812SerialController : public CPixelLEDController<RGB_ORDER, 8, 0xFF> {
  7. WS2812Serial *pserial;
  8. uint8_t *drawbuffer,*framebuffer;
  9. void _init(int nLeds) {
  10. if (pserial == NULL) {
  11. drawbuffer = (uint8_t*)malloc(nLeds * 3);
  12. framebuffer = (uint8_t*)malloc(nLeds * 12);
  13. pserial = new WS2812Serial(nLeds, framebuffer, drawbuffer, DATA_PIN, WS2812_RGB);
  14. pserial->begin();
  15. }
  16. }
  17. public:
  18. CWS2812SerialController() { pserial = NULL; }
  19. virtual void init() { /* do nothing yet */ }
  20. virtual void showPixels(PixelController<RGB_ORDER, 8, 0xFF> & pixels) {
  21. _init(pixels.size());
  22. uint8_t *p = drawbuffer;
  23. while(pixels.has(1)) {
  24. *p++ = pixels.loadAndScale0();
  25. *p++ = pixels.loadAndScale1();
  26. *p++ = pixels.loadAndScale2();
  27. pixels.stepDithering();
  28. pixels.advanceData();
  29. }
  30. pserial->show();
  31. }
  32. };
  33. FASTLED_NAMESPACE_END
  34. #endif // USE_WS2812SERIAL
  35. #endif // __INC_WS2812SERIAL_CONTROLLER_H