raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.26k stars 838 forks source link

pio helper functions #1616

Open peterharperuk opened 5 months ago

peterharperuk commented 5 months ago

It would be nice to add a pio_init function that picks a free pio, state machine and loads a program, as I keep writing this and it's easy to get wrong.

bool pio_init(const pio_program_t program, PIO pio_hw, uint sm, uint offset); static void pio_deinit(const pio_program_t *program, PIO pio_hw, uint sm, uint offset);

and while we're at it, pio_get_instance like static inline i2c_inst_t *i2c_get_instance(uint instance)

kilograham commented 5 months ago

don't like the name pio_init since it doesnt initialize a PIO

peterharperuk commented 5 months ago

pio_load?

lurch commented 5 months ago

pio_load_where_space_available or pio_load_if_possible ? :wink:

and while we're at it, pio_get_instance like static inline i2c_inst_t *i2c_get_instance(uint instance)

Unfortunately that function doesn't have any doxygen-comments, and thus doesn't appear in the API documentation.

EDIT: And there's also a (similarly un-documented) uart_get_instance function, but SPI is also lacking a _get_instance function. (And on a sidenote, it's also slightly inconsistent that I2C uses i2c_hw_index, whereas the other hardware-wrappers have pio_get_index, spi_get_index and uart_get_index functions.)

peterharperuk commented 5 months ago

some more ideas...

pio_claim_free_sm_add_program pio_unclaim_sm_remove_program