Skip to content

Commit

Permalink
tests/psoc6/dut/pin.py: Extended pin modes and features tests.
Browse files Browse the repository at this point in the history
Signed-off-by: enriquezgarc <[email protected]>
  • Loading branch information
jaenrig-ifx committed Jan 17, 2024
1 parent 1225978 commit 05d015b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
51 changes: 46 additions & 5 deletions tests/psoc6/dut/pin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from machine import Pin
import machine
import time

# Allocate pin based on board
machine = os.uname().machine
Expand All @@ -14,10 +15,17 @@
# Pin out and pin in must be connected
# together in the board

pin_out = Pin(pin1_name)
pin_out.init(Pin.OUT)
pin_out = Pin(pin1_name, mode=Pin.OUT, value=True)
pin_in = Pin(pin2_name, Pin.IN)

# Validating initialization values
print("pin out initial value 1: ", pin_in.value() == 1)

pin_out.deinit()
pin_out = Pin(pin1_name, mode=Pin.OUT, value=False)
print("pin out initial value 0: ", pin_in.value() == 0)

# Validation different output setting
pin_out.value(1)
print("pin out value 1: ", pin_in.value() == 1)

Expand All @@ -42,7 +50,40 @@
pin_out.off()
print("pin out value off: ", pin_in.value() == 0)

pin_in.irq(
handler=lambda t: print("Interrupt triggered"), trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING
)
pin_out(1)
print("pin out callable 1: ", pin_in.value() == 1)

pin_out(0)
print("pin out callable 0: ", pin_in.value() == 0)


# Validating pull resistors configurations and open drain mode
pin_out.deinit()
pin_out = Pin(pin1_name, pull=None, mode=Pin.OPEN_DRAIN)
print("pin out with pull none initially 0 or 1: ", pin_in.value() == 0 or pin_in.value() == 1)

pin_out.deinit()
pin_out = Pin(pin1_name, pull=Pin.PULL_DOWN, mode=Pin.OUT)
print("pin out with pull down initially down: ", pin_in.value() == 1)

pin_out.deinit()
pin_out = Pin(pin1_name, pull=Pin.PULL_UP, mode=Pin.OUT)
print("pin out with pull up initially high: ", pin_in.value() == 0)


# Validating interrupts
def blocking_delay_ms(delay_ms):
start = time.ticks_ms()
while time.ticks_diff(time.ticks_ms(), start) < delay_ms:
pass


pin_in.irq(handler=lambda t: print("interrupt triggered rising"), trigger=Pin.IRQ_RISING)
pin_out.high()

blocking_delay_ms(1000)

pin_in.irq(handler=lambda t: print("interrupt triggered falling"), trigger=Pin.IRQ_FALLING)
pin_out.low()

blocking_delay_ms(1000)
10 changes: 9 additions & 1 deletion tests/psoc6/dut/pin.py.exp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pin out initial value 1: True
pin out initial value 0: True
pin out value 1: True
pin out value 0: True
pin out value True: True
Expand All @@ -6,4 +8,10 @@ pin out value high: True
pin out value low: True
pin out value on: True
pin out value off: True
Interrupt triggered
pin out callable 1: True
pin out callable 0: True
pin out with pull none initially 0 or 1: True
pin out with pull down initially down: True
pin out with pull up initially high: True
interrupt triggered rising
interrupt triggered falling

0 comments on commit 05d015b

Please sign in to comment.