Skip to content

Commit

Permalink
tests/psoc6: Adding tests for ADC and ADCBlock.
Browse files Browse the repository at this point in the history
Signed-off-by: NikhitaR-IFX <Nikhita.Rajasekhar@infineon.com>
  • Loading branch information
NikhitaR-IFX committed Jul 31, 2023
1 parent 49d615c commit d2ae382
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/psoc6/adc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
ADC test for the PSoC6 port.
"""

from machine import ADC, Pin

adc_pin = Pin("P10_0")
adc_wrong_pin = Pin("P13_7")

# Exceptions should be raised
try:
adc = ADC(adc_wrong_pin)
except:
print("Invalid ADC Pin")

adc = ADC(adc_pin, sample_ns=1000)
print(adc)

print(adc.read_u16() > 0)
print(adc.read_uv() > 0)
4 changes: 4 additions & 0 deletions tests/psoc6/adc.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Invalid ADC Pin
<ADC Pin=80, ADCBlock_id=0, sampling_time_ns=1000>
True
True
29 changes: 29 additions & 0 deletions tests/psoc6/adcblock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
ADCBlock test for the PSoC6 port.
"""
from machine import Pin, ADCBlock

pin = Pin("P10_3")

# Negative tests
try:
adcBlock = ADCBlock(1)
except:
print("TypeError: Specified ADC id not supported. Currently only block 0 is configured!")

try:
adcBlock = ADCBlock(0, bits=10)
except:
print("TypeError: Invalid bits. Current ADC configuration supports only 12 bits resolution!")

adcBlock = ADCBlock(0)

try:
adcPin = adcBlock.connect(0, pin)
except:
print("TypeError: Wrong pin specified for the mentioned channel")


adcPin = adcBlock.connect(3, pin)

print(adcPin.read_uv() > 0)
4 changes: 4 additions & 0 deletions tests/psoc6/adcblock.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TypeError: Specified ADC id not supported. Currently only block 0 is configured!
TypeError: Invalid bits. Current ADC configuration supports only 12 bits resolution!
TypeError: Wrong pin specified for the mentioned channel
True

0 comments on commit d2ae382

Please sign in to comment.