Conversation
lurch
commented
Feb 14, 2026
- Add extra comments and defines to make the code easier to understand
- Use pio_claim_unused_sm instead of hardcoding "last SM + 1"
- Should now work with LED3 on GPIO 31 and LED4 on GPIO 32
* Add extra comments and defines to make the code easier to understand * Use pio_claim_unused_sm instead of hardcoding "last SM + 1" * Should now work with LED3 on GPIO 31 and LED4 on GPIO 32
| sm[1] = sm[0] + 2; | ||
| offset[1] = offset[0]; | ||
| pio_sm_claim(pio[1], sm[1]); | ||
| sm[2] = pio_claim_unused_sm(pio[1], true); |
There was a problem hiding this comment.
Maybe we should have a pio_claim_free_sm_and_add_for_gpio_range function
There was a problem hiding this comment.
Sounds like a @kilograham question to me! 😆
(Although I guess that potential function might be useful for @poetaster in raspberrypi/pico-sdk#2030 )
There was a problem hiding this comment.
Or we should make the existing function clever enough to know not to add the same program to the same PIO twice.
There was a problem hiding this comment.
Or we should make the existing function clever enough to know not to add the same program to the same PIO twice.
Don't know if we can do that with the current API, as I think the PIO instruction memory is write-only?
There was a problem hiding this comment.
You might be able to stash an array of pio_program_t structures. Worth seeing if it makes the API better.
| assert(PIO_BLINK_LED3_GPIO < 31 || PIO_BLINK_LED3_GPIO >= 32); | ||
|
|
||
| // LED1 and LED2 are both expected to be in the "lower" range of PIO-addressable GPIOs | ||
| assert((PIO_BLINK_LED1_GPIO < 32) && (PIO_BLINK_LED2_GPIO < 32)); |
There was a problem hiding this comment.
arguably, these asserts should be unnecessary - the code should be able to work whatever value is used.
There was a problem hiding this comment.
I guess it depends on the focus of the example - is it showing "here's how you flash two GPIOs in one PIO-range and two GPIOs in a different range" (which I think was the original intention?), or is it showing "here's totally generic (but more complicated) code for flashing any four GPIOs in any combination" ?
Perhaps I ought to add a comment highlighting the intention of the example? 🤔
There was a problem hiding this comment.
Perhaps I ought to add a comment highlighting the intention of the example?
Done.