diff --git a/tests/psoc6/hw_ext/i2s.py b/tests/psoc6/hw_ext/i2s.py index a5809c174d1c0..bc399a2b96995 100644 --- a/tests/psoc6/hw_ext/i2s.py +++ b/tests/psoc6/hw_ext/i2s.py @@ -29,6 +29,21 @@ print("SKIP") raise SystemExit +sample_num = 3600 +max_num = 0x80 +sample = bytearray( + [0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF] +) +buf = bytearray([0] * sample_num) +j = 0 +for i in range(sample_num): + if i >= (j + 1) * max_num: + j = j + 1 + buf[i] = sample[j % len(sample)] + + +# for i in range(sample_num/max_num - 1): +# print(binascii.hexlify(buf[i*max_num: (i + 1)*max_num])) audio_out = I2S( 0, @@ -38,30 +53,47 @@ mode=I2S.TX, bits=32, format=I2S.STEREO, - rate=8000, - ibuf=20000, -) -audio_in = I2S( - 1, - sck=sck_rx_pin, - ws=ws_rx_pin, - sd=sd_rx_pin, - mode=I2S.RX, - bits=32, - format=I2S.STEREO, - rate=8000, + rate=22050, ibuf=20000, ) -buf = bytearray([0] * 64) -for i in range(64): - buf[i] = i +# audio_in = I2S( +# 1, +# sck=sck_rx_pin, +# ws=ws_rx_pin, +# sd=sd_rx_pin, +# mode=I2S.RX, +# bits=32, +# format=I2S.STEREO, +# rate=8000, +# ibuf=20000, +# ) + +tx_done = False + + +def tx_complete_irq(obj): + global tx_done + tx_done = True + # print("tx completed") + + # buf = b"\x01\x00\x17\x15\x16\x44" -print("tx Buffer") -print(buf) +# print("tx Buffer") +# print(buf) +audio_out.irq(tx_complete_irq) num_written = audio_out.write(buf) -buf1 = bytearray(64) -num_read = audio_in.readinto(buf1) -print("Rx Buffer") -print(buf1) -audio_out.stop() -audio_in.stop() + +while not tx_done: + pass + +print("tx completed") + +# print(num_written) +# buf1 = bytearray(64) +# num_read = audio_in.readinto(buf1) +# print("Rx Buffer") +# print(buf1) +# audio_out.stop() +# audio_in.stop() +# time.sleep(5) +# audio_out.deinit()