Package import"zappem.net/pub/io/pious"
Documentationhttps://pkg.go.dev/zappem.net/pub/io/pious
Sourceshttps://github.com/tinkerator/pious

pious - a go package supporting RP PIO sequences

Overview

The RP2350B processor contains a PIO engine that can be used to implement realtime communication protocol exchanges. This Go based project is one to help work with PIO sequences.

Status

The package supports assembling and disassembling known PIO instructions and Tinygo compatible code generation. An example application of the latter is to CRAM load the ice40 FPGA on a pico2-ice board.

Some of the tests are extracted from known assembly output.

To explore:

$ git clone https://github.com/tinkerator/pious.git
$ cd pious
$ go test -v
=== RUN   TestDisassemble
--- PASS: TestDisassemble (0.00s)
=== RUN   TestAssemble
--- PASS: TestAssemble (0.20s)
PASS
ok  	zappem.net/pub/io/pious	0.204s

An example assembling and then disassembling a .pio program:

$ go run examples/piocli.go --src pio/clock.pio
.program clock
.set 1
	set	pindirs, 1
.wrap_target
	set	pins, 0 [1]
	set	pins, 1 [1]
.wrap

That output matches the pio/clock.pio input.

You can prepare a tinygo compatible package that uses the rp2-pio package to manage a PIO sequence like this in the form of a package, clock in this case:

$ go install examples/piocli.go
$ ~/go/bin/piocli --src pio/clock.pio --tinygo > /tmp/clock.go
$ grep func /tmp/clock.go
func (s *StateMachine) Start() {
func (s *StateMachine) Activate(run bool) {
func Assign(block *pio.PIO) (*Engine, error) {
func (e *Engine) ConfigureClock(setBase machine.Pin) (*StateMachine, error) {

The way to initialize this PIO code is to select a GPIO (setBase) and use tinygo code like this:

e, _ := clock.Assign(rp2pio.PIO0)
s, _ := e.ConfigureClock(machine.GPIO6)
s.Start()
s.Activate(true)

You can disable or enable the running PIO clock driving machine.GPIO6 using s.Activate(false) and s.Activate(true) respectively.

Reference

The PIO Instruction set has 10 instruction types. One of these (nop) is a conventional alias for a pointless mov instruction. Full details are provided in the RP2350 Datasheet, but we provide a quick summary here:

NOTE: All instructions that assign values have an assignment direction to the left, that is the syntax specifies the destination to the left of the source.

Examples

The pio/ subdirectory contains some PIO example source files. These are used to validate the package, and provide some references for writing your own PIO code.

So far, we have:

TODO

Things I’m thinking about exploring:

Support

This is a personal project aiming at exploring the capabilities of the pico2-ice board. As such, no support can be expected. That being said, if you find a bug, or want to request a feature, use the github pious bug tracker.

License information

See the LICENSE file: the same BSD 3-clause license as that used by golang itself.


Markdown rendering courtesy of gomarkdown/markdown.