@@ -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