rp2040.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // This sketch is based on the SDK example here:
  2. // https://github.com/raspberrypi/pico-examples/tree/master/pio/ws2812
  3. /**
  4. Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
  5. SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #if defined(ARDUINO_ARCH_RP2040)
  8. #include <stdlib.h>
  9. #include "hardware/pio.h"
  10. #include "hardware/clocks.h"
  11. #include "rp2040_pio.h"
  12. void rp2040Init(uint8_t pin, bool is800KHz)
  13. {
  14. // todo get free sm
  15. PIO pio = pio0;
  16. int sm = 0;
  17. uint offset = pio_add_program(pio, &ws2812_program);
  18. if (is800KHz)
  19. {
  20. // 800kHz, 8 bit transfers
  21. ws2812_program_init(pio, sm, offset, pin, 800000, 8);
  22. }
  23. else
  24. {
  25. // 400kHz, 8 bit transfers
  26. ws2812_program_init(pio, sm, offset, pin, 400000, 8);
  27. }
  28. }
  29. void rp2040Show(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz)
  30. {
  31. static bool init = true;
  32. if (init)
  33. {
  34. // On first pass through initialise the PIO
  35. rp2040Init(pin, is800KHz);
  36. init = false;
  37. }
  38. while(numBytes--)
  39. // Bits for transmission must be shifted to top 8 bits
  40. pio_sm_put_blocking(pio0, 0, ((uint32_t)*pixels++)<< 24);
  41. }
  42. #endif // KENDRYTE_K210