forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: NikhitaR-IFX <Nikhita.Rajasekhar@infineon.com>
- Loading branch information
1 parent
beb9c8e
commit bb203a0
Showing
3 changed files
with
92 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,67 @@ | ||
import os | ||
from machine import PDM_PCM, Pin | ||
import machine | ||
|
||
# Allocate pin based on board | ||
board = os.uname().machine | ||
if "CY8CPROTO-062-4343W" in board: | ||
clk_pin = "P10_4" | ||
data_pin = "P10_5" | ||
send_signal_to_tx_pin = "P10_0" | ||
|
||
elif "CY8CPROTO-063-BLE" in board: | ||
print("SKIP") | ||
raise SystemExit | ||
elif "CY8CKIT-062S2-AI" in board: | ||
clk_pin = "P10_4" | ||
data_pin = "P10_5" | ||
|
||
pdm_pcm = PDM_PCM( | ||
0, | ||
sck=clk_pin, | ||
data=data_pin, | ||
sample_rate=8000, | ||
decimation_rate=64, | ||
bits=PDM_PCM.BITS_16, | ||
format=PDM_PCM.STEREO, | ||
left_gain=0, | ||
right_gain=0, | ||
) | ||
|
||
pdm_pcm.deinit() | ||
|
||
def generate_exp_seq(data): | ||
exp_seq = bytearray(data * 64) | ||
return exp_seq | ||
|
||
|
||
# Test Case 1: Blocking mode | ||
_sampling_rate = [8000, 16000, 32000, 48000, 22050, 44100] | ||
_mode = [PDM_PCM.MONO_LEFT, PDM_PCM.MONO_RIGHT, PDM_PCM.STEREO] | ||
_bits = 16 | ||
exp_data = [[0xFF]] | ||
iterations = 100 | ||
exp_seq = generate_exp_seq([0x00]) | ||
|
||
for i in range(len(_sampling_rate)): # Check for all sampling rates | ||
set_sampling_rate = _sampling_rate[i] | ||
if _sampling_rate[i] == 22050 or _sampling_rate[i] == 44100: | ||
machine.freq(machine.AUDIO_PDM_22_579_000_HZ) | ||
else: | ||
machine.freq(machine.AUDIO_PDM_24_576_000_HZ) | ||
for j in range(len(_mode)): # Check for all modes | ||
set_mode = _mode[j] | ||
if set_mode == PDM_PCM.STEREO: | ||
iterations = 200 | ||
pdm_pcm = PDM_PCM( | ||
0, | ||
sck=clk_pin, | ||
data=data_pin, | ||
sample_rate=set_sampling_rate, | ||
decimation_rate=64, | ||
bits=PDM_PCM.BITS_16, | ||
format=set_mode, | ||
left_gain=0, | ||
right_gain=0, | ||
) | ||
pdm_pcm.init() # Start | ||
|
||
for k in range(iterations): | ||
rx_buf = bytearray([0] * 64) | ||
num_read = pdm_pcm.readinto(rx_buf) | ||
# print("buf :", ''.join(f'{x:02x} ' for x in rx_buf)) | ||
if rx_buf[:3] == bytearray([exp_data[0][0], exp_data[0][0], exp_data[0][0]]): | ||
is_seq_received = rx_buf == exp_seq | ||
if is_seq_received: | ||
print( | ||
f"data high received for mode = {set_mode}, bits = PDM_PCM.BITS_16, rate = {set_sampling_rate} : {is_seq_received}" | ||
) | ||
break | ||
pdm_pcm.deinit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
machine.PDM_PCM: PLL0 freq is changed to 24576000. This will affect all resources clock freq sourced by PLL0. | ||
data high received for mode = 0, bits = PDM_PCM.BITS_16, rate = 8000 : True | ||
data high received for mode = 1, bits = PDM_PCM.BITS_16, rate = 8000 : True | ||
data high received for mode = 2, bits = PDM_PCM.BITS_16, rate = 8000 : True | ||
data high received for mode = 0, bits = PDM_PCM.BITS_16, rate = 16000 : True | ||
data high received for mode = 1, bits = PDM_PCM.BITS_16, rate = 16000 : True | ||
data high received for mode = 2, bits = PDM_PCM.BITS_16, rate = 16000 : True | ||
data high received for mode = 0, bits = PDM_PCM.BITS_16, rate = 32000 : True | ||
data high received for mode = 1, bits = PDM_PCM.BITS_16, rate = 32000 : True | ||
data high received for mode = 2, bits = PDM_PCM.BITS_16, rate = 32000 : True | ||
data high received for mode = 0, bits = PDM_PCM.BITS_16, rate = 48000 : True | ||
data high received for mode = 1, bits = PDM_PCM.BITS_16, rate = 48000 : True | ||
data high received for mode = 2, bits = PDM_PCM.BITS_16, rate = 48000 : True | ||
data high received for mode = 0, bits = PDM_PCM.BITS_16, rate = 22050 : True | ||
data high received for mode = 1, bits = PDM_PCM.BITS_16, rate = 22050 : True | ||
data high received for mode = 2, bits = PDM_PCM.BITS_16, rate = 22050 : True | ||
data high received for mode = 0, bits = PDM_PCM.BITS_16, rate = 44100 : True | ||
data high received for mode = 1, bits = PDM_PCM.BITS_16, rate = 44100 : True | ||
data high received for mode = 2, bits = PDM_PCM.BITS_16, rate = 44100 : True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
from machine import Pin | ||
|
||
# Allocate pin based on board | ||
board = os.uname().machine | ||
if "CY8CPROTO-062-4343W" in board: | ||
clk_pin = "P10_4" | ||
data_pin = "P10_5" | ||
elif "CY8CPROTO-063-BLE" in board: | ||
print("SKIP") | ||
raise SystemExit | ||
elif "CY8CKIT-062S2-AI" in board: | ||
clk_pin = "P10_4" | ||
data_pin = "P10_5" | ||
|
||
start_time = time.time() | ||
|
||
data_out = Pin("P13_7", mode=Pin.OUT, value=False) | ||
clk_in = Pin("P13_6", Pin.IN, Pin.PULL_DOWN) | ||
|
||
while time.time() - start_time < 10: # Wait for 5 second | ||
data_out.low() |