# RP2040 - Dual SM application, toggle GPIO16 and GPIO-26
# by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-08-22  Initial release

from	machine		import	Pin
import	rp2

# ======================= PIO functions ======================

# 1000 Hz 50/50 on GPIO-16 
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def Freq50():
    set(pins, 1)
    set(pins, 0)


# 1000 Hz 20/80 on GPIO-26 
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def Freq20():
    set(pins, 1)
    set(pins, 0)	[3]

# ======================= State machine ========================

# helper class for PIO StateMachines
class PioMach:
    
    def  __init__(self, program, freq=125_000_000, id=0, **kwargs):
        self.sm = rp2.StateMachine(id, program, freq, **kwargs)
#        sm.active(True)

# ========================== main ==============================

sm1 = PioMach(Freq50, freq=2_000,       set_base=Pin(26))		# 1000 Hz @ 50/50
sm2 = PioMach(Freq20, freq=5_000, id=1, set_base=Pin(16))		# 1000 Hz @ 20/80
sm1.sm.active(True)
sm2.sm.active(True)

# =========================== end ==============================