# AN108 copy AD to DA David Pilling
# Based on
# Arbitrary waveform generator for Rasberry Pi Pico
# Rolf Oldeman, 13/2/2021. CC BY-NC-SA 4.0 licence
# tested with rp2-pico-20210205-unstable-v1.14-8-g1f800cac3.uf2
from machine import Pin,mem32
from rp2 import PIO, StateMachine, asm_pio
from array import array
from utime import sleep
from math import pi,sin,exp,sqrt,floor
from uctypes import addressof
from random import random

#from sys import atexit

fclock=125000000 #clock frequency of the pico








#state machine that just pushes bytes to the pins
@asm_pio(out_init=(PIO.OUT_HIGH,PIO.OUT_HIGH,PIO.OUT_HIGH,PIO.OUT_HIGH,PIO.OUT_HIGH,PIO.OUT_HIGH,PIO.OUT_HIGH,PIO.OUT_HIGH),
         out_shiftdir=PIO.SHIFT_RIGHT, autopull=False, pull_thresh=32, autopush=False, push_thresh=32,
         sideset_init=(PIO.OUT_LOW,PIO.OUT_LOW))
def stream():
    in_(pins,8) .side(1)
    mov(osr,isr) .side(0)
    out(pins,8) .side(2)

sm = StateMachine(0, stream, freq=62500000, out_base=Pin(14),in_base=Pin(6),sideset_base=Pin(26))
sm.active(1)

