import rp2
from rp2 import PIO
from machine import Pin
from time import sleep
@rp2.asm_pio(set_init=[PIO.OUT_LOW]*1, out_init=[PIO.OUT_LOW]*1, sideset_init=[PIO.OUT_HIGH]*3, autopull=True, fifo_join=PIO.JOIN_TX)
def dualHoltekHT1632C():
wrap_target()
label("init")
pull(block) .side(0b111)
mov(x, osr)
pull(block)
mov(y, osr)
pull(block)
jmp(not_x, "cs1_start")
nop() .side(0b101) # 'tsu1' setup time for CS to WR clock width (300ns BEGINS)
nop().delay(1)
label("cs0_loop")
out(pins, 1) .side(0b100) # 'tsu' setup time for Data to WR clock width (100ns BEGINS)
nop() .side(0b101) # 'th' hold time for Data to WR clock width (200ns BEGINS)
jmp(x_dec, "cs0_loop")
set(pins, 0)
label("cs1_start")
jmp(not_y, "init") .side(0b111)
nop() .side(0b011)
nop().delay(1)
label("cs1_loop")
out(pins, 1) .side(0b010)
nop() .side(0b011)
jmp(y_dec, "cs1_loop")
set(pins, 0)
wrap()
sm = rp2.StateMachine(0, dualHoltekHT1632C, freq=3000000, set_base=Pin(10), out_base=Pin(10), sideset_base=Pin(11))
sm.active(1)
while True:
sm.put(22 - 1 );
sm.put(22 - 1 );
sm.put(0xA03E0681);
sm.put(0xF1800000);
# 10100000001111100000011010000001111100011000
sleep(1)