Skip to content

Commit c2e1046

Browse files
committed
use modern API
1 parent 6b4ffe3 commit c2e1046

File tree

2 files changed

+9
-33
lines changed

2 files changed

+9
-33
lines changed

Adafruit_NeoPixel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ class Adafruit_NeoPixel {
388388
void rp2040releasePIO(void);
389389
void rp2040Show(uint8_t *pixels, uint32_t numBytes);
390390
PIO pio = NULL;
391-
int8_t pio_sm = -1;
392-
uint32_t pio_program_offset = 0;
391+
uint pio_sm = -1;
392+
uint pio_program_offset = 0;
393393
#endif
394394

395395
protected:

Adafruit_Neopixel_RP2.cpp

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,15 @@ bool Adafruit_NeoPixel::rp2040claimPIO(void) {
66
// Find a PIO with enough available space in its instruction memory
77
pio = NULL;
88

9-
#ifdef pio2
10-
// RP2350 - has 3 PIOs
11-
PIO pios[] = {pio0, pio1, pio2};
12-
#else
13-
// RP2040 - has 2 PIOs
14-
PIO pios[] = {pio0, pio1};
15-
#endif
16-
17-
uint8_t pio_count = sizeof(pios) / sizeof(pios[0]);
18-
19-
for (uint8_t i = 0; i < pio_count; i++) {
20-
if (pio_can_add_program(pios[i], &ws2812_program)) {
21-
pio = pios[i];
22-
pio_program_offset = pio_add_program(pio, &ws2812_program);
23-
break;
24-
}
25-
}
26-
if (pio == NULL) {
9+
if (! pio_claim_free_sm_and_add_program_for_gpio_range(&ws2812_program,
10+
&pio, &pio_sm, &pio_program_offset,
11+
pin, 1, true)) {
12+
pio = NULL;
13+
pio_sm = -1;
14+
pio_program_offset = 0;
2715
return false; // No PIO available
2816
}
2917

30-
// Find a free SM on one of the PIO's
31-
pio_sm = pio_claim_unused_sm(pio, false); // don't panic
32-
if (pio_sm < 0) {
33-
return false;
34-
}
35-
3618
// yay ok!
3719

3820
if (is800KHz) {
@@ -50,13 +32,7 @@ void Adafruit_NeoPixel::rp2040releasePIO(void) {
5032
if (pio == NULL)
5133
return;
5234

53-
pio_remove_program(pio, &ws2812_program, pio_program_offset);
54-
55-
if (pio_sm < 0)
56-
return;
57-
58-
pio_sm_set_enabled(pio, pio_sm, false);
59-
pio_sm_unclaim(pio, pio_sm);
35+
pio_remove_program_and_unclaim_sm(&ws2812_program, pio, pio_sm, pio_program_offset);
6036
}
6137

6238

0 commit comments

Comments
 (0)