From 98b2cd8e7622e0f494e8b7a4dc08701adcae09d7 Mon Sep 17 00:00:00 2001 From: soypat Date: Wed, 9 Sep 2026 01:58:30 -0700 Subject: [PATCH] add new Base API based on @davecheney parallel changes --- rp2-pio/pio.go | 21 +++++++++++++++++++++ rp2-pio/pio_rp2040.go | 8 ++++++++ rp2-pio/pio_rp2350.go | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/rp2-pio/pio.go b/rp2-pio/pio.go index 47c423b..edfd9b0 100644 --- a/rp2-pio/pio.go +++ b/rp2-pio/pio.go @@ -431,3 +431,24 @@ type noCopy struct{} // Lock is a no-op used by -copylocks checker from `go vet`. func (*noCopy) Lock() {} func (*noCopy) UnLock() {} + +// GPIOBase checks base of used pins. When using ranges of pins +// you only need to pass in the "highest" pin of the range. +// if OK is false then pin set is invalid: either +// they do not share the same base or they are out of device pin range. +// Base should be then set with [SetGPIOBase] and base value subtracted from pins. +func GPIOBase(pins ...machine.Pin) (base uint32, ok bool) { + ok = true + expectLowbase := pins[0] < 32 + for _, pin := range pins { + lowbase := pin < 32 + if pin >= numPins || expectLowbase != lowbase { + ok = false // exceeded number of pins or mismatched base between pins. + break + } + } + if ok && !expectLowbase { + base = 16 + } + return base, ok +} diff --git a/rp2-pio/pio_rp2040.go b/rp2-pio/pio_rp2040.go index cd46091..0072628 100644 --- a/rp2-pio/pio_rp2040.go +++ b/rp2-pio/pio_rp2040.go @@ -11,6 +11,7 @@ import ( const ( rp2350ExtraReg = 0 numPIO = 2 + numPins = 32 // validINTEBits defines valid interrupt source bits for RP2040. // RP2040 only supports 12 bits: FIFO status (bits 0-7) and IRQ flags 0-3 (bits 8-11). @@ -51,6 +52,13 @@ func irqSet(num uint32, enabled bool) { irqSetMask(1<