Krolyxon
Commit 1d55752

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8Adafruit NeoPixelAdafruit_Neopixel_RP2.cpp

50 lines · 1.4 KB · C++

1#if defined(ARDUINO_ARCH_RP2040) // RP2040 specific driver
2
3#include "Adafruit_NeoPixel.h"
4
5bool Adafruit_NeoPixel::rp2040claimPIO(void) {
6 // Find a PIO with enough available space in its instruction memory
7 pio = NULL;
8
9 if (!pio_claim_free_sm_and_add_program_for_gpio_range(
10 &ws2812_program, &pio, &pio_sm, &pio_program_offset, pin, 1,
11 true)) {
12 pio = NULL;
13 pio_sm = -1;
14 pio_program_offset = 0;
15 return false; // No PIO available
16 }
17
18 // yay ok!
19
20 if (is800KHz) {
21 // 800kHz, 8 bit transfers
22 ws2812_program_init(pio, pio_sm, pio_program_offset, pin, 800000, 8);
23 } else {
24 // 400kHz, 8 bit transfers
25 ws2812_program_init(pio, pio_sm, pio_program_offset, pin, 400000, 8);
26 }
27
28 return true;
29}
30
31void Adafruit_NeoPixel::rp2040releasePIO(void) {
32 if (pio == NULL)
33 return;
34
35 pio_remove_program_and_unclaim_sm(&ws2812_program, pio, pio_sm,
36 pio_program_offset);
37}
38
39// Private, called from show()
40void Adafruit_NeoPixel::rp2040Show(uint8_t *pixels, uint32_t numBytes) {
41 // verify we have a valid PIO and state machine
42 if (!pio || (pio_sm < 0)) {
43 return;
44 }
45
46 while (numBytes--)
47 // Bits for transmission must be shifted to top 8 bits
48 pio_sm_put_blocking(pio, pio_sm, ((uint32_t)*pixels++) << 24);
49}
50#endif