Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

52 rindas
1.2KB

  1. #ifndef WS2812Serial_h_
  2. #define WS2812Serial_h_
  3. #include <Arduino.h>
  4. #include "DMAChannel.h"
  5. #define WS2812_RGB 0 // The WS2811 datasheet documents this way
  6. #define WS2812_RBG 1
  7. #define WS2812_GRB 2 // Most LED strips are wired this way
  8. #define WS2812_GBR 3
  9. #define WS2812_BRG 4
  10. #define WS2812_BGR 5
  11. class WS2812Serial {
  12. public:
  13. constexpr WS2812Serial(uint16_t n, void *f, void *d, HardwareSerial &s, uint8_t c) :
  14. numled(n), config(c),
  15. frameBuffer((uint8_t *)f), drawBuffer((uint8_t *)d),
  16. uart( &s == &Serial1 ? &KINETISK_UART0 : nullptr)
  17. {
  18. }
  19. void begin();
  20. void setPixel(uint32_t num, int color) {
  21. if (num >= numled) return;
  22. num *= 3;
  23. drawBuffer[num+0] = color & 255;
  24. drawBuffer[num+1] = (color >> 8) & 255;
  25. drawBuffer[num+2] = (color >> 16) & 255;
  26. }
  27. void setPixel(uint32_t num, uint8_t red, uint8_t green, uint8_t blue) {
  28. if (num >= numled) return;
  29. num *= 3;
  30. drawBuffer[num+0] = blue;
  31. drawBuffer[num+1] = green;
  32. drawBuffer[num+2] = red;
  33. }
  34. void show();
  35. bool busy();
  36. uint16_t numPixels() {
  37. return numled;
  38. }
  39. private:
  40. const uint16_t numled;
  41. const uint8_t config;
  42. uint8_t *frameBuffer;
  43. uint8_t *drawBuffer;
  44. KINETISK_UART_t *uart;
  45. DMAChannel *dma = nullptr;
  46. };
  47. #endif