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.

51 lines
922B

  1. #include "WS2812Serial.h"
  2. void WS2812Serial::begin()
  3. {
  4. if (!uart) return;
  5. if (!dma) dma = new DMAChannel;
  6. if (!dma) return;
  7. SIM_SCGC4 |= SIM_SCGC4_UART0;
  8. uint32_t divisor = BAUD2DIV(2400000);
  9. CORE_PIN1_CONFIG = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(3);
  10. UART0_BDH = (divisor >> 13) & 0x1F;
  11. UART0_BDL = (divisor >> 5) & 0xFF;
  12. UART0_C4 = divisor & 0x1F;
  13. UART0_C1 = 0;
  14. UART0_PFIFO = 0;
  15. UART0_C2 = UART_C2_TE;
  16. UART0_C3 = UART_C3_TXINV;
  17. UART0_C5 = UART_C5_TDMAS;
  18. frameBuffer[0] = 0xDB;
  19. frameBuffer[1] = 0xDA;
  20. frameBuffer[2] = 0xDB;
  21. dma->sourceBuffer(frameBuffer, 3);
  22. dma->destination(UART0_D);
  23. dma->transferSize(1);
  24. dma->transferCount(3);
  25. dma->disableOnCompletion();
  26. dma->triggerAtHardwareEvent(DMAMUX_SOURCE_UART0_TX);
  27. }
  28. void WS2812Serial::show()
  29. {
  30. //UART0_D = 0xDB;
  31. //UART0_D = 0xDA;
  32. //UART0_D = 0xDB;
  33. dma->enable();
  34. UART0_C2 = UART_C2_TE | UART_C2_TIE;
  35. }