File tree Expand file tree Collapse file tree 1 file changed +19
-16
lines changed Expand file tree Collapse file tree 1 file changed +19
-16
lines changed Original file line number Diff line number Diff line change 44
55bool Adafruit_NeoPixel::rp2040claimPIO (void ) {
66 // Find a PIO with enough available space in its instruction memory
7- pio = pio0;
8- if (pio_can_add_program (pio, &ws2812_program)) {
9- pio_program_offset = pio_add_program (pio, &ws2812_program);
10- } else {
11- // ok try pio1
12- pio = pio1;
13- if (pio_can_add_program (pio, &ws2812_program)) {
14- pio_program_offset = pio_add_program (pio, &ws2812_program);
15- } else {
16- // ok try pio2 (RP2350)
17- pio = pio2;
18- if (pio_can_add_program (pio, &ws2812_program)) {
7+ pio = NULL ;
8+
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];
1922 pio_program_offset = pio_add_program (pio, &ws2812_program);
20- } else {
21- pio = NULL ;
22- return false ;
23- }
23+ break ;
2424 }
2525 }
26+ if (pio == NULL ) {
27+ return false ; // No PIO available
28+ }
2629
2730 // Find a free SM on one of the PIO's
2831 pio_sm = pio_claim_unused_sm (pio, false ); // don't panic
You can’t perform that action at this time.
0 commit comments