Open urish opened 4 months ago
I like it and it'd be useful. Could include as is but this stuff involves some caveats... mainly that the pin becomes taken over by PIO, e.g.
Pin(GPIO21, mode=ALT, pull=PULL_DOWN, alt=PIO0)
and then all the uPython sdk stuff doesn't necessarily work as expected. So this is expertish mode. So, we add it as a util or side library in the SDK? Or start a side project set of libs for things like this?
In some cases, like my TT04 USB CDC project, we need a way to pulse a pin for a single clock cycle, e.g. to latch some value into a register.
This can be achieved using the Pi Pico's PIO. The relevant PIO machine code is as follows:
Then, to use it, you need to set up the clock frequency to match your project clock frequency (48 MHz in the example below), and to set the pin you would like to pulse:
Finally, to pulse the pin, call to
put
method with any value, e.g.:It would be great to have this functionality built into the SDK, e.g. as a utility class that takes a pin number and the tt object, and creates the PIO machines behind the scenes. Something along the following lines: