from I2Sduplex import I2Sduplex
import time
from machine import Pin
from micropython import const
SIO_BASE = const(0xD0000000)
GPIO_OUT_SET = const(0x0014 >> 2) # Divide by 4, ptr32 indexes in 4-byte words
GPIO_OUT_CLR = const(0x0018 >> 2)
led = Pin('LED', Pin.OUT)
# TODO:
# 1. Use uPython RP2 DMA module. DONE
# 2. Make PIO SM choosable.
print("Initialising audio interface...")
i2s = I2Sduplex()
@micropython.viper
def processBuffer(rx : ptr32, tx : ptr32, N : int) -> bool:
n = 0
valid = True
while n < N:
valid = valid and tx[n]==rx[n]
tx[n] = tx[n] + 128
n += 1
sio = ptr32(SIO_BASE)
if valid:
sio[GPIO_OUT_SET] = 0x02000000
else:
sio[GPIO_OUT_CLR] = 0x02000000
i2s.begin(processBuffer)
#time.sleep_ms(100)
#DMA.abort_all()
#i2s.sm.active(0)